Skip to main content

Menu toggle

Accessibility

To implement an accessible PatternFly menu toggle component:

  • Due to the composable nature of the menu and menu toggle components, keyboard interaction will need to be added manually between the menu toggle and the menu. See the custom menus demos to see how this is done.
  • When adding an action to the menu toggle, an aria-label will need to be added to the MenuToggleAction or the MenuToggleCheckbox to communicate to users what this action will do.
  • When adding any additional elements to the menu toggle, remember to follow that element's specific considerations. For example, if you are adding an avatar to the menu toggle, you will need to provide an alt attribute with a description of the image.

Testing

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

  • Tab navigates to the menu and Shift + Tab navigates to the previous focusable element. Refer to our menu accessibility documentation for more implementation details when using these components together.
  • This will communicate what the menu toggle is to users of assistive technologies when navigating through a page or a screen reader's rotor 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 toggle]"MenuToggleAdds an accessible name to the menu toggle. Required when there is no text displayed in the menu toggle.
icon={[custom icon]}MenuToggleAdds an optional icon rendered inside the toggle, before the children content. Add aria-hidden to the icon to hide the decorative item from screen reader elements.
aria-label="[text that labels the action]"MenuToggleActionAdds an accessible name to the menu toggle action when the action is represented by an icon and no text.
aria-label="[text that labels the checkbox]"MenuToggleCheckboxAdds an accessible name to the checkbox item on the menu toggle when there is no associated visible label text.

HTML/CSS customization

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

Attribute or ClassApplied toReason
aria-expanded="true or false".pf-v5-c-menu-toggle, .pf-v5-c-menu-toggle__buttonIndicates that the menu toggle component is in the expanded or collapsed state.
aria-label="[text that labels the menu toggle]".pf-v5-c-menu-toggleAn accessible label for the menu toggle when there is no visible text within the toggle. Required when using a pf-m-plain with no text.
aria-hidden="true".pf-v5-c-menu-toggle__toggle-iconMakes the decorative icon on the toggle hidden from screen reader users. Required when the toggle contains only an icon