shadcn-remix
GitHub

Switch

A control that allows the user to toggle between checked and not checked.

import { css } from 'remix/component'

import { Label } from '#app/ui/label.tsx'
import { Switch } from '#app/ui/switch.tsx'

const rowStyles = css({
import { css } from 'remix/component'

import { Label } from '#app/ui/label.tsx'
import { Switch } from '#app/ui/switch.tsx'

const rowStyles = css({
  display: 'flex',
  alignItems: 'center',
  '& > :not(:last-child)': { marginInlineEnd: '0.5rem' },
})

export function SwitchDemo() {
  return () => (
    <div mix={rowStyles}>
      <Switch id="airplane-mode" />
      <Label htmlFor="airplane-mode">Airplane Mode</Label>
    </div>
  )
}

Installation

$ pnpm dlx shadcn@latest add https://www.shadcn-remix.com/r/switch.json

Usage

import { Switch } from '#app/ui/switch.tsx'
<Switch />

API Reference

Switch

A control that allows the user to toggle between checked and not checked. Renders a <button role="switch">; when it belongs to a form, a hidden native checkbox mirrors its state so name/value/required work with native form submission and validation.

PropTypeDefault
checkedboolean-
defaultCheckedboolean-
onCheckedChange((checked: boolean) => void)-
requiredboolean-
valuestring"on"
size"default" | "sm""default"
mixMixValue-