Skip to main content
LibreChat is joining ClickHouse to power the open-source Agentic Data Stack 🎉 Learn more
LibreChat

Switch

An on or off setting that applies immediately.

Use Switch for a setting that takes effect as soon as it changes. For an option that is applied when a form is submitted, use a checkbox instead.

import { useId, useState } from 'react'
import { Label, Switch } from '@librechat/client'

export default function SwitchDefault() {
  const id = useId()
  const [checked, setChecked] = useState(true)
  return (
    <div className="flex items-center gap-3">
      <Switch
        id={id}
        aria-labelledby={`${id}-label`}
        checked={checked}
        onCheckedChange={setChecked}
      />
      <Label id={`${id}-label`} htmlFor={id}>
        Auto-send dictation
      </Label>
    </div>
  )
}

Props

PropTypeDescription
checkedbooleanThe controlled state.
onCheckedChange(checked: boolean) => voidCalled when the user toggles the switch.
defaultCheckedbooleanThe initial state when uncontrolled.
disabledbooleanBlocks toggling.
aria-label or aria-labelledbystringRequired: exactly one names the switch.

Accessibility

The switch exposes the switch role with its checked state, and its type requires an accessible name.

KeyAction
Space or EnterToggles the switch

How is this guide?

On this page