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.

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

Select color

selectedValue:

vue
<template>
  <MazSelect
    v-model="selectedValue"
    label="Select color"
    :color="color"
    :options="['primary', 'secondary', 'info', 'success', 'danger', 'warning']"
  />
</template>

<script setup lang="ts">
  import { ref } from 'vue'
  import MazSelect from 'maz-ui/components/MazSelect'

  const selectedValue = ref()
</script>

Multiple

Choose options

selectedValues:

html
<MazSelect
  v-model="selectedValues"
  :options="colors"
  label="Choose options"
  multiple
/>

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="[...]" />
Select color
html
<MazSelect
  v-model="selectedValue"
  label="Select color"
  :options="colors"
  search
/>

Opt Group

Group your options like a native optgroup

Select options
vue
<template>
  <MazSelect
    v-model="optGroupValue"
    label="Select option"
    :options="optGroup"
    multiple
  />
</template>

<script setup lang="ts">
  import { ref } from 'vue'
  const selectedValue = ref()
  const optGroup = [
    { label: 'Basic colors', options: ['primary', 'secondary', 'danger'] },
    { label: 'Custom colors', options: [{ label: 'third', value: 'third' }] },
  ]
</script>

Custom template options


Select color
vue
<template>
  <MazSelect
    label="Select color"
    v-model="selectedUser"
    :options="customTemplateOptions"
    v-slot="{ option, isSelected }"
    search
  >
    <div class="flex items-center" style="width: 100%; gap: 1rem">
      <MazAvatar size="0.8rem" :src="option.picture" />
      <strong>
        {{ option.label }}
      </strong>
    </div>
  </MazSelect>
</template>

<script lang="ts" setup>
  import { ref } from 'vue'
  import MazSelect from 'maz-ui/components/MazSelect'
  import MazAvatar from 'maz-ui/components/MazAvatar'

  const selectedUser = ref()

  const customTemplateOptions = [
    { picture: 'https://api.dicebear.com/7.x/big-smile/svg?backgroundColor=1d90ff&seed=JamesSmile', label: 'James Smile', value: 1 },
    { picture: 'https://api.dicebear.com/7.x/big-smile/svg?backgroundColor=1d90ff&seed=BradSmile', label: 'Brad Smile', value: 2 },
    { picture: 'https://api.dicebear.com/7.x/big-smile/svg?backgroundColor=1d90ff&seed=CedricSmile', label: 'Cedric Smile', value: 3 },
    { picture: 'https://api.dicebear.com/7.x/big-smile/svg?backgroundColor=1d90ff&seed=HarrySmile', label: 'Harry Smile', value: 4 },
  ]
</script>

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


vue
<template>
  <MazSelect
    v-model="selectedValueCustom"
    :options="options"
    :color="selectedValueCustom"
    option-value-key="valueOption"
    option-label-key="labelOption"
    option-input-value-key="inputLabel"
    search
  />
</template>

<script lang="ts" setup>
  import { ref } from 'vue'
  const selectedValueCustom = ref('danger')

  const customOptions = [
    { valueOption: 'primary', labelOption: 'primary label', inputLabel: 'primary input', },
    { valueOption: 'secondary', labelOption: 'secondary label', inputLabel: 'secondary input', },
    { valueOption: 'info', labelOption: 'info label', inputLabel: 'info input', },
    { valueOption: 'success', labelOption: 'success label', inputLabel: 'success input', },
    { valueOption: 'warning', labelOption: 'warning label', inputLabel: 'warning input', },
    { valueOption: 'danger', labelOption: 'danger label', inputLabel: 'danger input', },
    { valueOption: 'white', labelOption: 'white label', inputLabel: 'white input', },
    { valueOption: 'black', labelOption: 'black label', inputLabel: 'black input', },
  ]
</script>

Types

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

Props, Event & Slots

Props

Prop nameDescriptionTypeValuesDefault
styleStyle attribut of the component root elementTSIndexedAccessType-undefined
classClass attribut of the component root elementTSIndexedAccessType-undefined
idThe id of the selectstring-undefined
modelValueThe value of the selectunion-undefined
optionsThe options of the selectArray-undefined
optionValueKeyThe key of the option value
@default 'value'
string-'value'
optionLabelKeyThe key of the option label
@default 'label'
string-'label'
optionInputValueKeyThe key of the option input value
@default 'label'
string-'label'
listPositionThe position of the list
@default 'bottom left'
Position-'bottom left'
itemHeightThe height of the option list itemnumber-undefined
maxListHeightThe max height of the option listnumber-240
maxListWidthThe max width of the option listnumber-undefined
minListHeightThe min height of the option listnumber-undefined
minListWidthThe min width of the option listnumber-undefined
sizeThe size of the select
@default 'md'
Size-'md'
colorThe color of the select
@default 'primary'
Color-'primary'
searchDisplay search input in option listboolean-
searchPlaceholderThe placeholder of the search input
@default 'Search in options'
string-'Search in options'
searchThresholdThe 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
openif true, the option list is opened by defaultboolean-
multipleEnable the multiple selectionboolean-undefined
requiredMake the input required in the formboolean-
disabledDisable the componentboolean-
blockThe input will be displayed in full widthboolean-
excludeSelectorsThe exclude selectors for the v-closable directive - will exclude the elements from the directiveArray-undefined
autocompleteThe autocomplete attribute of the input
@default 'off'
string-'off'

Events

Event namePropertiesDescription
closevalue Event - the eventOn list is closed
openvalue boolean - if the list is opened or notOn list is opened
blurvalue Event - the eventOn input blur
focusvalue Event - the eventOn input focus
changevalue Event - the eventOn input change value
inputvalue Event - the eventOn input value
update:model-valuevalue ModelValueSimple | ModelValueSimple[] - the new valueOn model value update, returns the new value
selected-optionvalue MazSelectOption - the option objectOn selected value, returns the option object

Slots

NameDescriptionBindings
no-resultsNo results slot - Displayed when no results corresponding with search query
optgroupCustom optgroup labellabel String - the label of the optgroup
defaultCustom optionoption Object - the option object
is-selected Boolean - if the option is selected

Expose

openList

Method to open the option list

closeList

Method to close the option list