Toggle
The Quasar Toggle component is another basic element for user input. You can use this for turning settings, features or true/ false inputs on and off.
Please also refer to the Option Group documentation on other possibilities for creating groups of Toggles.
Works well with QField for additional functionality such as a helper, error message placeholder and many others.
Installation
Edit /quasar.conf.js
:framework: {
components: ['QToggle']
}
Basic Usage
<q-toggle v-model="checked" label="Toggle Label" /> |
Check “Vue Properties” for even more options.
Vue Properties
Supports v-model
which should be binded to a Boolean or Array in your scope.
Vue Property | Type | Description |
---|---|---|
val |
Object | Used to modify the v-model of the Toggle when using an Array as v-model . |
true-value |
Any | Gets into “true” state when model has this value. |
false-value |
Any | Gets into “false” state when model has this value. |
label |
String | The text label for the Toggle. |
left-label |
Boolean | Set to true , if the label should be placed to the left of the Toggle. |
icon |
String | Optional icon to use. Overriden by checked-icon and unchecked-icon if the latter are used. |
checked-icon |
String | The icon to use, when the Toggle is checked. |
unchecked-icon |
String | The icon to use, when the Toggle is not checked. |
color |
String | Color from Quasar Color Palette. |
keep-color |
Boolean | Keep color when not truthy too. |
readonly |
Boolean | Set to true , to make the toggle read-only. |
disable |
Boolean | Set to true , to disable the toggle. |
dark |
Boolean | Set to true when background is dark. |
Vue Events
Vue Event | Description |
---|---|
@input(newVal) |
Triggered immediately on model value change. |
@change(newVal) |
Triggered on lazy model value change. |
@blur |
Triggered, when Toggle loses focus. |
@focus |
Triggered, when Toggle gains focus. |
Array as Model
If you have a number of toggles for a selection, use can also use an Array as the model object and the val
prop for the inserted value into the Array.
<template> |
Ticking all toggles will make selection
scope variable to be ['one', 'two', 'three']
. Unticking all toggles will result in selection
being an empty array []
.
More Examples
There are a number of props, which are available to help quickly format a Toggle. An interesting feature of Toggle is the ripple effect that user gets when clicking/tapping on it to change its state.
Custom Model Values
Instead of the default true/false
values, you can use custom ones:<q-toggle
v-model="customModel"
color="secondary"
label="Do you agree with the terms & conditions?"
true-value="yes"
false-value="no"
/>
Specific State Icons
For a more informational Toggle, you can also use the checked-icon
and unchecked-icon
props to display an inset icon in the toggle.
<q-toggle |
Specifying checked-icon
and unchecked-icon
overrides icon
property if you’ve also used it.
Coloring
Use the color
prop to control the toggle’s color.
<q-toggle v-model="checked" color="orange" /> |
Label Position
Use the left-label
prop, to move the label to the left of Toggle.
<q-toggle |
Usage Inside of a List
In the following example we use the right side of QItems to insert Toggle, but it works anywhere.
<q-list link> |