Skip to content

Select ​

A Select is an input with a dropdown menu of predefined, selectable options.

NameValue
Props
disabled
defaultLabel
defaultIcon
status
View
Reading direction
Note: For icon properties, the relevant icon also needs to be imported from the @wikimedia/codex-icons package. See the usage documentation for more information.

Overview ​

When to use Select ​

Use the Select component when users need to choose an option from a short, predefined list.

When not to use:

  • If the list of options is too long, consider using Lookup instead.
  • If users need to be able to select multiple options, use a Checkbox group (for a short list of options) or MultiselectLookup (for a long list).
  • If users need to be able to select a predefined option or enter their own custom value, use Combobox.

About Select ​

Select includes the following elements.

Default icon (optional) ​

A default icon can be included alongside the default label to visually enhance the Select's purpose.

  • Use a simple icon that is easily understandable to users.
  • Include an icon when the menu items also contain icons.

Label ​

The Select will display the label of its selected item. If nothing is selected, a default label can be displayed.

  • The default label text should clearly indicate the kinds of options that follow. Clear & Trustworthy

  • Don't make the default label a part of a sentence that is completed by the options. Translatable

When the Select is open, a Menu with options is displayed. These options can use all the features of the MenuItem component.

  • 2–5 menu items are recommended for optimal usability.
  • When there are more items, consider setting a visible item limit to enable scrolling.

Examples ​

Basic usage ​

Menu items must have a value, and can have a label that gets output in the Select component. If no label is provided (like the third menu item in this example), the value will be displayed.

With icons ​

The defaultLabel and menuItems can have icons.

With custom label display ​

You can customize how the label of the selected item appears.

Developer notes

The label scoped slot enables you to customize the display of the label, with bindings for the selectedMenuItem and the defaultLabel.

With menu groups ​

You can group menuItems to improve organization. Groups can be customized to add a description or an icon.

Developer notes

You can add optgroup-like groupings within the Select via the menuItems prop. Refer to the MenuGroupData type for more information about the configuration options for each menu group.

Form field ​

A Select can be wrapped in the Field component to add features like a semantic label, description and help text, validation messages, and more. Refer to the Field page for more information.

Select a search interface to use by default
Special:Search is better for searching text-based items like articles. Special:MediaSearch provides a better interface for searching files.

Other features ​

The Select component has an internal Menu. You can use the following features from Menu in the Select component:

Technical implementation ​

Vue usage ​

Menu items are provided as an array of MenuItemData types, and v-model is used to bind the current selection's value.

Props ​

Prop nameDescriptionTypeDefault
menuItems(required)Menu items and/or menu group definitions.

Menu groups and individual menu items will be output in the order they appear here.
(MenuItemData|MenuGroupData)[]
selected(required)Value of the current selection.

Must be bound with v-model:selected.

The property should be initialized to null rather than using a falsy value.
string|number|null
defaultLabelLabel to display when no selection has been made.string''
disabledWhether the dropdown is disabled.booleanfalse
menuConfigConfiguration for various menu features. All properties default to false.

See the MenuConfig type.
MenuConfig{}
defaultIconAn icon at the start of the select element displayed when no selection has been made.Icon|undefinedundefined
statusstatus attribute of the input.ValidationStatusType'default'

Events ​

Event namePropertiesDescription
load-moreWhen the user scrolls towards the bottom of the menu.

If it is possible to add or load more menu items, then now would be a good moment so that the user can experience infinite scrolling.
update:selectedmodelValue string|number|null - The new model valueWhen the selection value changes.

Slots ​

NameDescriptionBindings
labelDisplay of the current selection or default labelselected-menu-item MenuItemData, undefined - The currently selected menu
default-label string - The default label, provided via a prop
menu-itemDisplay of an individual item in the menumenu-item MenuItemData - The current menu item

CSS-only version ​

Markup structure ​

The CSS-only version of this component uses the native <select> element. This element will be styled to match the Vue version, but the menu will use native browser styles.

Disabled ​

Add the disabled attribute to the <select> element to get a disabled element with appropriate styles.

Keyboard navigation ​

KeyFunction
Down arrowWhen the focus is placed on the input, it opens the menu. When the menu is open, it navigates through menu options. If pressed at the last visible option, it scrolls to the next "hidden" menu item.
Up arrowWhen the focus is placed on the input, it opens the menu. When the menu is open, it navigates through menu options.
EnterIt expands and collapses the menu when the focus is placed on the Select. If the focus is placed in any of the options within the menu, the focused option is selected.
EscThis key closes the menu when it is open.
HomeOptionally, it moves the focus to the first option. Optionally, in a single-select listbox, selection may also move with focus. Supporting this key is strongly recommended for lists with more than five options.
EndOptionally, it moves the focus to the last option. Optionally, in a single-select listbox, selection may also move with focus. Supporting this key is strongly recommended for lists with more than five options.