HextaUI

Switch: In a field

With Field, the label and description are linked to the switch.

Product news and offers, about once a month.

import {
  Field,
  FieldContent,
  FieldDescription,
  FieldLabel,
} from "@/components/ui/field"
import { Switch } from "@/components/ui/switch"

export function SwitchField() {
  return (
    <Field orientation="horizontal" className="w-full max-w-sm">
      <FieldContent>
        <FieldLabel>Marketing emails</FieldLabel>
        <FieldDescription>
          Product news and offers, about once a month.
        </FieldDescription>
      </FieldContent>
      <Switch name="marketing" />
    </Field>
  )
}

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

pnpm dlx shadcn@latest add https://hextaui.com/r/switch-field.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
name
string–

Every prop is in the Switch API reference.

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