Dropdown
Dropdowns are used to reveal a list of options or commands.
The Dropdown
component is a compound of the following:
DropdownButton
: wraps the button that emits the trigger to open theDropdownMenu
.DropdownMenu
: wraps a series ofDropdownItems
.DropdownItem
: wraps an item of theDropdownMenu
.
Importβ
import { Dropdown, DropdownButton, DropdownMenu, DropdownItem } from '@faststore/ui'
Usageβ
- React
- CSS
Loading...
[data-store-dropdown-button] {
@apply bg-pink-500 text-white text-base w-36 rounded-md p-1;
@apply focus:bg-pink-700;
}
[data-store-dropdown-item] {
@apply bg-gray-300 p-2 text-base border-2;
@apply focus:bg-pink-700 focus:text-white focus:border-pink-300 focus:outline-none;
}
[data-store-dropdown-overlay] {
@apply bg-transparent;
}
[data-store-dropdown-menu] {
@apply flex flex-col m-0;
@apply border border-gray-700;
padding: 0;
}
Use casesβ
Use the Dropdown
component to create:
- Navigation menus that present a list of links to subcategories related to a top-level category.
- Mega menus that display navigation options in a two-dimensional dropdown layout.
Propsβ
DropdownButton
β
DropdownItem
β
DropdownMenu
β
Dropdown
β
Customizationβ
data-store-dropdown-button
data-store-dropdown-item
data-store-dropdown-overlay
data-store-dropdown-menu
Best practicesβ
β Do'sβ
- Consider creating a mega menu if you have a website with too many top-ranking pages or categories.
- Use clear typography, enough spacing, and a neat layout to create readable dropdowns.
- Keep the dropdown items under two levels deep.
β Don'tsβ
- Avoid dropdowns that are too long and force users to scroll down to see all the available options at a glance.
- Don't use the Dropdown component for attribute selection and form fillings. Instead, use the Select component.
Accessibilityβ
- Check if the menu works in all browsers and is easily navigable for everyone.
- The
DropdownButton
andDropdownItem
s must be finger-friendly for mobile users and large enough for reliable interactions. Generally, touch targets are at least 44 by 44 CSS pixels. - Text elements must have sufficient color contrast against the background.
- Provide visual feedback on interactions. Whenever a user interacts with the
DropdownButton
orDropdownItem
, the button should change its state and let the user know that something is happening as a consequence. - Make sure that the dropdown works on a tabbing map (i.e., when a user uses βtabβ to navigate an interface and βenterβ to input information).