Skip to content

Import

import { Dropdown } from '@dnb/eufemia'

Description

The Dropdown component is a fully custom-made component. This allows us to change its form based on context (small screens, touch devices, etc.).

When to use Dropdown vs Eufemia Forms

Classic form components like this one are presentational controls. They handle the styling, sizing, icons, and basic events, while you manage their value, validation, and error handling yourself.

For most data input and forms situations, use Eufemia Forms fields instead. They build on these same components, but add data handling, validation, and error messages through the surrounding Form.Handler. Browse the field components to find the one that matches your data.

Reach for a classic component when you need it standalone outside of a form context, or when you handle the value and validation yourself.

The Eufemia Forms equivalent of Dropdown is Field.Selection (the default dropdown variant).

Relevant links

When to use

Use a dropdown when you need to provide many options to the user but don't have space to display them all. The hidden options should only appear when the user requests them, reducing visual clutter.

  1. When space is limited
  2. When you want to reduce visual clutter
  3. When it's intuitive for users to request hidden content

When not to use

  1. Do not use a dropdown if you have only a few options that could be shown using Radio buttons or ToggleButtons.

Note: This pattern can be constructed in various ways to achieve a similar effect—from using the HTML select element to custom building with divs, spans, and JavaScript.

Accessibility

When preventSelection is true, the Dropdown will use role="menu", instead of role="listbox" for better screen reader support.

Custom size

You can change the width of the Dropdown component with CSS by using:

.dnb-dropdown {
--dropdown-width: 20rem; /* custom width */
}

You can also set the width directly, but then it has to be defined like so (including min-width):

/** Because of the included label/status etc. we target the "__shell" */
.dnb-dropdown__shell {
width: 10rem;
}
/** In order to change only the drawer-list width */
.dnb-dropdown .dnb-drawer-list__root {
width: 10rem;
}
/** If using popup style (no title) */
.dnb-dropdown--is-popup .dnb-drawer-list__root {
width: 10rem;
}

Root Element (React Portal)

The Dropdown component uses PortalRoot internally to render its option list. See the PortalRoot documentation for information on how to control where the portal content appears in the DOM, and for the BrowserTranslate helper when browser translation tools such as Google Translate should not modify content rendered through PortalRoot.

Related components

Dropdown is part of the Input category. Other components for similar needs:

  • Autocomplete — to help people find and choose from matching suggestions as they type.
  • Checkbox — when people can turn one or more options on or off.
  • DatePicker — when people need to choose one date or a date range.
  • Filter — to help people narrow down a list or data set.
  • FormLabel — to name an input, control, or form-related field.
  • Input — when people need to enter a short line of text.

See all in Input →

Demos

Default dropdown

No value is defined, but a title is given.

Dropdown with different item content directions

Icon on left side

Dropdown as tertiary variant

Dropdown in different sizes

Four sizes are available: small, default, medium and large

Custom width

Dropdown with status

And vertical label layout.

Findable list

With long list to make it scrollable and searchable

Disabled dropdown

Individual options can also be disabled.

Disabled tertiary dropdown

Customized Dropdown

An example of how you can customize the look of your Dropdown

DrawerList opened

Only to visualize and used for visual testing

Groups

If an item has a groupIndex property, it will use the groups in the groups property. Only the first group can be without title, all other groups must have a title.

No divider

We can remove the divider between items with the noDivider prop. Beware that this can make information dense lists difficult to parse.