Dropdown
Component that allows users to select one option from a list of predefined options.
For accessibility and mobile responsiveness, all dropdowns are triggered by a click on the trigger element. This ensures consistent behavior across devices, as mobile layouts do not support hover interactions.
Moreover, dropdowns can be applied in any element, such as a, ul, ol, etc., but in this guide, button and nav elements are used.
Button Dropdown
Buttons that have hidden extra options. Please refer to HPUCSS Buttons for more usage info.
Dropdown Menu Alignment
By default, menu options are aligned left, but they can be configured to align center or right by using the Typography text alignment on the .dropdown-wrap wrapping element:
- .hpu-text-left
- .hpu-text-center
- .hpu-text-right
Please refer to HPUCSS Typography for usage info.
Dropdown Accessibility
You may have noticed that dropdown components include numerous aria-*, role and the tabindex attributes. These are essential for users who rely on assistive technologies, so please ensure that you consistently include these accessibility attributes in your implementations.
Additionally, well-built dropdowns support multiple methods of interaction. Try the following actions in the example below:
- Open the dropdown and press the Escape key to close it.
- Use the Tab key to move through the links within the opened dropdown.
- Click anywhere outside the dropdown to dismiss it.
These interactions help ensure a more accessible and user-friendly experience for all users. They are already pre-applied, so there is no need to make changes to these behaviors.