For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/ui/components/switch.md.
lynx-ui logo
lynx-ui
  • English
  • Switch

    A headless Switch (toggle) component for ReactLynx. It provides unstyled primitives for toggle states.
    Info

    You can check the source code to understand how it works, and you're welcome to submit PRs to enhance its capabilities.

    Basic Usage

    The basic usage of <Switch>

    Examples

    Theme Control

    Use a controlled Switch (checked + onChange) to drive page theme, and let token changes update the Switch visuals automatically. The example also shows a composed ThemedSwitch wrapper alongside part-level primitives; see Styling & Theming.

    Structure

    <Switch>
      <SwitchTrack />
      <SwitchThumb />
    </Switch>

    Component API

    Switch

    Props for the Switch component.

    checkediOSAndroid
    Typeboolean
    Whether the Switch is checked. If checked is provided, the component is controlled and defaultChecked is ignored.
    classNameiOSAndroidHarmony
    Typestring
    className
    defaultCheckediOSAndroid
    Typeboolean·Defaultfalse
    The initial checked state when used as an uncontrolled component.
    disablediOSAndroid
    Typeboolean·Defaultfalse
    Whether the user can interact with the Switch. When true, the Switch cannot be toggled.
    onChangeiOSAndroid
    Type(checked: boolean) => void
    Callback fired when the checked state changes.
    styleiOSAndroidHarmony
    TypeCSSProperties
    style
    switchPropsiOSAndroid
    TypeViewProps
    Switch supports original view props to be directly spread in this prop.
    childreniOSAndroid
    TypeReactNode | ((status: { checked: boolean; active: boolean; disabled: boolean }) => ReactNode)
    Content displayed inside or next to the Switch.

    State-based styling & rendering

    This component exposes runtime states through one or both of the following channels. The table lists only the channels available for each state:

    • UI variant class — when supported, a class like ui-<state> is toggled on the corresponding component node for selectors such as .ui-<state> { ... }.
    • Render-prop field — when supported and children is a function, the state is passed in via children({ <state>: boolean, ... }) for runtime-driven rendering.

    UI variants applied by Switch based on its render state.

    Class NameRender PropTypeDescription
    ui-activeactivebooleanWhether the Switch is active (pressed or being interacted with). Applied when `status.active` is true.
    ui-checkedcheckedbooleanWhether the Switch is currently checked. Applied when `status.checked` is true.
    ui-disableddisabledbooleanWhether the Switch is disabled. Applied when `status.disabled` is true.

    SwitchTrack

    The track of the Switch. Represents the background area on which the thumb slides. Can also be used for pressed overlays or state decorations.

    childreniOSAndroid
    TypeReactNode
    Content slot of the track. Allows custom elements, can be used to add overlays or state decorations.
    classNameiOSAndroidHarmony
    Typestring
    className
    styleiOSAndroidHarmony
    TypeCSSProperties
    style

    UI variants applied by SwitchTrack.

    Class NameDescription
    ui-activeWhether the Switch is active (pressed or being interacted with). Applied when `status.active` is true.
    ui-checkedWhether the Switch is currently checked. Applied when `status.checked` is true.
    ui-disabledWhether the Switch is disabled. Applied when `status.disabled` is true.

    SwitchThumb

    The thumb of the Switch. The draggable/clickable handle that toggles the state.

    childreniOSAndroid
    TypeReactNode
    Content slot of the thumb. Allows custom elements such as icons.
    classNameiOSAndroidHarmony
    Typestring
    className
    styleiOSAndroidHarmony
    TypeCSSProperties
    style

    UI variants applied by SwitchThumb.

    Class NameDescription
    ui-activeWhether the Switch is active (pressed or being interacted with). Applied when `status.active` is true.
    ui-checkedWhether the Switch is currently checked. Applied when `status.checked` is true.
    ui-disabledWhether the Switch is disabled. Applied when `status.disabled` is true.
    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.