GitHub

Switch

Toggle switch for boolean options

Basic Usage

Loading...

Installation

pnpm add @corew500/ui

Usage

import { Switch } from "@corew500/ui/switch"

<Switch>Content</Switch>

Variants

switchVariants

AxisValuesDefault
size
smdefaultlg
default

thumbVariants

AxisValuesDefault
size
smdefaultlg
default

CMS Integration

CMSPayload CMS Integration
This component supports CMS-driven content via @corew500/cms-payload.
Loading...

API Reference

Props

PropTypeDefaultDescription
classNameenumCSS class applied to the element, or a function that returns a class based on the component’s state.
defaultCheckedenumfalseWhether the switch is initially active. To render a controlled switch, use the `checked` prop instead.
styleenumStyle applied to the element, or a function that returns a style object based on the component’s state.
idstringThe id of the switch element.
renderenumAllows you to replace the component’s HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
checkedenumWhether the switch is currently active. To render an uncontrolled switch, use the `defaultChecked` prop instead.
disabledenumfalseWhether the component should ignore user interaction.
inputRefenumA ref to access the hidden `<input>` element.
namestringIdentifies the field when a form is submitted.
onCheckedChange(checked: boolean, eventDetails: { reason: "none"; event: Event; cancel: () => void; allowPropagation: () => void; isCanceled: boolean; isPropagationAllowed: boolean; trigger: Element; }) => voidEvent handler called when the switch is activated or deactivated.
readOnlyenumfalseWhether the user should be unable to activate or deactivate the switch.
requiredenumfalseWhether the user must activate the switch before submitting a form.
valuestringThe value submitted with the form when the switch is on. By default, switch submits the "on" value, matching native checkbox behavior.
uncheckedValuestringThe value submitted with the form when the switch is off. By default, unchecked switches do not submit any value, matching native checkbox behavior.
nativeButtonenumfalseWhether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `true` if the rendered element is a native button.
sizeenum

Accessibility

Keyboard Navigation

  • Keyboard accessible: Space or Enter to toggle
  • Focus visible ring for keyboard navigation

Screen Readers

  • - Uses `role="switch"` for proper semantics (handled by Base UI)
  • `aria-checked` state managed automatically

Additional

  • Disabled state indicated visually and to assistive technology
  • Extended touch target via pseudo-element for mobile accessibility

Localization

Translatable Content

  • - Labels should be provided externally via `FieldLabel`
  • For accessible name, use `aria-label` or associate with a label

Related

Related Components