Lynx

Switch

A component that allows you to instantly turn on or off specific settings and states.

Engine ≥ 3.6
Available since@seed-design/lynx-react@0.1.0, @seed-design/lynx-css@0.1.0
Loading Lynx example…

Installation

npx @seed-design/cli@latest add ui:switch

Props

Switch

Prop

Type

label?React.ReactNode
defaultChecked?boolean | undefined
onCheckedChange?((checked: boolean) => void) | undefined
style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined

Switchmark

Prop

Type

className?string | undefined
style?CSSProperties | undefined
defaultChecked?boolean | undefined
onCheckedChange?((checked: boolean) => void) | undefined

Examples

Sizes

Loading Lynx example…

Tones

Brand

Loading Lynx example…

Neutral

Loading Lynx example…

Long Label

Loading Lynx example…

Disabled

Loading Lynx example…

Listening to Value Changes

You can detect changes in the switch's selected state using onCheckedChange.

Loading Lynx example…

Use Cases

Using Switchmark

Switchmark is a switch component without a label and can be used for custom layouts.

Loading Lynx example…

Web Version Differences

Lynx Switch has the following differences from React Switch.

  • Event handling: Only onCheckedChange is exposed instead of onChange. The tap handler is owned internally by Switch.
  • Rendering elements: Renders native <view> / <text> elements instead of HTML <label> / <input>.
  • Compound structure: The structure of Switch.Root → Switch.Control → Switch.Thumb / Switch.Label and the flow of sharing state/variant with Context are the same. It also supports passing tone/size directly to Control to override Root.
  • Accessibility: Switch.Root is exposed as an accessibility element by default. The role description is switch, and the value is checked or not checked depending on the selection state. The disabled trait is passed in the disabled state. Registry Switch uses the string label as the accessibility name. For Switchmark or compound labels, specify accessibility-label directly.
  • ref forwarding: All sub-components support React.forwardRef.

Scale Feedback

Lynx Switch does not currently provide feedback where Switchmark shrinks when pressed. This is not a CSS support issue, but because the current Rootage specification and Lynx Recipe do not have a pressed scale state. If you need this feedback, connect the pressed state and scale transform of the element wrapping Switchmark directly in your app.

Unsupported Lynx Features

The following features are not supported due to current Lynx platform constraints.

Excluded due to Runtime Model Differences

FeatureWeb EquivalentDescription
SwitchHiddenInput<input type="checkbox">No HTML form submission model in Lynx
name / value / required / invalidform field propsNo native form submission model in Lynx
focus / focusVisibleKeyboard focusNo keyboard focus concept in Lynx
onChange (raw DOM event)React.ChangeEventNot applicable. Use onCheckedChange instead

Table of contents