HextaUI

Switch: Disabled and read-only

readOnly keeps the value visible and focusable but won't change it.

import { Switch } from "@/components/ui/switch"

export function SwitchStates() {
  return (
    <div className="flex flex-col gap-4 text-sm">
      <label className="flex items-center gap-3">
        <Switch disabled />
        Disabled
      </label>
      <label className="flex items-center gap-3">
        <Switch disabled defaultChecked />
        Disabled and on
      </label>
      <label className="flex items-center gap-3">
        <Switch readOnly defaultChecked />
        Read-only (managed by your admin)
      </label>
    </div>
  )
}

This adds the example as components/examples/switch/states.tsx, together with the Switch component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/switch-states.json

To add only the component, follow the Switch installation.

Props in this example

The Switch props this example sets, from the API reference.

PropTypeDefault
defaultChecked
booleanfalse
disabled
booleanfalse
readOnly
booleanfalse

Every prop is in the Switch API reference.

See them all, with keyboard support and accessibility notes, on the Switch page.