The QSelect component has two types of selection: single or multiple. This component opens up a menu 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.
/* * No installation step is necessary. * It gets installed by default by @quasar/app v2+. */
For your QSelect you can use only one of the main designs (
borderless). You cannot use multiple as they are self-exclusive.
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
Disable and readonly
Slots with QBtn type “submit”
When placing a QBtn with type “submit” in one of the “before”, “after”, “prepend”, or “append” slots of a QField, QInput or QSelect, you should also add a
@click listener on the QBtn in question. This listener should call the method that submits your form. All “click” events in such slots are not propagated to their parent elements.
Please note that transitions do not work when using
In the example below there’s a few transitions showcased. For a full list of transitions available, go to Transitions.
Options list display mode
By default QSelect shows the list of options as a menu on desktop and as a dialog on mobiles. You can force one behavior by using the
Please note that on iOS menu behavior might generate problems, especially when used in combination with
use-input prop. You can use a conditional
behavior prop like
:behavior="$q.platform.is.ios === true ? 'dialog' : 'menu'" to use dialog mode only on iOS.
The model for single selection can be anything (String, Object, …) while the model for multiple selection must be an Array.
The model content can be influenced by
emit-value prop as you’ll learn in “The options” section below.
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.
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).
Custom prop names
By default, QSelect looks at
sanitize props of each option from the options array Objects. But you can override those:
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.
Customizing menu options
Here is another example where we add a QToggle to each option. The possibilities are endless.
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.
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.
You can dynamically load new options when scroll reaches the end:
The display value
Filtering and autocomplete
Native attributes with
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 (please check
use-input prop description first to understand what it does) for filtering / autocomplete / adding new value. Some examples: autocomplete, placeholder.
More information: native input attributes.
Create new values
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
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
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.
The @new-value event
@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-modeprop, 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
done() with no parameters simply empties the input box value, without tampering with the model in any way.
Using menu and filtering
Filtering and adding the new values 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:
Generating multiple values from input:
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:
sanitizekey of the untrusted option to
true(for specific untrusted options)
- or by setting
options-sanitizeprop of QSelect (for all options)
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:
display-value-sanitizeprop of QSelect is set
- or you are not using
options-sanitizeprop of QSelect is set
- any selected option has
sanitizekey set to
If you use
selected-item slots, then you are responsible for sanitization of the display value. The
display-value-sanitize prop will not apply.
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.
To get the best performance while using lots of options freeze the array you are passing in the
options prop using
When QSelect is focused:
- pressing ENTER, ARROW DOWN (or SPACE if
use-inputis not set) will open the list of options
- pressing SHIFT + TAB will navigate backwards through the QChips (if a QChip is selected TAB will navigate forward through the QChips)
- pressing ENTER when a QChip is selected will remove that option from the selection
- pressing BACKSPACE will remove the last option from the selection (when
use-inputis set the input should be empty)
- pressing TAB (or SHIFT + TAB if
use-chipsis not set or the first QChip is selected) will navigate to the next or previous focusable element on page
- typing text (0 - 9 or A - Z) if
use-inputis not set will:
- create a search buffer (will be reset when a new key is not typed for 1.5 seconds) that will be used to search in the options labels
- select the next option starting with that letter (after the current focused one) if the first key in buffer is typed multiple times
- select the next option (starting with the current focused one) that matches the typed text (the match is fuzzy - the option label should start with the first letter and contain all the letters)
When the list of options is opened:
- pressing ARROW UP or ARROW DOWN will navigate up or down in the list of options
- pressing PAGE UP or PAGE DOWN will navigate one page up or down in the list of options
- pressing HOME or END will navigate to the start or end of the list of options (only if you are not using
use-input, or the input is empty)
- when navigating using arrow keys, navigation will wrap when reaching the start or end of the list
- pressing ENTER (or SPACE when
use-inputis not set, or TAB when
multipleis not set) when an option is selected in the list will:
- select the option and close the list of options if
multipleis not set
- toggle the option if
- select the option and close the list of options if
Native form submit v1.9+
When dealing with a native form which has an
action and a
method (eg. when using Quasar with ASP.NET controllers), you need to specify the
name property on QSelect, otherwise formData will not contain it (if it should) - all value are converted to string (native behaviour, so do not use Object values):