Dropdown
Pilot

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.

Name
Type
Default
React.ChildrenArray<React.Element<typeof DropdownItem | typeof DropdownSection>>
-

Must be instances of Dropdown.Item, Dropdown.Link or Dropdown.Section components. See the Types of items variant to learn more.

string
-

Unique id to identify each Dropdown. Used for Accessibility purposes.

() => void
-

Callback fired when the menu is closed.

?HTMLElement
-

Ref for the element that the Dropdown will attach to, will most likely be a Button. See the Accessibility guidelines to learn more.

boolean
false

Removes the Layer component around Popover. Should only be used in cases where Layer breaks the Dropdown positionings such as when the anchor element is within a sticky component.

React.Node
-

Content to display at the top of the Dropdown before any items or sections. See the Custom header variant to learn more.

"up" | "right" | "down" | "left"
"down"

Preferred direction for the Dropdown to open.

interface Indexable { index(): number; }
-

An object representing the zIndex value of the Dropdown menu. Learn more about zIndex classes

Name
Type
Default
({| event: SyntheticInputEvent<>, item: {label: string, value: string, subtext?: string} |}) => void
-

Callback when the user selects an item using the mouse or keyboard.

{| label: string, value: string, subtext?: string |}
-

Object detailing the label, value, and optional subtext for this item.

string
-

When supplied, will display a Badge next to the item's label. See the Badges variant to learn more.

React.Node
-

If needed, users can supply custom content to each Dropdown Item. This can be useful when extra functionality is needed beyond a basic Link. See the Custom item content variant to learn more.

{| label: string, value: string, subtext?: string |} | Array<{| label: string, value: string, subtext?: string |}>
-

Either the selected item info or an array of selected items, used to determine when the "selected" icon appears on an item.

Name
Type
Default
string
-

Directs users to the url when item is selected. See the Types of items variant to learn more.

{| label: string, value: string, subtext?: string |}
-

Object detailing the label, value, and optional subtext for this item.

string
-

When supplied, will display a Badge next to the item's label. See the Badges variant to learn more.

React.Node
-

If needed, users can supply custom content to each Dropdown Item. This can be useful when extra functionality is needed beyond a basic Link. See the Custom item content variant to learn more.

boolean
-

When true, adds an arrow icon to the end of the item to signal this item takes users to an external source and opens the link in a new tab. Do not add if the item navigates users within the app. See the Best practices for more info.

AbstractEventHandler<| SyntheticMouseEvent<HTMLButtonElement> | SyntheticMouseEvent<HTMLAnchorElement> | SyntheticKeyboardEvent<HTMLAnchorElement> | SyntheticKeyboardEvent<HTMLButtonElement>, {| dangerouslyDisableOnNavigation: () => void |}
-

Callback fired when clicked (pressed and released) with a mouse or keyboard.

See OnLinkNavigationProvider to learn more about link navigation.

Name
Type
Default
React.ChildrenArray<React.Element<typeof DropdownItem>>
-

Any Dropdown.Items and/or Dropdown.Links to be rendered

string
-

Label for the section. See the Sections variant for more info.

Usage guidelines

When to Use
  • 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.
When Not to Use
  • In cases when there are less than 3 items in the list, and there is space to display all options. Consider RadioButtons 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

Do

Use Dropdown when features such as subtext, custom headers or badges are needed, since this functionality is not available in SelectList.

Don't

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.

Do

Order the items in Dropdown either alphabetically or by usage. Place destructive actions at the bottom.

Don't

Attach Tooltips to menu items. Use the `subtext` property if additional explanation is needed.

Do

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.

Don't

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 the id 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 or Space 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 Menu
  • Tab or Shift + 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.

Variants

Types of items

Action/Selection

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.

Link

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.

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.

Typeahead
If users need the ability to choose an option by typing in an input and filtering a long list of options, use Typeahead.

OnLinkNavigationProvider
OnLinkNavigationProvider allows external link navigation control across all children components with link behavior.