Skip to contents
Interfaces DS
Landing Page

Switch

Turn a setting on or off immediately. Try a labeled airplane mode switch and compare its initial states.

On this page

Usage

Usage guidelines

Use a switch for an on-or-off setting that takes effect when changed. Give it a persistent label that describes the setting in either state.

Use defaultChecked for local state or control checked with onCheckedChange when the setting comes from elsewhere.

Examples

Checked

Installation

  1. Set up your license key before connecting the private registry.

    Connect this project to https://docs.interfacesds.com using the full URL shown below, including {name}. In components.json, add the registries field at the top level. If the field already exists, add only the @interfaces-ds entry inside it. Keep your existing aliases and other registries.

    For a global stylesheet in app/ or src/app/.

    JSON
    {
      "registries": {
        "@interfaces-ds": {
          "url": "https://docs.interfacesds.com/r/{name}.json",
          "headers": {
            "Authorization": "Bearer ${INTERFACES_DS_LICENSE_KEY}"
          }
        }
      }
    }
  2. Install the component.

    Terminal
    npx shadcn@latest add @interfaces-ds/switch

    To run the usage example, install these components together.

    Terminal
    npx shadcn@latest add @interfaces-ds/switch @interfaces-ds/label

API reference

Import these exports from @/components/ui/switch. The tables cover component-specific props and common controls.

Switch
PropTypeDefault
checkedboolean—
defaultCheckedboolean—
disabledboolean—
namestring—
onCheckedChange(checked: boolean, eventDetails: SwitchPrimitive.Root.ChangeEventDetails) => void—
readOnlyboolean—
requiredboolean—
valuestring—