Skip to contentKino
Skip to Content

Switch

A switch whose thumb stretches toward the other side while it is pressed, then slides across.

npx shadcn add https://kinoui.com/r/switch.json
Share on

Examples

Default

Wrap it in a <label> with its text, so a press on the text turns it too, and name it from the title alone. Hold it down and the thumb stretches toward the side it will go to.

Notifications

Ledger web app · sent to priya@kinoui.com

Settings

One switch per row, at the end. Name it from the title with aria-labelledby, point aria-describedby at the description, and say why beside a disabled one.

Webhooks

Ledger web app · 4 endpoints
EndpointOn
https://api.kinoui.com/hooks/ledger
https://hooks.slack.com/services/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
https://billing.internal.kinoui.com/v2/webhooks/stripe-sync
https://n8n.priya.dev/webhook/ledger

Small

Set size="sm" in a table or a menu. A switch with no text beside it needs aria-label.

Security

Kino workspace · 48 members

Saving

Move it at once and make it readOnly while the change saves. If the save fails, set it back: the thumb slides back and the row says why.

Display options

In a menu

Each option is a <label>, so a press anywhere on the row turns it. Long text wraps, and the switch stays beside its first line.

Installation

npx shadcn@latest add https://kinoui.com/r/switch.json
Files
lib/reduce-motion.tslib/resize.tslib/choice.tscomponents/kino/switch.tsx
Packages
@base-ui/reactclass-variance-authority

New to Kino? Installation covers what your project needs first and the @kino namespace.

API reference

Props

PropTypeDefaultDescription
checkedbooleanNoneWhether it is on, when you hold the state.
defaultCheckedbooleanfalseWhether it starts on, when it holds its own state.
onCheckedChange(checked, details) => voidNoneCalled when it is turned on or off.
size'default''sm''default'20 by 36 pixels, or 16 by 28 for tables and menus.
readOnlybooleanfalseKeeps its look but ignores presses, such as while a change saves.
aria-invalidbooleanNoneDraws a ring in the destructive colour.

Data attributes

AttributeOnDescription
data-checkedSwitchPresent while it is on.
data-disabledSwitchPresent while it is disabled. Style its label with has-data-disabled:.
data-sizeSwitchIts size, default or sm.

Accessibility

  • It is a switch to assistive technology, announced as on or off. Space turns it, and a press on its <label> does too.
  • A switch with no text beside it needs aria-label, such as "Send to api.kinoui.com".
  • On and off differ in where the thumb sits, not only in colour. In forced colours the track fills with the system highlight when on.
  • When the system asks for less motion, the thumb moves at once and doesn’t stretch over time; the colours still fade.