MazSelect - with "multiple" options
MazSelect is a standalone component that replaces the standard html input select with a beautiful design system. There are many options like multiple values, search text field, custom templates options, colors, sizes, disabled, loading, error, warning, valid states, error messages, and icons.
Before use it, you should install the MazUi plugin in your project, follow instructions in Getting Started
TIP
This component can be translated globally using the MazUi plugin.
Basic usage
selectedValue:
Multiple
selectedValues:
Search
Use search property to add a search input in the options list
TIP
You can use your own template to replace the empty icon when no results are found
View code
<MazSelect>
<template #no-results>
<div class="p-4 text-center">No result</div>
</template>
</MazSelect>INFO
You can adjust the search results by using search-threshold where 1 is a perfect match and 0 is a match with any character
<MazSelect :search-threshold="0.75" :options="[...]" />Custom search function
You can provide your own search function to customize the search behavior
Opt Group
Group your options like a native optgroup
Disabled
Size
Custom template options
Customize the options list with your own template
Custom options model
By default, the options should be an array of { value: any, label: string }
If you want custom keys of these options, you can use:
option-value-keyto override the key of the value in your optionoption-label-keyto override the key of the label to show in the option listoption-input-value-keyto override the key of the value to show in the input
Example
Types
type ModelValueSimple = string | number | null | undefined | booleanAccessibility
MazSelect follows the WAI-ARIA combobox pattern with a listbox popup:
- The input is a
combobox(aria-haspopup="listbox",aria-expanded,aria-controls). - The list is a
listbox(aria-multiselectablein multiple mode) labelled by thelabel,top-labelorplaceholder, each option is anoptionwitharia-selected. - Keyboard: ↓ / ↑ / Space or a letter open the list, the arrows move between options, Home / End go to the first / last option, Enter selects, Esc closes.
- The labels read by screen readers (toggle button, empty results) come from
@maz-ui/translations(arianamespace).
Props
| Name | Description | Type | Required | Default | Possible values |
|---|---|---|---|---|---|
| id | The id of the select | string | No | - | - |
| label | The label of the select | string | No | - | - |
| top-label | Static label displayed above the input field. Unlike the floating label, this remains fixed | string | No | - | - |
| placeholder | The placeholder of the select | string | No | - | - |
| model-value | v-model The value of the select | (Multiple extends true ? Value[] : Value) | No | - | - |
| options | The options of the select | Option[] | Yes | - | - |
| option-value-key | The key of the option value | string | No | "value" | - |
| option-label-key | The key of the option label | string | No | "label" | - |
| option-input-value-key | The key of the option input value | string | No | "label" | - |
| list-position | The position of the list (auto by default - will switch between bottom-start and top-start) | MazPopoverPosition | No | "auto" | - |
| prefer-position | The prefer position of the list | MazPopoverPreferPosition | No | "bottom-start" | - |
| fallback-position | The fallback position of the list | MazPopoverFallbackPosition | No | "top-start" | - |
| item-height | The height of the option list item | number | No | - | - |
| max-list-height | The max height of the option list | number | No | 240 | - |
| max-list-width | The max width of the option list | number | No | - | - |
| min-list-height | The min height of the option list | number | No | - | - |
| min-list-width | The min width of the option list | number | No | - | - |
| size | The size of the select | "xs" | "sm" | "md" | "lg" | "xl" | "mini" | No | 'md' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'mini' |
| color | The color of the select | "primary" | "secondary" | "accent" | "info" | "success" | "warning" | "destructive" | "contrast" | "transparent" | No | "primary" | 'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'destructive' | 'contrast' | 'transparent' |
| search | Display search input in option list | boolean | No | - | - |
| search-function | Replace the default search function to provide a custom search function | ((query: string, options: Option[]) => Option[] | undefined) | No | - | - |
| search-threshold | The threshold for the search input where 1 is a perfect match and 0 is a match with any character | number | No | 0.75 | - |
| multiple | Enable the multiple selection | Multiple | No | false | - |
| required | Make the input required in the form | boolean | No | - | - |
| disabled | Disable the component | boolean | No | - | - |
| block | The input will be displayed in full width | boolean | No | - | - |
| autocomplete | The autocomplete attribute of the input | string | No | "off" | - |
| translations | The translations of the component | Partial<{ searchPlaceholder: string; }> | No | { searchPlaceholder: 'Search in options', } | - |
| format-input-value | The function to format the input value | ((value: Multiple extends true ? Value[] : Value) => string) | No | - | - |
| transition | The transition name of the panel list options | string | No | "scale-fade" | - |
| open | v-model:open | boolean | No | false | - |
Events
| Event name | Payload | Description |
|---|---|---|
| update:model-value | value: Multiple extends true ? Value[] : Value | On model value update, returns the new value |
| open | - | On list is opened |
| close | - | On list is closed |
| blur | value: Event | On input blur |
| change | value: Event | On input change value |
| focus | value?: Event | undefined | On input focus |
| input | value: Event | On input value |
| selected-option | value: Option | On selected value, returns the option object |
| update:open | value: boolean |
Slots
| Name | Description | Bindings |
|---|---|---|
| start-icon | Add a custom inline-start icon (left in LTR, right in RTL) | isOpen false - Current open state of the popoverclose () => void - Function to close the popoveropen () => void - Function to open the popovertoggle () => void - Function to toggle the popover |
| end-icon | Add and replace a custom inline-end icon (right in LTR, left in RTL) | isOpen false - Current open state of the popoverclose () => void - Function to close the popoveropen () => void - Function to open the popovertoggle () => void - Function to toggle the popover |
| no-results | No results slot - Displayed when no results corresponding with search query | - |
| optgroup | Custom optgroup label | label string | number | true - the label of the optgroup |
| default | Custom option | option Option - the option objectisSelected boolean - if the option is selectedisOpen false - if the popover is openclose () => void - function to close the popoveropen () => void - function to open the popovertoggle () => void - function to toggle the popover |