Combobox β
A Combobox is a text input with a dropdown menu of selectable options.
Name | Value |
---|---|
Props | |
status | |
disabled | |
View | |
Reading direction |
Overview β
When to use Combobox β
Use the Combobox component when it's difficult to predict the user's response to a prompt. It provides predefined input values as options, for example common responses, to make it easier to complete the field.
If users can only select a predefined option, use Select (for a short list of options) or Lookup (for a longer, searchable list).
About Combobox β
Combobox allows users to either input text or select a value from a menu of options to complete a form field. Combobox includes the following elements.
Start icon (optional) β
A start icon can be included to visually enhance the Combobox's purpose.
- Use a simple icon that is easily understandable to users.
Input β
The user can type text into the TextInput. If they select an item from the menu, it will appear in the TextInput.
Placeholder text (optional) β
Placeholder text provides an example of what type of information is being requested in the input.
- Placeholder text should further illustrate and support the Combobox's label.
- Placeholder text should never replace the label nor be the input's only description.
Menu β
When the Combobox is expanded, a Menu of 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 β
The Combobox component combines a menu of selectable items with a text box that can accept arbitrary input from the user.
Developer notes
The component should receive a v-model:selected
binding from its parent as well as an array of menuItems
(which can be empty).
With configurable scroll β
By default, all menu items are displayed when the menu is expanded. You can configure a visibleItemLimit
to limit the height of the menu and enable scrolling.
Developer notes
To limit the height of the menu and enable scrolling, use the visibleItemLimit
property of the menuConfig
prop.
With filtering β
When there are many options, you can filter items depending on the current input.
- Include a "no results" message when no matching items are found.
Developer notes
Add a "no results" message via the no-results
slot. If populated, this slot will automatically display when there are zero menu items.
Form field β
A Combobox 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.
Other features β
The Combobox component has an internal TextInput and Menu. You can use the following features from those components in the Combobox component:
- Start and end icons
- Clearable
- Custom menu item display
- Limited height with scrolling
- Menu groups
- MenuItem features
Technical implementation β
Vue usage β
TextInput props apply
This component contains a TextInput component. You can bind TextInput props to this component and they will be passed to the TextInput within.
Attributes passed to input
This component will pass any HTML attributes applied to it, except for CSS class, to the <input>
element within the component.
Props β
Prop name | Description | Type | Default |
---|---|---|---|
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 . | string|number | |
disabled | Whether the dropdown is disabled. | boolean | false |
menuConfig | Configuration for various menu features. All properties default to false. See the MenuConfig type. | MenuConfig | {} |
status | status property of the TextInput component | ValidationStatusType | 'default' |
Events β
Event name | Properties | Description |
---|---|---|
input | event InputEvent | When the input value changes via direct use of the input |
change | event Event | When an input value change is committed by the user (e.g. on blur) |
load-more | When 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:selected | selected string|number - The new selected value | When the selected value changes. |
focus | event FocusEvent | When the input comes into focus |
blur | event FocusEvent | When the input loses focus |
Slots β
Name | Description | Bindings |
---|---|---|
menu-item | Display of an individual item in the menu | menu-item MenuItemData - The current menu item |
no-results | Message to show if there are no menu items to display. |
Keyboard navigation β
Key | Function |
---|---|
Tab | It places the focus within the input of the Combobox and opens its menu. It also moves the focus to the next interactive element in tab order. |
Shift + Tab | When the focus is placed within the Combobox input, it moves the focus to the previous interactive element. |
Down arrow | When the Combobox is focused, 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 arrow | When the Combobox is focused, it opens the menu. When the menu is open, it navigates through menu options. |
Enter | It opens the menu when the focus is placed on the Combobox. If the menu is open, it closes the menu. If the focus is placed in any of the options within the menu, the focused option is selected. |
Esc | When the menu itβs open, it closes the menu. |
Home | Optionally, 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. |
End | Optionally, 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. |