Skip to content

@wordpress/ui: Standardize keyboard shortcut presentation and accessibility #80321

Closed

Description

@ciampo

Follow-up to #76135.

What problem does this address?

@wordpress/ui does not have a consistent contract for presenting keyboard shortcuts and exposing them to assistive technology.

Actually reacting to keyboard shortcuts is outside the scope of UI components and remains the consumer's responsibility. This issue focuses on using the representations provided by @wordpress/keycodes consistently across @wordpress/ui:

  • Applying aria-keyshortcuts to the interactive element associated with the action.
  • Displaying a platform-appropriate shortcut.
  • Providing a localized, human-readable description for assistive technology.
  • Using a consistent shortcut prop shape across higher-level components.

A single logical shortcut currently needs three related representations:

  • A visual representation, such as ⌘S or Ctrl+S.
  • A human-readable label, such as Command S.
  • An aria-keyshortcuts-compatible value, such as Meta+S.

@wordpress/keycodes provides separate displayShortcut, shortcutAriaLabel, and ariaKeyShortcut helpers. PR #74205 intentionally did not ship a combined formatter because the existing helpers do not always accept the same input syntax.

The current component patterns are incomplete:

  • IconButton accepts displayShortcut and ariaKeyShortcut. It renders the visual value in its tooltip and sets aria-keyshortcuts, but does not provide an explicit accessible description.
  • Button has no shortcut-specific API. Adding one would either couple this low-level component to Tooltip or force a particular visual placement.
  • The new Menu in #79560 demonstrates manually pairing aria-keyshortcuts with a visual suffix. This wiring should be consistent and reusable across menu items.

The aria-keyshortcuts specification makes clear that the attribute advertises a shortcut but does not implement it. It also recommends making shortcuts discoverable visually. The APG keyboard interface guidance says shortcuts should augment normal keyboard access and that key assignments should be revealed on their target elements.

Following the discussion in #76135, @wordpress/ui should also provide an explicit accessible description instead of relying only on assistive technology support for aria-keyshortcuts. This can be implemented with aria-describedby pointing to visually hidden text such as "Keyboard shortcut: Command S".

Proposed approach

Expand the existing IconButton shortcut shape with a third value containing the human-readable shortcut label, typically generated with shortcutAriaLabel.

When a higher-level component receives this shortcut metadata, it should:

  1. Apply the ARIA-compatible value through aria-keyshortcuts.
  2. Render the visual value as presentational content.
  3. Render a localized, visually hidden shortcut description.
  4. Merge that description into any consumer-provided aria-describedby.
  5. Leave registration and keyboard event handling to the consumer.

Consumers must also keep the external shortcut handler synchronized with the component's enabled or disabled state.

Tasks

Out of scope

  • Registering, listening for, remapping, or resolving conflicts between shortcuts.
  • Adding a generic visual Shortcut component without a concrete additional use case.
  • Reintroducing a combined @wordpress/keycodes formatter without resolving the input-format limitations discussed in #74205.

Related history

Activity

  1. added
    [Type] Tracking IssueTactical breakdown of efforts across the codebase and/or tied to Overview issues.
    on Jul 15, 2026
  2. ciampo commented on Jul 17, 2026

    @ciampo
    ContributorAuthor

    Update:

  3. ciampo commented on Aug 10, 2026

    @ciampo
    ContributorAuthor
  4. ciampo commented on Aug 19, 2026

    @ciampo
    ContributorAuthor

    Update: we're closing #80407 since it may too early to have a dedicated high level component for that usecase.

    Instead, the work will continue in #81826 to expose the smaller utilities that consumers of the package can use when adding keyboard shortcut support to @wordpress/ui components.

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

Metadata

Metadata

Labels

[Package] UI/packages/ui[Type] Tracking IssueTactical breakdown of efforts across the codebase and/or tied to Overview issues.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions