Dropdown
Displays a set of actions/items to the user, usually used to show a menu of options.
Overview
Import
Import the component from @faststore/ui
import {
Dropdown,
DropdownItem,
DropdownMenu,
DropdownButton,
} from '@faststore/ui'
Import Styles into your FastStore project
To apply the styles of this component in your FastStore project, import the following into your stylesheet:
@import '@faststore/ui/src/components/molecules/Dropdown/styles.scss';
Follow the instructions in the Importing FastStore UI component styles tutorial.
Usage
Default
Controlled
As Child
Props
Dropdown
Name | Type | Description | Default |
---|---|---|---|
onDismiss | () => void | Event emitted when the Dropdown is closed. | |
isOpen | false | true | A boolean value that represents the state of the Dropdown. | |
id | string | ID to identify Dropdown. | fs-dropdown |
Dropdown Item
Name | Type | Description | Default |
---|---|---|---|
testId | string | ID to find this component in testing tools (e.g.: cypress, testing library, and jest). | fs-dropdown-item |
icon | string | number | false | true | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | @deprecated A React component that will be rendered as an icon. | |
asChild | false | true | Replace the default rendered element with the one passed as a child, merging their props and behavior. | |
dismissOnClick | false | true | Emit onDismiss event when the component is clicked. | true |
Dropdown Menu
Name | Type | Description | Default |
---|---|---|---|
testId | string | ID to find this component in testing tools (e.g.: cypress, testing library, and jest). | fs-dropdown-menu |
aria-labelledby | string | Identifies the element (or elements) that labels the current element. @see aria-labelledby https://www.w3.org/TR/wai-aria-1.1/#aria-labelledby | |
onDismiss | (event: MouseEvent<Element, MouseEvent> | KeyboardEvent<Element>) => void | This function is called whenever the user hits "Escape" or clicks outside the dialog. | |
size | "small" | "regular" | Specifies the size variant. | regular |
align | "left" | "right" | "center" | Alignment for the dropdown | left |
Dropdown Button
Name | Type | Description | Default |
---|---|---|---|
testId | string | ID to find this component in testing tools (e.g.: cypress, testing library, and jest). | fs-dropdown-button |
asChild | false | true | Replace the default rendered element with the provided child element, merging their props and behavior. | false |
loading | false | true | Boolean that represents a loading state. | |
loadingLabel | string | Specifies a label for loading state. | |
icon | string | number | false | true | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | @deprecated A React component that will be rendered as an icon. | |
iconPosition | "left" | "right" | @deprecated Specifies where the icon should be positioned | |
size | "small" | "regular" | Specifies the size variant. | |
disabled | false | true | Specifies that this button should be disabled. |
Design Tokens
Compound Components
Dropdown Item
Local token | Default value/Global token linked |
---|---|
--fs-dropdown-item-min-height | 2.375rem |
--fs-dropdown-item-padding | var(--fs-spacing-1) var(--fs-spacing-2) var(--fs-spacing-1) var(--fs-spacing-1) |
--fs-dropdown-item-text-size | var(--fs-text-size-base) |
--fs-dropdown-item-text-weight | var(--fs-text-weight-regular) |
--fs-dropdown-item-color | var(--fs-color-link) |
--fs-dropdown-item-bkg-color | var(--fs-color-tertiary-bkg-light) |
--fs-dropdown-item-bkg-color-hover | var(--fs-color-primary-bkg-light) |
--fs-dropdown-item-border-bottom-color | var(--fs-border-color-light) |
--fs-dropdown-item-icon-min-width | 1.125rem |
--fs-dropdown-item-icon-margin-right | var(--fs-spacing-0) |
--fs-dropdown-item-icon-margin-top | calc(-1 * var(--fs-spacing-1)) |
Dropdown Menu
Local token | Default value/Global token linked |
---|---|
--fs-dropdown-menu-bkg-color | var(--fs-color-tertiary-bkg) |
--fs-dropdown-menu-border-radius | var(--fs-border-radius) |
--fs-dropdown-menu-box-shadow | var(--fs-shadow-hover) |
Variants
Small
Local token | Default value/Global token linked |
---|---|
--fs-dropdown-item-small-min-height | 1.75rem |
--fs-dropdown-item-small-padding | var(--fs-spacing-0) var(--fs-spacing-2) var(--fs-spacing-0) var(--fs-spacing-1) |
--fs-dropdown-item-small-text-size | var(--fs-text-size-1) |
Customization
For further customization, you can use the following data attributes:
Dropdown Item
data-fs-dropdown-item
Dropdown Menu
data-fs-dropdown-menu
data-fs-dropdown-overlay
data-fs-dropdown-menu
data-fs-dropdown-menu-size="small | regular"
Dropdown Button
data-fs-dropdown-button
This component inherits Button CSS selectors and styles.
Accessibility
Keyboard Interactions
Key | Description |
---|---|
Enter | When focusing on |
ArrowDown | When focusing on an item, moves focus to the next
|
ArrowUp | When focusing on an item, moves focus to the previous
|
Escape | Closes |
Home | When |
End | When |