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.
INFO
Before you have to import the global css files in your project, follow instructions in Getting Started
TIP
This component use MazInput, so it inherits all his props
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
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-key
to override the key of the value in your optionoption-label-key
to override the key of the label to show in the option listoption-input-value-key
to override the key of the value to show in the input
Example
Types
type ModelValueSimple = string | number | null | undefined | boolean
Props, Event & Slots
Props
Prop name | Description | Type | Values | Default |
---|---|---|---|---|
style | Style attribut of the component root element | TSIndexedAccessType | - | undefined |
class | Class attribut of the component root element | TSIndexedAccessType | - | undefined |
id | The id of the select | string | - | undefined |
modelValue | The value of the select | union | - | undefined |
options | The options of the select | Array | - | undefined |
optionValueKey | The key of the option value@default 'value' | string | - | 'value' |
optionLabelKey | The key of the option label@default 'label' | string | - | 'label' |
optionInputValueKey | The key of the option input value@default 'label' | string | - | 'label' |
listPosition | The position of the list@default 'bottom left' | Position | - | 'bottom left' |
itemHeight | The height of the option list item | number | - | undefined |
maxListHeight | The max height of the option list | number | - | 240 |
maxListWidth | The max width of the option list | number | - | undefined |
minListHeight | The min height of the option list | number | - | undefined |
minListWidth | The min width of the option list | number | - | undefined |
size | The size of the select@default 'md' | Size | - | 'md' |
color | The color of the select@default 'primary' | Color | - | 'primary' |
search | Display search input in option list | boolean | - | |
searchPlaceholder | The placeholder of the search input@default 'Search in options' | string | - | 'Search in options' |
searchFunction | Replace the default search function to provide a custom search function@default undefined | TSFunctionType | - | |
searchThreshold | The threshold for the search input where 1 is a perfect match and 0 is a match with any character@default 0.75 | number | - | 0.75 |
open | if true, the option list is opened by default | boolean | - | |
multiple | Enable the multiple selection | boolean | - | undefined |
required | Make the input required in the form | boolean | - | |
disabled | Disable the component | boolean | - | |
block | The input will be displayed in full width | boolean | - | |
excludeSelectors | The exclude selectors for the v-closable directive - will exclude the elements from the directive | Array | - | undefined |
autocomplete | The autocomplete attribute of the input@default 'off' | string | - | 'off' |
Events
Event name | Properties | Description |
---|---|---|
close | value Event - the event | On list is closed |
open | value boolean - if the list is opened or not | On list is opened |
blur | value Event - the event | On input blur |
focus | value Event - the event | On input focus |
change | value Event - the event | On input change value |
input | value Event - the event | On input value |
update:model-value | value ModelValueSimple | ModelValueSimple[] - the new value | On model value update, returns the new value |
selected-option | value MazSelectOption - the option object | On selected value, returns the option object |
Slots
Name | Description | Bindings |
---|---|---|
no-results | No results slot - Displayed when no results corresponding with search query | |
optgroup | Custom optgroup label | label String - the label of the optgroup |
default | Custom option | option Object - the option objectis-selected Boolean - if the option is selected |
Expose
openList
Method to open the option list
closeList
Method to close the option list