Skip to content

Update Basic Dropdown example to demonstrate focus management #839

@tlabaj

Description

@tlabaj

The dropdown panel should trap focus when visible. This means that:

  • When a user navigates using only a keyboard, focus can only move within the panel while the panel is visible
  • When a user uses a screen reader, only the contents within the panel are visible to the screen reader while the panel is visible (i.e. aria-hidden=“true” is applied to all other contents on the page).

There are two use cases for the Dropdown component which have different keyboard interaction behaviors:

  1. The primary use case is where clicking the Dropdown toggle produces a menu of actions.
  2. An alternate use cases we want to support is where the panel that displays could contain whatever the consumer defines (a form, paragraph text).
    • The keyboard interaction that’s expected in this case is similar to what you’d expect with a modal or popover. For example:
      • Esc key dismisses the panel - this behavior requires implementation, and is related to Handle Esc key for multiple components #1051
      • Tab key shifts focus within elements in the panel - this behavior is provided automatically, but there are some cases that might require handling (refer to the Modal component as an example):
        • If the last element has focus, hitting Tab will shift focus to the first focusable element in the panel
        • If the first element has focus, hitting Shift+Tab will shift focus to the last focusable element in the panel
      • Other keys that automatically work with native elements should still work as expected (e.g. Enter/Space for button elements)

Some notes about this issue:

  • Similar behavior was implemented for the modal in feat(PF4-Modal): Adds keyboard and screen reader focus trapping #1011. However, unlike the modal, the user should be able to click anywhere outside the panel/menu to dismiss the panel/menu (e.g. clicking the toggle or clicking some other area on the screen should dismiss it).
  • "trapping focus" may or may not be required for the primary use case where arrow keys are used to navigate the menu items. Alternatively, another solution for trapping focus in this case might work better. The following is an implementation of a button menu that provides similar arrow key interaction, and also hides the page contents from the screen reader while the menu is visible: https://github.com/HugoGiraudel/react-menu-button

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions