Switch: Saving
Return a promise from onCheckedChange and the switch flips right away, even when it's controlled. A spinner shows in the thumb only if saving takes longer than 400ms. If it rejects, the switch flips back and shakes.
This adds the example as components/examples/switch/async.tsx, together with the Switch component and the HextaUI theme tokens it needs.
pnpm dlx shadcn@latest add https://hextaui.com/r/switch-async.jsonTo add only the component, follow the Switch installation.
Props in this example
The Switch props this example sets, from the API reference.
| Prop | Type | Default |
|---|---|---|
defaultChecked | boolean | false |
onCheckedChangeReturn a promise to show the saving state. On rejection an uncontrolled switch flips back. | (checked, details) => void | Promise | – |
Every prop is in the Switch API reference.
See them all, with keyboard support and accessibility notes, on the Switch page.
- MotionThe easing curves, durations and reduced-motion check every component animates with, plus hooks for size morphs and sliding highlights.
- SpinnerA loading indicator with Apple-style ticks or a breathing ring that can wait before showing and stay long enough not to flicker.
- CalendarA date grid for single, range and multiple selection, with sliding months, range previews and touch-sized days.
- CheckboxA checkbox whose check draws in, with indeterminate parents, groups and labels that share its hover.
- ComboboxA filterable select with chips, groups and async results, in a popup that resizes as you type.
- Date pickerA button that opens a calendar in a popover, or a bottom sheet on phones, for single dates and ranges.