Skip to content

Switch

@hua-labs/ui
v1.1.0

bash
npm install @hua-labs/hua
tsx
import { Switch } from "@hua-labs/hua";

:

default
outline
filled
glass

sm
md
lg

variant"default" | "outline" | "filled" | "glass""default"Visual style variant
size"sm" | "md" | "lg""md"Switch size
labelstring-Label text displayed next to switch
descriptionstring-Additional description below label
errorbooleanfalseError state indicator
successbooleanfalseSuccess state indicator
checkedboolean-Controlled checked state
defaultCheckedboolean-Initial checked state (uncontrolled)
disabledbooleanfalseDisables the switch

docs:common.basicUsage
import { Switch } from '@hua-labs/hua';

<Switch label="Enable notifications" />
With Description
<Switch
  label="Auto Save"
  description="Automatically save your work"
/>
Controlled
const [enabled, setEnabled] = useState(false);

<Switch
  checked={enabled}
  onChange={(e) => setEnabled(e.target.checked)}
  label="Dark Mode"
/>

  • Switch Role: Uses role='switch' for proper semantics
  • aria-checked: Reflects on/off state for screen readers
  • Keyboard Toggle: Space key toggles switch state
  • Focus Visible: Clear focus indicator for keyboard navigation