Skip to content

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:

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
html
<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

html
<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-key to override the key of the value in your option
  • option-label-key to override the key of the label to show in the option list
  • option-input-value-key to override the key of the value to show in the input

Example ​


Types ​

ts
type ModelValueSimple = string | number | null | undefined | boolean

Accessibility ​

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-multiselectable in multiple mode) labelled by the label, top-label or placeholder, each option is an option with aria-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 (aria namespace).

Tips ​

TIP

This component use MazInput, so it inherits all his props

Props ​

NameDescriptionTypeRequiredDefaultPossible values
idThe id of the selectstringNo--
labelThe label of the selectstringNo--
top-labelStatic label displayed above the input field. Unlike the floating label, this remains fixedstringNo--
placeholderThe placeholder of the selectstringNo--
model-valuev-model The value of the select(Multiple extends true ? Value[] : Value)No--
optionsThe options of the selectOption[]Yes--
option-value-keyThe key of the option valuestringNo"value"-
option-label-keyThe key of the option labelstringNo"label"-
option-input-value-keyThe key of the option input valuestringNo"label"-
list-positionThe position of the list (auto by default - will switch between bottom-start and top-start)MazPopoverPositionNo"auto"-
prefer-positionThe prefer position of the listMazPopoverPreferPositionNo"bottom-start"-
fallback-positionThe fallback position of the listMazPopoverFallbackPositionNo"top-start"-
item-heightThe height of the option list itemnumberNo--
max-list-heightThe max height of the option listnumberNo240-
max-list-widthThe max width of the option listnumberNo--
min-list-heightThe min height of the option listnumberNo--
min-list-widthThe min width of the option listnumberNo--
sizeThe size of the select"xs" | "sm" | "md" | "lg" | "xl" | "mini"No'md''xs' | 'sm' | 'md' | 'lg' | 'xl' | 'mini'
colorThe color of the select"primary" | "secondary" | "accent" | "info" | "success" | "warning" | "destructive" | "contrast" | "transparent"No"primary"'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'destructive' | 'contrast' | 'transparent'
searchDisplay search input in option listbooleanNo--
search-functionReplace the default search function to provide a custom search function((query: string, options: Option[]) => Option[] | undefined)No--
search-thresholdThe threshold for the search input where 1 is a perfect match and 0 is a match with any characternumberNo0.75-
multipleEnable the multiple selectionMultipleNofalse-
requiredMake the input required in the formbooleanNo--
disabledDisable the componentbooleanNo--
blockThe input will be displayed in full widthbooleanNo--
autocompleteThe autocomplete attribute of the inputstringNo"off"-
translationsThe translations of the componentPartial<{ searchPlaceholder: string; }>No{ searchPlaceholder: 'Search in options', }-
format-input-valueThe function to format the input value((value: Multiple extends true ? Value[] : Value) => string)No--
transitionThe transition name of the panel list optionsstringNo"scale-fade"-
openv-model:openbooleanNofalse-

Events ​

Event namePayloadDescription
update:model-valuevalue: Multiple extends true ? Value[] : ValueOn model value update, returns the new value
open-On list is opened
close-On list is closed
blurvalue: EventOn input blur
changevalue: EventOn input change value
focusvalue?: Event | undefinedOn input focus
inputvalue: EventOn input value
selected-optionvalue: OptionOn selected value, returns the option object
update:openvalue: boolean

Slots ​

NameDescriptionBindings
start-iconAdd a custom inline-start icon (left in LTR, right in RTL)isOpen false - Current open state of the popover
close () => void - Function to close the popover
open () => void - Function to open the popover
toggle () => void - Function to toggle the popover
end-iconAdd and replace a custom inline-end icon (right in LTR, left in RTL)isOpen false - Current open state of the popover
close () => void - Function to close the popover
open () => void - Function to open the popover
toggle () => void - Function to toggle the popover
no-resultsNo results slot - Displayed when no results corresponding with search query-
optgroupCustom optgroup labellabel string | number | true - the label of the optgroup
defaultCustom optionoption Option - the option object
isSelected boolean - if the option is selected
isOpen false - if the popover is open
close () => void - function to close the popover
open () => void - function to open the popover
toggle () => void - function to toggle the popover