Stable

Switch

Switches toggle the state of a single item on or off. Built on bits-ui's Switch.Root, with a draggable thumb (swipe past a 16px threshold to flip state) in addition to click/tap.

Overview

The Switch component implements the Material Design 3 Switch pattern: a pill-shaped track with a thumb that scales up and shifts color when checked.

Use icons="none" for a plain thumb, or icons="both" to show a check/close icon in both states.

Import

import { Switch } from '@noxlovette/material';

Live Demo

See it live, with Controls, in Storybook rather than a hand-rolled preview here.

widgets

Playground

Open the Switch story with Controls for checked, disabled, and icon mode.

Basic Usage

Bind checked to read and set the on/off state:

<script lang="ts">
  import { Switch } from '@noxlovette/material';

  let notifications = $state(true);
</script>

<Switch bind:checked={notifications} />

Switch Props

PropTypeDefaultDescription
checked
booleanfalseWhether the switch is on. Bindable.
disabled
booleanfalseDisables the switch.
icons
"checked" | "both" | "none""checked"Which thumb states show an icon: only when checked, both checked/unchecked, or neither.
checkedIconProps
IconProps{ name: 'check' }Props for the icon shown inside the thumb when checked.
uncheckedIconProps
IconProps{ name: 'close' }Props for the icon shown inside the thumb when unchecked (used only when icons is 'both').

Accessibility

keyboard

Keyboard support

Space/Enter toggles the switch when focused, matching the native role="switch" behaviour from bits-ui.

swipe

Drag gesture

Pointer drag past a 16px threshold flips state, mirroring native mobile switch behaviour — purely additive to click support.

visibility

State icons

Optional check/close icons give a non-color-dependent signal of on/off state.