Components · Form Controls
Switch Field
A Switch with its label, description and error, the label clickable.
import { SwitchField } from '@nexub/react';Playground
Props
Buyers can see and order from the shop
<SwitchField label="Online store" description={…} defaultChecked />Examples
Settings row
Compact, before the label
States
Buyers can see and order from the shop
defaultBuyers can see and order from the shop
invalidBuyers can see and order from the shop
readOnlyBuyers can see and order from the shop
loadingBuyers can see and order from the shop
checkedBuyers can see and order from the shop
size="sm"Buyers can see and order from the shop
size="md"Buyers can see and order from the shop
size="lg"
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| labelrequired | React.ReactNode | — | Names the switch; clicking it toggles. |
| description | React.ReactNode | — | Help under the label and the error under the row. error marks the switch invalid. |
| error | React.ReactNode | — | Help under the label and the error under the row. error marks the switch invalid. |
| layout | 'start' | 'end' | 'end' | 'end': label first, the switch at the row end (settings lists). 'start': the switch first, for tight rows. |
| checked / onCheckedChange | boolean / (checked: boolean) => void | — | As Switch, with size, loading, disabled and readOnly. |
| checkedIcon | React.ReactNode | — | Small icon inside the thumb while on. |
| invalid | boolean | — | Error border on the track and aria-invalid. |
| loading | boolean | — | Spinner in the thumb and aria-busy; clicks don't toggle while loading. Stays focusable. |
| readOnly | boolean | — | Focusable but cannot toggle; sets aria-readonly. |
| size | 'sm' | 'md' | 'lg' | — | |
| uncheckedIcon | React.ReactNode | — | Small icon inside the thumb while off. |
Accessibility
Notes
The label is a `<label for>` on the switch, so it names it and toggles it.
Description and error are linked with `aria-describedby`.
On iOS & Android: SwitchField
import { SwitchField } from '@nexub/react-native';
<SwitchField label="Round-ups" description="Save the change from every card payment." checked={on} onCheckedChange={setOn} />Web vs mobile
Same tokens and prop names. Where the platforms differ:
| Web | iOS & Android | |
|---|---|---|
| Label | Compose Label + control + HelperText (or FormField). | One component: label, helperText and error are props. |
Interactive preview of @nexub/react-native rendered for the web. Native chrome (switches, pickers, Liquid Glass) looks like the platform on a device.
On device

iPhone (iOS simulator)

Pixel (Android emulator)
Screenshots from the latest CI run of the showcase app; the live frame renders the same code for the web.
SwitchField props
| Prop | Type | Default | Description |
|---|---|---|---|
| labelrequired | string | — | Visible label, also the switch's accessible name. Pressing it toggles the switch. |
| description | string | — | Help under the label, read after the label by screen readers. |
| error | string | — | The error under the field; also marks the switch invalid. |
| layout | 'start' | 'end' | 'end' | 'end': label first, the switch at the row's end (settings lists). 'start': the switch
first, then the label, compact for tight rows. |
| style | StyleProp<ViewStyle> | — | — |
| checked | boolean | — | — |
| defaultChecked | boolean | false | — |
| onCheckedChange | (checked: boolean) => void | — | — |
| disabled | boolean | — | — |
| loading | boolean | — | Spinner beside the switch and busy for screen readers; it can't toggle while loading. |
| invalid | boolean | — | Error colour on the track and announced as invalid. |
| readOnly | boolean | — | Can be focused and read but not toggled. |
| size | Extract<ControlSize, 'sm' | 'md' | 'lg'> | 'md' | md is the platform switch's own size; sm and lg scale it. |
| checkedIcon | React.ReactNode | — | Small icon inside the thumb while on. With an icon the Nexub-drawn switch is used, since the platform switch has no room for one. |
| uncheckedIcon | React.ReactNode | — | Small icon inside the thumb while off. Uses the Nexub-drawn switch, like checkedIcon. |