AisCombobox
Comboboxes are the foundation of accessible autocompletes and command palettes for your app, complete with robust support for keyboard navigation.
Option specification
An array of strings or objects that define the selectable options for your Combobox.
String options
The first method to populate a Combobox is to bind the options prop to an array of strings.
John Smith
v-model: John Smith
Object options
The options prop will also accept structured data in the form of an array of objects. By default, the component will use the following field keys to populate each option: label, value, and disabled.
Michael Jordan
v-model: 23
Object Keys
If your objects don't have those default field keys, or you just want to use different field keys from your objects, you can use these props: labelKey, valueKey, and disabledKey.
Chancey Yepiskov
v-model: 71708376
multiple
Use the multiple boolean prop to allow for selecting more than one option. You will also need to bind an array as your v-model instead of binding a string.
Durward Reynolds, Kenton Towne
v-model: [
1,
2
]
check-on-right
The checkmark icon that represents the selected option is displayed on the left side of the option by default. To display this checkmark on the right, use the check-on-right boolean prop. You can use check-on-right by itself or :check-on-right="true".
Michael Jordan
v-model: Michael Jordan
display-value
This only applies when the options are objects. This prop accepts a function which returns the string to be displayed in the input for the selected option.
Franky Stokey (franky-stokey@uiowa.edu)
v-model: fstokey2
size
The size prop takes the standard sm, md, and lg values and adjusts the size of the combobox accordingly.
Michael Jordan
icon
AisCombobox accepts an icon prop to display an icon in the combobox. icon will accept either a FontAwesome icon definition or a string for one of our standard icons.
Michael Jordan
selected-icon
AisCombobox accepts a selected-icon prop to override the default icon used to identify the selected combobox option. selected-icon will accept either a FontAwesome icon definition or a string for one of our standard icons.
John Smith
v-model: John Smith
class
AisCombobox accepts a selected-icon-class prop to customize the selected icon
John Smith
v-model: John Smith
slot
AisCombobox offers a selected-icon slot to override the default icon used to identify the selected combobox option.
BJ Armstrong
v-model: 10
disabled
Use the boolean disabled prop to disable an AisCombobox. You can use disabled by itself or :disabled="true". A combobox within a disabled AisForm or AisField will automatically be set to disabled.
Michael Jordan
Michael Jordan
invalid
Use the boolean prop invalid to mark an AisCombobox as invalid. You can use invalid by itself or :invalid="true". A combobox inside an AisField with errors will automatically be set to invalid.
Michael Jordan
Larry Bird
- This field has an error
status
AisCombobox accepts a status prop to place the input in a logical state. status will accept the values: busy, success, error, and required. The current state will be expressed through an icon on the right side of the input.
Developers are responsible for maintaining a field's status as a user works through a particular process flow.
Michael Jordan
Rounded
Add one of the Tailwind rounded classes to the class attribute of the AisCombobox.
Michael Jordan
Create
If you want to allow your users to enter a value that isn't already in the options list, then use the create prop. The create prop accepts an asynchronous function. This async function will:
- be called when the "Create" submit button is clicked on the "Add new Option" screen
- receive the new option object as the first and only parameter
- need to make an async call to your backend to add the option to your database
- need to refresh the combobox options
Additional props to customize the built-in create feature:
create-label: thisstringwill be appended to "Add " and will be displayed in the combo footer and as the title of the create panelcreate-opt-value-label: thisstringwill be the label for the field of the new option valuecreate-opt-descr-label: thisstringwill be the label for the field of the new option description/label
Checking Account
v-model: 1234560
Action Slot
If you want to add your own custom action screen within the combobox, use the action slot combined with the footer slot. Add something to the footer for the user to click to show your action screen using the slot prop showActionSlot. Add your custom screen in the action slot and use the slot prop hideActionSlot to easily hide the action screen and return to the combobox options screen.
R2-D2
v-model: r2d2
Events
@update:modelValue
AisCombobox uses Vue 3's standard v-model configuration. As a result, you can bind the @update:modelValue to do additional work when the selection changes. It will be fired every time v-model changes.
@load
The @load event fires when the combobox is loaded. The event's payload contains the selected value from the options array. If options is an array of objects, the payload will be the selected object and not the primitive value emitted by v-model.
@load may be used to capture the selected object or to trigger additional initialization logic. See the code example for @change to see how the two events work together.
@change
The @change event fires when the user selects a new value. The event's payload contains the selected value from the options array. If options is an array of objects, the payload will be the selected object and not the primitive value emitted by v-model. This is what makes @change different from @update:modelValue.
@change may be used to capture the selected object or to trigger additional work. When capturing the selected object, use @load to initialize the selection. Notice how both v-model and selectedObject have a value on page load in the example below.
Chancey Yepiskov
v-model:
71708376
selectedObject:
{}
Component Reference
Props
Property | Type(s) | Required | Default | Description | Deprecated |
|---|---|---|---|---|---|
| checkOnRight | Boolean | false | When true, the checkmark(s) indicating selection will be on the right instead of the left | false | |
| create | Func | | The asynchronous Function to be called when the Create button is clicked. This is the function where you can add
your logic for adding the new option to your backend/db/store/etc.
Note: Function must be async | false | |
| createLabel | String | 'new option' | Label to be displayed in the create button in the combobox footer, and as the title of the create option panel | false | |
| createOptDescrLabel | String | 'New Option Description/Label' | Label to be displayed on the new option description field. | false | |
| createOptValueLabel | String | 'New Option Value' | Label to be displayed on the new option value field. | false | |
| disabled | Boolean | false | Places component in a disabled state, when true | false | |
| disabledKey | String | 'disabled' | The property in the option object that will be used to determine whether the component is disabled | false | |
| displayValue | Func | undefined | Customize the display text for the selected options | false | |
| icon | Undefined | undefined | Optional icon to be displayed immediately prior to the text in the combobox default/collapsed view. Accepts
either an object imported from the FontAwesome icon packs or a string specifying one of the preloaded,
core icons | false | |
| invalid | Boolean | false | Places component in a invalid state, when true | false | |
| labelKey | String | 'label' | The property in the option object that the user will see as the option label | false | |
| menuHeight | Array, String | 'max-h-[400px]' | Classes to set the height of the menu/options container | false | |
| menuWidth | Array, String | 'w-96' | Classes to set the width of the menu/options container. | false | |
| modelValue | Array, Number, String | '' | The selected value(s). If multiple, return value is Array; otherwise, String | false | |
| multiple | Boolean | false | When true, multiple selections are allowed.
Note: v-model must be an Array | false | |
| options | Array | [] | The combobox options | false | |
| placeholder | String | '' | Placeholder text for combobox | false | |
| rounded | Boolean, String | undefined | Applies rounded corners using
TailwindCSS's rounded classes | false | |
| selectedIcon | Undefined | undefined | The icon that designates the selected option. Accepts either an object imported from the FontAwesome icon packs
or a string specifying one of the preloaded, core icons | false | |
| selectedIconClass | Array, String | '' | Classes to set to the selectedIcon. | false | |
| size | String | undefined | Set the size of the component's appearance Valid values: xs, sm, md, lg, xl | false | |
| status | String | undefined | Optional icon on the right side of the header to indicate the logical state of the card Valid values: busy, success, error, required | false | |
| valueKey | String | 'value' | The property in the option object that the user will see as the option value | false |
Slots
Name | Scoped | Description |
|---|---|---|
| action | Slot for customizing the combobox action screen | |
| footer | Slot for customizing the combobox menu footer | |
| selectedIcon | No | Slot for customizing the icon used to designate the selected option |
Events
Event | Arguments | Description |
|---|---|---|
| change |
| Emitted when the selected values change |
| load |
| Emitted when the combobox first loads, returning the initial selected option Object(s) |
| update:modelValue |
| Emitted when the selected values change |