Skip to main content

Menu

Accessibility

To implement an accessible PatternFly menu component:

  • Due to the composable nature of the menu component, keyboard interaction will need to be added manually between the menu toggle and the menu. See the custom menu demos to see how this is done.
  • Any actions placed within a menu item will need an aria-label on the MenuItemAction to communicate to users what the action is.

Testing

At a minimum, a menu component should meet the following criteria:

  • Tab navigates to the menu, Shift + Tab navigates to the previous focusable element, up and down arrow keys should be used to navigate between menu items, and Escape should close the menu."
  • This will differentiate each action when announced to users of assistive technologies when navigating through a page or a screen reader's rotor menu.

React customization

The following React props have been provided for more fine-tuned control over accessibility.

PropApplied toReason
aria-label=[text that labels the menu]MenuAdds an accessible name to the menu.
aria-label=[text that labels the menu item]MenuItemAdds an accessible name to the menu item.
icon={<Icon aria-hidden />}MenuItemRenders an icon to a menu item. When icon is decorative, pass an aria-hidden to the icon to hide it from screen reader users.
isExternalLinkMenuItemRenders an icon on the item when it receives focus or is hovered, as well as visually hidden text, to let users of certain assistive technologies know that the item will open in a new tab/window. Required if the item opens a new tab/window.
aria-label=[text that labels the menu item's action]MenuItemActionAdds an accessible name to the action item on the menu.
icon={<Icon aria-hidden />}MenuItemActionRenders an icon to a menu item action. When icon is decorative, pass an aria-hidden to the icon to hide it from screen reader users.
labelHeadingLevel=[a heading tag]MenuGroupAdds a group label's heading level. Default is h1. Be sure to not skip heading levels when passing this prop in. For example, if a menu group is within a page section that has an h2 heading, you should not pass headingLevel="h4".

HTML/CSS customization

The following HTML attributes and PatternFly classes can be used for more fine-tuned control over accessibility.

Attribute or classAppliedReason
role="menu".pf-v5-c-menu__listDeclares .pf-v5-c-menu__list as a menu.
disabledbutton.pf-v5-c-menu__itemWhen the menu item uses a button element, indicates that it is unavailable and removes it from keyboard focus.
role="menuitem".pf-v5-c-menu__item, .pf-v5-c-menu__list-item (checkbox)Assigns .pf-v5-c-menu__item as an option in a set of choices contained by a menu.
role="none".pf-v5-c-menu__list-itemRemoves semantic meaning from .pf-v5-c-menu__list-item.
aria-disabled="true"a.pf-v5-c-menu__itemWhen the menu item uses a link element, removes it from keyboard focus.
tabindex="-1"a.pf-v5-c-menu__itemWhen the menu item uses a link element, removes it from keyboard focus.
aria-hidden="true".pf-v5-c-menu__item-icon, .pf-v5-c-menu__item-action-icon, .pf-v5-c-menu__item-external-icon, .pf-v5-c-menu__item-toggle-icon, .pf-v5-c-menu__item-select-iconHides the icon from assistive technologies.
aria-label="[text that labels the action]".pf-v5-c-menu__item-action-icon.pf-m-favoriteProvides an accessible label indicating that the favorite action is not selected.
aria-label="[text that labels the action]".pf-v5-c-menu__item-action-icon.pf-m-favorite.pf-m-favoritedProvides an accessible label indicating that the favorite action is selected.