Switch
Toggle one persistent setting with an immediate state change.
Usage
Notifications
Toggle deployment notifications with one immediate action.
Toggle deployment notifications with one immediate action.
<!-- Switch / Off -->
<script setup lang="ts">
import { ref } from 'vue'
import { SwitchRoot, SwitchThumb } from '@sectile/vue/switch'
const enabled = ref(false)
</script>
<template>
<SwitchRoot v-model="enabled">
<span>Deployment notifications</span>
<SwitchThumb />
</SwitchRoot>
</template>On
Start on and expose the active state without changing the control label.
Start on and expose the active state without changing the control label.
<!-- Switch / On -->
<script setup lang="ts">
import { ref } from 'vue'
import { SwitchRoot, SwitchThumb } from '@sectile/vue/switch'
const enabled = ref(false)
</script>
<template>
<SwitchRoot v-model="enabled">
<span>Deployment notifications</span>
<SwitchThumb />
</SwitchRoot>
</template>Controlled
Let the parent own the current value and apply accepted changes back to the component.
Let the parent own the current value and apply accepted changes back to the component.
<!-- Switch / Controlled -->
<script setup lang="ts">
import { ref } from 'vue'
import { SwitchRoot, SwitchThumb } from '@sectile/vue/switch'
const enabled = ref(false)
</script>
<template>
<SwitchRoot v-model="enabled">
<span>Deployment notifications</span>
<SwitchThumb />
</SwitchRoot>
</template>API
Vue package: @sectile/vue/switch
SwitchRootSwitchThumb
Props
SwitchRootProps
asElement or component rendered for this part.
asChildWhether to merge this part into its single child instead of rendering a wrapper.
defaultValueInitial value used when the component owns its state.
disabledWhether interaction is unavailable.
formID of the native form associated with the control.
modelValueCurrent value when state is controlled by the parent.
nameName used for native form submission.
readonlyWhether the value can be inspected but not changed.
requiredWhether the control must contain a valid value before submission.
valueCurrent value exposed by this contract.
SwitchThumbProps
asElement or component rendered for this part.
asChildWhether to merge this part into its single child instead of rendering a wrapper.
Slots
SwitchSlotProps
checkedWhether the control is checked.
disabledWhether interaction is unavailable.
readonlyWhether the value can be inspected but not changed.
Events
SwitchRoot
update:modelValueEmitted when the component requests a new controlled value.
Other types
SwitchValueChangeHandler
type SwitchValueChangeHandler = (value: boolean) => voidParts
Shared scope: [data-scope="switch"]. Combine it with a part selector to keep styles local to this component.
| Part | Selector | Role | Extra attributes |
|---|---|---|---|
root | [data-part="root"] | Defines the component boundary and owns its composed parts. | — |
thumb | [data-part="thumb"] | Controls one value along the track. | — |
Keyboard interaction
| Key | Behavior |
|---|---|
| Space | Toggle the current value. |
| Tab | Move through the normal document focus order. |
Accessibility
The root exposes switch semantics and keeps checked, disabled, and readonly states distinct.
See the corresponding WAI-ARIA pattern for the host accessibility contract.
