Dropdown
A generic dropdown component. Can be used as is, or to build more specific components like a tooltip or a popover.
Import#
Dropdown: The component that provides the context to the other components.Dropdown.Trigger: Passes theonClickto your button, which opens the dropdown.Dropdown.Content: The actual dropdown element to which you pass your content.
Usage#
The dropdown is stateful by default so you can just us it without adding any of your own logic. See controlled example below on how to control is yourself.
SyntaxError: Unexpected token (1:8)
1 : return ()
^Props#
placement#
You can change the placement of the dropdown using the placement prop. The default is auto which means that the dropdown will try to fit on the screen.
Supported placements#
autobottombottom-endbottom-startleftleft-endleft-startrightright-endright-starttoptop-endtop-start
SyntaxError: Unexpected token (1:8)
1 : return ()
^trigger#
Use the trigger prop to choose when the dropdown should open. It can be either click or hover. Defaults to click.
SyntaxError: Unexpected token (1:8)
1 : return ()
^Controlled mode#
By passing isOpen you make the dropdown a controlled component, and you are then responsible for the opening and closing.
SyntaxError: Unexpected token (1:8)
1 : return ()
^note
It's still recommended to use the Dropdown.Trigger component, and pass onOpen to the Dropdown like in the example above. Dropdown.Trigger makes sure the dropdown is positioned correctly.
onClose can be passed to the Dropdown component if you want to support closing the dropdown on outside click.
Accessability#
Dropdown follows the practices for dialogs found at WAI-ARIA Authoring Practices.
- Focus is moved to
Dropdown.Contentwhen the dropdown is opened. Dropdown.Contentkeeps the focus inside the content when tabbing.- The trigger has
aria-haspopupset totrue. - When dropdown is closed, focus is moved back to the trigger.
- Pressing
Esccloses the dropdown. - If
triggeris set tohover, focus and blur toggles of the trigger the dropdown.