Dropdown
Dropdown displays a list of actions, options or links. It is triggered when a user interacts with a Button, Textfield or other control. Dropdown allows for complex functionality that can’t be accomplished with SelectList.
Props
Usage guidelines
- Displaying a list of actions, options, or links. Usually displays 3 or more options.
- Allowing complex functionality that a SelectList can't accomplish.
- Taking immediate action or navigating users to another view.
- In cases when there are less than 3 items in the list, and there is space to display all options. Consider RadioGroup or Checkboxes instead.
- When it is desirable to filter a long list of options. Use ComboBox instead.
- Displaying a list of actions or options using the browser's native select functionality. Use SelectList instead.
Best practices
Use Dropdown when features such as subtext, custom headers or badges are needed, since this functionality is not available in SelectList.
Use Dropdown for a simple list of items. Use SelectList instead for the added native mobile functionality. The exception to this is multiple Dropdowns or SelectLists that could be grouped together to create visual inconsistency, such as filters. In this case, use Dropdowns for all.
Order the items in Dropdown either alphabetically or by usage. Place destructive actions at the bottom.
Attach Tooltips to menu items. Use the `subtext` property if additional explanation is needed.
Add an icon indicator when links are external using the isExternal
prop. External links are either links outside of Pinterest or another sub-site of Pinterest.
Add custom elements within Dropdown. While some custom elements may be technically possible, it is best to avoid customization that becomes difficult to maintain.
Accessibility
ARIA attributes
Remember to include the following ARIA attributes on the element used for the anchor
prop:
accessibilityControls
: lets the screen reader know that this element controls the Dropdown menu (should match theid
property passed to Dropdown). Populates the aria-controls attribute.accessibilityHaspopup
: lets the screen reader know that there is a Dropdown menu linked to the trigger. Populates the aria-haspopup attribute.accessibilityExpanded
: informs the screen reader whether the Dropdown menu is currently open or closed. Populates the aria-expanded attribute.
Keyboard interaction
- Hitting
Enter
orSpace
key on the Dropdown's trigger opens the menu Escape
key closes the menu, while moving focus back on the Dropdown's trigger- Arrow keys are used to navigate items within the menu
Enter
key selects an item within the MenuTab
orShift + Tab
close the menu and move focus accordingly
Localization
Truncation
When the text of the Dropdown.Item becomes longer than the width of the menu, either intentionally or through localization, the text will truncate at one line. Subtext will wrap as needed to display the full text.
Subcomponents
Dropdown.Item
Use Dropdown.Item for action & selection, when the Dropdown item triggers an action or selects an option.
Dropdown.Item Props
Dropdown.Link
Use Dropdown.Link for navigation, when the Dropdown item navigates to a new page.
Dropdown.Link Props
Dropdown.Section
Use Dropdown.Section to create hierarchy within a single Dropdown.
Dropdown.Section Props
Variants
Types of items
Typically a Dropdown item triggers an action, like “Hide a Pin”, or makes a selection, like “Cozy” for a layout setting. Use Dropdown.Item for these use cases. onSelect
handles the user interaction, with the optional selected
indicating the currently-selected item.
If an item navigates to a new page, use Dropdown.Link with the required href
prop. If the item navigates to a page outside of the current context, (either a non-Pinterest site or a different Pinterest sub-site), the isExternal
prop should also be specified to display the "up-right" icon. Optional additional actions to be taken on navigation are handled by onClick
. Dropdown.Link can be paired with OnLinkNavigationProvider. See OnLinkNavigationProvider to learn more about link navigation.
Sections
Dropdown can also be composed of Dropdown.Section(s), which simply require a label. Use Dropdown.Section(s) to create hierarchy within a single Dropdown. Dropdown.Sections, Dropdown.Items and Dropdown.Links can be mixed as needed.
Custom header
Dropdown can also contain a custom header by specifying headerContent
, which always appears at the very top of the menu. It can be used instead of a section header if the menu contains only one type of content that needs additional description. It can contain anything, but most often will contain just text and/or a link.
Subtext
Each Dropdown item can also contain subtext
below the label. This subtext
will wrap if needed. Use this text to add an additional description of the Dropdown item.
Badges
A Badge can be used to indicate a new product surface or feature within the Dropdown using badgeText
. Multiple badges within a Dropdown should be avoided when possible.
Custom item content
If needed, users can supply custom content to each Dropdown.Item or Dropdown.Link. This can be useful when extra functionality is needed. However, please use with caution and only when absolutely necessary.
To ensure the entire width of the item is clickable, you will likely need to surround your custom content with a full-width Box.
Subcomponent composability
Under the hood, Dropdown executes two actions: recognizing subcomponents by display name and sequencially indexing each subcomponent for keyboard navigation.
Dropdown requires its own subcomponents as children to build the list of actions.
When building a Dropdown, we might want to render different combinations of subcomponents conditionally. Dropdown supports simple conditional rendering of subcomponents lists wrapped in React.Fragment as well as consecutive arrays of subcomponent arrays. See the example below which illustrates both of these cases. More logic complexity might break the correct Dropdown behavior.
Component quality checklist
Quality item | Status | Status description |
---|---|---|
Figma Library | Component is not currently available in Figma. | |
Responsive Web | Ready | Component is available in code for web and mobile web. |
iOS | Component is not currently available in code for iOS. | |
Android | Component is not currently available in code for Android. |
Related
Button, IconButton
It is most common to anchor Dropdown to Button or IconButton.
ScrollBoundaryContainer
ScrollableContainer is needed for proper positioning when the Dropdown is located within a scrolling container. The use of ScrollableContainer ensures the Dropdown remains attached to its anchor when scrolling.
SelectList
If users need to select from a short, simple list (without needing sections, subtext details, or the ability to filter the list), use SelectList.
ComboBox
If users need the ability to choose an option by typing in an input and filtering a long list of options, use ComboBox.
OnLinkNavigationProvider
OnLinkNavigationProvider allows external link navigation control across all children components with link behavior.