Select

The QSelect component has two types of selection: single or multiple. This component opens up a Popover for the selection list and action. A filter can also be used for longer lists.

In case you are looking for a dropdown “button” instead of “input” use Button Dropdown instead.

Installation


// quasar.conf.js

return {
  framework: {
    components: [
      'QSelect'
    ]
  }
}

Design

Overview

WARNING

For your QSelect you can use only one of the main designs (filled, outlined, standout, borderless). You cannot use multiple as they are self-exclusive.

Design Overview



Decorators

Decorators



Coloring

Coloring



Clearable

As a helper, you can use clearable prop so user can reset model to null through an appended icon. The second QSelect in the example below is the equivalent of using clearable.

Clearable



Disable and readonly

Disable and readonly



WARNING

Please note that transitions do not work when using options-cover prop.

In the example below there’s a few transitions showcased. For a full list of transitions available, go to Transitions.

Menu transitions



The model

WARNING

The model for single selection can be anything (String, Object, …) while the model for multiple selection must be an Array.

Single vs multiple selection



Multiple selection, counter and max-values



The model content can be influenced by emit-value prop as you’ll learn in “The options” section below.

The options

Options type

String options



Object options



Affecting model

When emit-value is used, the model becomes the determined value from the specified selected option. Default is to emit the whole option. It makes sense to use it only when the options are of Object form.

Emit-value



When map-options is used, the model can contain only the value, and it will be mapped against the options to determine its label. There is a performance penalty involved, so use it only if absolutely necessary. It’s not needed, for example, if the model contains the whole Object (so contains the label prop).

Map options



Custom prop names

By default, QSelect looks at label, value, disable and sanitize props of each option from the options array Objects. But you can override those:

WARNING

If you use functions for custom props always check if the option is null. These functions are used both for options in the list and for the selected options.

Custom label, value and disable props



Customizing menu options

Options slot



By default, when there are no options, the menu won’t appear. But you can customize this scenario and specify what the menu should display.

No options slot



Lazy loading

The following example shows a glimpse of how you can play with lazy loading the options. This means, along with many other things, that options prop is not required on first render.

Lazy load options



Cover mode

Menu covering component



The display value

Custom display value



Chips as display value



Selected-item slot



Filtering and autocomplete

Native attributes with use-input

All the attributes set on QSelect that are not in the list of props in the API will be passed to the native input field used for filtering / autocomplete / adding new value.

Please check this resources for more informations about native attributes (for input check also the specific attributes for each type):

Filtering options



Basic autocomplete



Autocomplete on more than 2 chars



Lazy autocomplete



Create new values

TIP

The following are just a few examples to get you started into making your own QSelect behavior. This is not exhaustive list of possibilities that QSelect offers.

It makes sense to use this feature along with use-input prop.

In order to enable the creation of new values, you need to either specify the new-value-mode prop and/or listen for @new-value event. If you use both, then the purpose of listening to @new-value would be only to override the new-value-mode in your custom scenarios.

The new-value-mode prop

The new-value-mode prop value specifies how the value should be added: add (adds a value, even if duplicate), add-unique (add only if NOT duplicate) or toggle (adds value if it’s not already in model, otherwise it removes it).

By using this prop you don’t need to also listen for @new-value event, unless you have some specific scenarios for which you want to override the behavior.

New value mode



The @new-value event

The @new-value event is emitted with the value to be added and a done callback. The done callback has two optional parameters:

  • the value to be added
  • the behavior (same values of new-value-mode prop, and when it is specified it overrides that prop – if it is used) – default behavior (if not using new-value-mode) is to add the value even if it would be a duplicate

Calling done() with no parameters simply empties the input box value, without tampering with the model in any way.

Listening on @new-value



Adding only unique values



Using menu and filtering

Filtering and adding the new values to menu:

Filtering and adding to menu



Filters new values (in the example below the value to be added requires at least 3 characters to pass), and does not add to menu:

Filtering without adding to menu



Sanitization

WARNING

Always sanitize values if you do not trust the origin (if the value comes from user input).

You can force sanitization of the menu options by:

  • setting sanitize key of the untrusted option to true (for specific untrusted options)
  • or by setting options-sanitize prop of QSelect (for all options)

WARNING

If you use option slot, then you are responsible for sanitization of the menu options. The options-sanitize prop will not apply.

The displayed value of QSelect is sanitized if:

  • the display-value-sanitize prop of QSelect is set
  • or you are not using display-value and
    • the options-sanitize prop of QSelect is set
    • any selected option has sanitize key set to true

WARNING

If you use selected or selected-item slots, then you are responsible for sanitization of the display value. The display-value-sanitize prop will not apply.

Sanitize options



Sanitize display value



Render performance

The render performance is NOT affected much by the number of options, unless map-options is used on a large set. Notice the infinite scroll in place which renders additional options as the user scrolls through the list.

10k options



QSelect API