Dropdown

Dropdown Component

Contributed by Chaoyang Li

Dropdown allow users to choose from a list of options in a limited space. The list of options can change based on the context.

Basic Component

The select tag can be used to create a dropdown component.

Code Usage

Variants

With dividers

The optgroup tag is used to group related options in a drop-down list.

Code Usage

With icons

You can add icons to the options in the dropdown. The select tag doesn't support this requirement.

Code Usage

With header

A Simple header in the dropdown can show the current status. The select tag doesn't support this requirement.

Code Usage

Usability

Include a label

Every picker should have a label. A picker without a label is ambiguous and not accessible.

Keep menu items concise

Keep menu items short and concise. Long menu items that cause text to wrap to multiple lines are discouraged. If text wrapping becomes a frequent concern, consider revising the text or use alternative UI patterns that will give your content more space.

Choose an appropriate width

When possible, the field button width should be wide enough so that any chosen menu items can be displayed in full.

Accessibility

The select tag supports keyboard operation.

KeyInteraction
SpaceSelects the dropdown item in focus, closes the dropdown menu and moves focus to the field button.
Up or Down ArrowMoves focus to previous or next option item in the dropdown. Does not loop when the last or first menu item is reached.
EnterChooses the option item that you selected in the dropdown and close the dropdown menu.
EscCloses the popover menu and moves focus to the field button.

Attributes

The select tag includes the global attributes.

AttributeDescriptionValue
autofocusSpecifies that the drop-down list should automatically get focus when the page loadsBoolean
disabledSpecifies that a drop-down list should be disabledBoolean
multipleSpecifies that multiple options can be selected at onceBoolean
nameDefines a name for the drop-down listString
requiredSpecifies that the user is required to select a value before submitting the formBoolean
sizeDefines the number of visible options in a drop-down listNumber

Vision

VersionEditorAuthorDateDescription
v1.0Chaoyang LiChaoyang Li28/09/2023Initial version