Loading preview
Floating Label Input
InputsA text field whose label sits inside and floats above on focus or when filled.
An on/off switch whose thumb slides with a little overshoot.
npx shadcn@latest add @venusui/toggle-switchRun this in a project set up with shadcn. If you haven’t set it up yet, run npx shadcn@latest init first.
Paths use the default shadcn aliases. The CLI follows the aliases in your components.json.
@/components/ui/toggle-switch.tsxThe code behind the preview above.
toggle-switch-demo.tsx
import { ToggleSwitch } from "@/components/ui/toggle-switch"
export default function ToggleSwitchDemo() {
return (
<div className="space-y-3">
<ToggleSwitch label="Email notifications" defaultChecked />
<ToggleSwitch label="Weekly summary" size="sm" />
</div>
)
}
| Prop | Type | Default | Description |
|---|---|---|---|
| checked | boolean | — | Controlled state. |
| defaultChecked | boolean | false | Initial state. |
| onCheckedChange | (checked: boolean) => void | — | Called on toggle. |
| label | ReactNode | — | Visible label. Without it, pass aria-label. |
| size | "sm" | "md" | "md" | Switch size. |
All <button> props except onChange and value.
bg-primary in the file to change it.role="switch" with aria-checked; Space and Enter toggle it; clicking the label toggles it too.type="button". Store its value in a hidden input if a form needs it.Unknown registry "@venusui"npx shadcn@latest), install by URL, or register it with its address: npx shadcn@latest registry add @venusui=https://venusui.com/r/{name}.json.No components.json foundnpx shadcn@latest init in your project first.A text field whose label sits inside and floats above on focus or when filled.
A number field with minus and plus buttons, clamped to a range.
One-time code entry in separate boxes with paste, autofill and keyboard navigation.