Skip to content
nexubDesign System
v11.9.0

Components · Form Controls

Switch Field

AlphaAdded v11.1.0

A Switch with its label, description and error, the label clickable.

import { SwitchField } from '@nexub/react';
View as Markdown

Playground

Props

layout

Buyers can see and order from the shop

TSX
<SwitchField label="Online store" description={…} defaultChecked />

Examples

Settings row

Buyers can see and order from the shop

Compact, before the label

States

  • Buyers can see and order from the shop

    default
  • Buyers can see and order from the shop

    invalid
  • Buyers can see and order from the shop

    readOnly
  • Buyers can see and order from the shop

    loading
  • Buyers can see and order from the shop

    checked
  • Buyers 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

Props
PropTypeDefaultDescription
labelrequiredReact.ReactNode—Names the switch; clicking it toggles.
descriptionReact.ReactNode—Help under the label and the error under the row. error marks the switch invalid.
errorReact.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 / onCheckedChangeboolean / (checked: boolean) => void—As Switch, with size, loading, disabled and readOnly.
checkedIconReact.ReactNode—Small icon inside the thumb while on.
invalidboolean—Error border on the track and aria-invalid.
loadingboolean—Spinner in the thumb and aria-busy; clicks don't toggle while loading. Stays focusable.
readOnlyboolean—Focusable but cannot toggle; sets aria-readonly.
size'sm' | 'md' | 'lg'—
uncheckedIconReact.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`.