Skip to content

Posts, Post Types: Add a presentation role to taxonomy tab list items - #16086

Open
abhishekfdd wants to merge 2 commits into
WordPress:trunkfrom
abhishekfdd:fix/66725-tablist-presentation-role
Open

abhishekfdd wants to merge 2 commits into
WordPress:trunkfrom
abhishekfdd:fix/66725-tablist-presentation-role

Conversation

@abhishekfdd

Copy link
Copy Markdown

Since [61764], post_categories_meta_box() and link_categories_meta_box() render their tabs as ul[role="tablist"] > li > a[role="tab"]. The li elements keep their implicit listitem role, but a tablist must own tab elements, and a listitem needs a list parent. axe-core reports aria-required-children, aria-required-parent and listitem.

Commit 1: Add role="presentation" to the tab list items

This fixes the markup reported in the ticket. It adds role="presentation" to both li elements in each function, so the tab list owns its tabs directly. The ARIA Authoring Practices Guide describes this approach in Hiding Semantics with the presentation Role. Core already uses the same markup for the embed share dialog tabs in src/wp-includes/embed.php.

Impact: In the browsers I could check, this is a validity fix. It removes the reliance on browsers repairing the markup, rather than changing what those browsers currently expose:

  • Chrome 157 (DevTools Protocol accessibility tree) and Firefox 160 (WebDriver BiDi accessibility locator) already treat these li elements as presentational on trunk. Neither exposes listitem nodes between the tab list and the tabs, before or after the patch.
  • The listitem level appears in spec-based role calculation, as used by axe and Playwright's ariaSnapshot(). That shows tablist > listitem > tab on trunk and tablist > tab with the patch.
  • I could not inspect WebKit's native accessibility tree, and I have not tested screen readers.

Classes, whitespace and attribute order are unchanged. No JS or CSS depends on the li role:

  • post.js and link.js select with #<tax>-tabs a / #category-tabs a, .parent(), .parent('li').next()/.prev() and .siblings('li'). All of these use the DOM tree, not the accessibility tree.
  • edit.css styles ul.category-tabs li by element and class. Nothing in src/wp-admin/css uses a [role] selector on these elements.

Commit 2: Remove the extra Tab stop on the inactive "Most Used" tab

I found this keyboard bug while testing the fix. On trunk, after a fresh page load, the Tab after "All" stops on "Most Used" before leaving the tab list, because "Most Used" is rendered without tabindex="-1". In the tabs pattern, only the active tab is in the Tab sequence, and the arrow keys move between tabs. The extra stop disappears only once the user activates a tab and the script sets tabindex.

This commit renders the "Most Used" tab with tabindex="-1" in both functions. No JS change is needed:

  • When the saved user setting restores "Most Used" on load, the script's triggered click sets tabindex="-1" on every tab and removes it from the clicked one.
  • Without JS, the "Most Used" tab is hidden by .hide-if-no-js.

It is a separate commit so it can be reviewed, or split out, on its own. If a committer prefers, I'm happy to move it to a new ticket.

Testing instructions

Setup:

  1. Use the classic editor for posts, for example by activating the Classic Editor plugin.
  2. Optional, to exercise the $tax_name path: register a second hierarchical taxonomy for posts. For example, add this to a mu-plugin:
    add_action( 'init', function () {
        register_taxonomy( 'genre', 'post', array( 'hierarchical' => true, 'show_ui' => true, 'label' => 'Genres' ) );
    } );
  3. Optional, to test the link category box: add_filter( 'pre_option_link_manager_enabled', '__return_true' );, then open Links > Add New.

Accessibility checks (commit 1):

  1. Open Posts > Add New (and Links > Add New, if enabled).
  2. Run axe (axe DevTools browser extension, or axe-core) with the WCAG 2 A/AA rules.
  3. Before: aria-required-children on each ul.category-tabs, aria-required-parent on each tab link and listitem on each li. After: none of these in the tab lists.
  4. Check that the tab li elements have role="presentation".

Keyboard checks (commit 2), for each tab list:

  1. Reload the page, then Tab into the box. Focus stops on the active tab only, and the next Tab leaves the tab list. (On trunk, the next Tab stops on "Most Used".)
  2. ArrowRight/ArrowLeft move focus between the tabs.
  3. Enter and Space activate the focused tab. The panel switches, the page does not scroll, and aria-selected/tabindex move to the new tab.
  4. Select "Most Used", then reload. "Most Used" is restored, it is the only tab reachable with Tab, and "All" has tabindex="-1".
  5. Select "All", then reload. "All" is restored.

Results

I tested with Chrome 157 and axe-core 4.10.2. The ticket was filed with axe-core 4.14.1, and the same three rules exist in both.

  • axe: on trunk, 10 violations on post-new.php (Categories plus a custom taxonomy) and 5 on link-add.php. With the patch, none. Commit 1 alone also clears them.
  • Keyboard (Playwright): on trunk, step 1 fails in both boxes because of the extra stop on "Most Used". With the patch, every step passes. The other steps pass on both.

Full results are in the Trac ticket.

Trac ticket: https://core.trac.wordpress.org/ticket/66725

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Investigating the markup and JS, preparing both commits, running the axe, keyboard and accessibility tree checks in a local environment, and drafting this description. I reviewed the code, test results and text, and take responsibility for them.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

The taxonomy and link category meta boxes render their tabs as `ul[role="tablist"] > li > a[role="tab"]`. The `li` elements keep their implicit `listitem` role, so the tablist's owned children are list items instead of tabs, and each list item has no `list` parent. Automated checkers report this as `aria-required-children`, `aria-required-parent` and `listitem` violations.

Add `role="presentation"` to the `li` elements in `post_categories_meta_box()` and `link_categories_meta_box()`, so the tabs become the tablist's direct children in the accessibility tree. This is the approach described in the ARIA Authoring Practices Guide's "Hiding Semantics with the presentation Role", and matches the embed share dialog tabs.

Follow-up to [61764].

See #66725.
…tab sequence.

The "Most Used" tab in the taxonomy and link category meta boxes is rendered without `tabindex="-1"`, so both tabs are in the Tab sequence until the user activates a tab and the script sets `tabindex` on them. The tabs pattern expects only the active tab to be reachable with Tab, with the arrow keys moving between tabs.

Render the inactive tab with `tabindex="-1"`. When the user setting restores the "Most Used" tab on load, the script's triggered click already removes `tabindex` from that tab and sets `tabindex="-1"` on "All", so no script change is needed.

Follow-up to [61764].

See #66725.
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props abhishekfdd.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant