Switch

Switch between two opposing states

<template>
    <section>
        <b-field>
            <b-switch>Default</b-switch>
        </b-field>
        <b-field>
            <b-switch v-model="isSwitched">
                {{ isSwitched }}
            </b-switch>
        </b-field>
        <b-field>
            <b-switch v-model="isSwitchedCustom"
                true-value="Yes"
                false-value="No">
                {{ isSwitchedCustom }}
            </b-switch>
        </b-field>
        <b-field>
            <b-switch disabled>Disabled</b-switch>
        </b-field>
    </section>
</template>

<script>
    export default {
        data() {
            return {
                isSwitched: false,
                isSwitchedCustom: 'Yes'
            }
        }
    }
</script>

# Types

<template>
    <section>
        <b-field>
            <b-switch :value="true">
                Default
            </b-switch>
        </b-field>
        <b-field>
            <b-switch :value="true"
            type="is-info">
                Info
            </b-switch>
        </b-field>
        <b-field>
            <b-switch :value="true"
            type="is-success">
                Success
            </b-switch>
        </b-field>
        <b-field>
            <b-switch :value="true"
            type="is-danger">
                Danger
            </b-switch>
        </b-field>
        <b-field>
            <b-switch :value="true"
            type="is-warning">
                Warning
            </b-switch>
        </b-field>
        <b-field>
            <b-switch
                v-model="lightMode"
                passive-type='is-dark'
                type='is-warning'>
                {{ lightMode ? "Light Mode" : "Dark Mode" }}
            </b-switch>
        </b-field>
    </section>
</template>

<script>
export default {
    data() {
        return {
            lightMode: false
        }
    }
}
</script>

# Sizes

<template>
    <section>
        <b-field>
            <b-switch size="is-small">Small</b-switch>
        </b-field>
        <b-field>
            <b-switch>Default</b-switch>
        </b-field>
        <b-field>
            <b-switch size="is-medium">Medium</b-switch>
        </b-field>
        <b-field>
            <b-switch size="is-large">Large</b-switch>
        </b-field>
    </section>
</template>

# Styles

<template>
    <section>
        <b-field grouped>
            <b-switch v-model="isRounded">Rounded</b-switch>
            <b-switch v-model="isOutlined">Outlined</b-switch>
        </b-field>
        <b-field label="Type">
            <b-select expanded v-model="type" placeholder="Type">
                <option value="null">Default</option>
                <option value="is-primary">Primary</option>
                <option value="is-success">Success</option>
                <option value="is-warning">Warning</option>
                <option value="is-danger">Danger</option>
            </b-select>
        </b-field>
        <b-field label="Passive Type">
            <b-select expanded v-model="passiveType" placeholder="Passive Type">
                <option value="null">Default</option>
                <option value="is-primary">Primary</option>
                <option value="is-success">Success</option>
                <option value="is-warning">Warning</option>
                <option value="is-danger">Danger</option>
            </b-select>
        </b-field>
        <b-field label="Size">
            <b-select expanded v-model="size">
                <option value="">Default</option>
                <option value="is-small">is-small</option>
                <option value="is-medium">is-medium</option>
                <option value="is-large">is-large</option>
            </b-select>
        </b-field>
        <b-field label="Left Label">
            <b-radio v-model='leftLabel' :native-value='false'>False</b-radio>
            <b-radio v-model='leftLabel' :native-value='true'>True</b-radio>
        </b-field>
        <b-switch
            :rounded="isRounded"
            :outlined="isOutlined"
            :size="size"
            :type="type"
            :left-label='leftLabel'
            :passive-type='passiveType'>Sample</b-switch>
    </section>
</template>

<script>
    export default {
        data() {
            return {
                size: '',
                type: null,
                passiveType: null,
                isRounded: false,
                isOutlined: false,
                leftLabel: false,
            }
        }
    }
</script>

# API

Name
Description
Type
Values
Default
typeType (color) of the switch, optionalStringis-white, is-black, is-light, is-dark, is-primary, is-info, is-success, is-warning, is-danger, and any other colors you've set in the $colors list on Sass
passive-typeType (color) of the switch when switch is passive, optionalStringis-white, is-black, is-light, is-dark, is-primary, is-info, is-success, is-warning, is-danger, and any other colors you've set in the $colors list on Sass
v-modelBinding valueAnyfalse
native-valueSame as native valueAny
true-valueOverrides the returned value when it's checkedAnytrue
false-valueOverrides the returned value when it's not checkedAnyfalse
disabledSame as native disabledBooleanfalse
nameSame as native nameString
sizeSize of the control, optionalStringis-small, is-medium, is-large
roundedRounded styleBooleantrue
outlinedOutlined styleBooleanfalse
aria-labelledbyAccessibility label to establish relationship between the switch and control labelString

# Variables

You can use these variables to customize this component.

Name
Default
$switch-width-number2.75
$switch-width$switch-width-number * 1em
$switch-padding0.2em
$switch-active-background-color$primary
$switch-colors$form-colors

This page is open source. Noticed a typo or something's unclear?

Improve this page on GitHub