Skip to content

Switch ​

A mechanical toggle switch built on reka-ui's Switch primitive, featuring 3D tactile keycaps, stamped guide track recesses, and industrial status markings, with v-model support.

Demo ​

Preview

基础 3D 机械滑块

工控通断铭牌刻印 (showLabels) & 吸合音效

机械形态 (shape="rocker")

尺寸矩阵 (sm / default / lg)

SM
DEFAULT
LG

Installation ​

pnpm dlx brutx-vue@latest add switch

Usage ​

vue
<script setup>
import { ref } from 'vue'
import { Switch, Label } from 'brutx-ui-vue'

const enabled = ref(false)
</script>

<template>
    <div class="flex items-center gap-3">
        <Switch v-model="enabled" />
        <Label>Airplane mode</Label>
    </div>
</template>

Industrial Marking Labels (I / O Marks) ​

Enable showLabels to render high-contrast monospace industrial markings (I / O) inside the track. Marked with aria-hidden for zero screen reader clutter.

vue
<script setup>
import { ref } from 'vue'
import { Switch, Label } from 'brutx-ui-vue'

const power = ref(true)
</script>

<template>
    <div class="flex items-center gap-3">
        <Switch v-model="power" show-labels />
        <Label>Main Equipment Power</Label>
    </div>
</template>

Mechanical Shape ​

Supports standard mechanical slider and industrial rocker switch shapes, orthogonally decoupled from the color variant.

vue
<script setup>
import { ref } from 'vue'
import { Switch } from 'brutx-ui-vue'

const val1 = ref(false)
const val2 = ref(true)
</script>

<template>
    <div class="flex items-center gap-4">
        <Switch v-model="val1" shape="slider" variant="primary" />
        <Switch v-model="val2" shape="rocker" variant="accent" show-labels />
    </div>
</template>

Disabled State ​

vue
<template>
    <Switch disabled />
</template>

Custom Accessibility Label ​

Switch provides aria-label via locale by default, ensuring screen readers can read it correctly. When a more specific description is needed, customize it through the ariaLabel prop. Falls back to t('switch.toggle') when not provided.

vue
<script setup>
import { ref } from 'vue'
import { Switch, Label } from 'brutx-ui-vue'

const sync = ref(false)
</script>

<template>
    <div class="flex items-center gap-3">
        <Switch v-model="sync" aria-label="Auto-sync data" />
        <Label>Auto sync</Label>
    </div>
</template>

API Reference ​

Switch — Props
NameTypeDefaultDescription
class
string | undefined
undefined
CSS classes added to the Switch primitive root element.
Details

Declared type

string | undefined

Default value details

Resolved value
undefined

Source

Switch.vue:13

packages/ui/src/components/switch/Switch.vue

modelValue
Nullable
boolean | null | undefined
undefined
The controlled switch state, bound with v-model; null is treated as off.
Details

Declared type

boolean | null | undefined

Literal values

  • false
  • null
  • true

Default value details

Resolved value
undefined

Source

Switch.vue:17

packages/ui/src/components/switch/Switch.vue

defaultValue
boolean | undefined
undefined
The initial state used when modelValue is omitted; it takes precedence over defaultChecked when both are provided.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Resolved value
undefined

Source

Switch.vue:21

packages/ui/src/components/switch/Switch.vue

defaultChecked
boolean | undefined
undefined
An alias for the initial state in uncontrolled mode; overridden when defaultValue is also provided.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Resolved value
undefined

Source

Switch.vue:25

packages/ui/src/components/switch/Switch.vue

disabled
boolean | undefined
false
Disables switch interaction.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Resolved value
false

Source

Switch.vue:26

packages/ui/src/components/switch/Switch.vue

variant
"accent" | "danger" | "default" | "primary" | "secondary" | undefined
"default"
Sets the switch color and state style variant.
Details

Declared type

NonNullable<"default" | "primary" | "secondary" | "danger" | "accent" | null | undefined> | undefined

Literal values

  • "accent"
  • "danger"
  • "default"
  • "primary"
  • "secondary"

Default value details

Resolved value
"default"

Source

Switch.vue:27

packages/ui/src/components/switch/Switch.vue

shape
"rocker" | "slider" | undefined
"slider"
Sets the mechanical appearance to a sliding or rocker-style switch.
Details

Declared type

NonNullable<"slider" | "rocker" | null | undefined> | undefined

Literal values

  • "rocker"
  • "slider"

Default value details

Resolved value
"slider"

Source

Switch.vue:28

packages/ui/src/components/switch/Switch.vue

size
"default" | "lg" | "sm" | undefined
"default"
Sets the size of the switch track and thumb.
Details

Declared type

NonNullable<"default" | "lg" | "sm" | null | undefined> | undefined

Literal values

  • "default"
  • "lg"
  • "sm"

Default value details

Resolved value
"default"

Source

Switch.vue:29

packages/ui/src/components/switch/Switch.vue

showLabels
boolean | undefined
false
Shows O/I markings for off and on inside the track; the markings are decorative and hidden from the accessibility tree.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Resolved value
false

Source

Switch.vue:31

packages/ui/src/components/switch/Switch.vue

ariaLabel
string | undefined
undefined
Sets the switch’s accessible name; the current locale’s default text is used when omitted.
Details

Declared type

string | undefined

Default value details

Resolved value
undefined

Source

Switch.vue:33

packages/ui/src/components/switch/Switch.vue

sound
boolean | undefined
false
Explicitly enables the relay sound when the state changes; sound is off by default.
Details

Declared type

boolean | undefined

Literal values

  • false
  • true

Default value details

Resolved value
false

Source

Switch.vue:35

packages/ui/src/components/switch/Switch.vue

Switch — Events
NameSignature or typeDescription
@update:modelValue
[value: boolean]
Emits the new boolean after the user toggles the switch to synchronize v-model.
Details

Declared type

[value: boolean]

Literal values

  • false
  • true

Source

Switch.vue

packages/ui/src/components/switch/Switch.vue

Accessibility ​

  • Keyboard: Supports Space / Enter to toggle switch state
  • ARIA attributes: Automatically manages role="switch" and aria-checked; provides aria-label via locale by default
  • Focus management: Focusable via Tab key, uses --brutal-ring token for visible focus ring
  • Label isolation: showLabels markings carry aria-hidden="true", preventing screen reader pollution

Brute force builds.