Skip to main content

Switch

Toggles between two mutually exclusive states, rendering a custom role="switch" control.

Basic usage​

Controlled switch
Off

Current state: Off

import { useState } from 'react'
import { LhSwitch } from '@lh-ui/react'

export default function Demo() {
const [active, setActive] = useState(false)

return (
<>
<LhSwitch checked={active} onChange={(val) => setActive(val)} />
<LhSwitch
checked={active}
activeText="On"
inactiveText="Off"
onChange={(val) => setActive(val)}
/>
<LhSwitch disabled />
<LhSwitch loading />
</>
)
}

Switch Props​

PropDescriptionTypeOptionsDefault
checkedControlled switch stateboolean——
defaultCheckedUncontrolled default stateboolean—false
disabledWhether to disableboolean—false
loadingLoading stateboolean—false
activeTextText shown when onstring—Locale pack switch.on
inactiveTextText shown when offstring—Locale pack switch.off
sizeSize'large' | 'middle' | 'small'—Follows ConfigProvider
themeVarsComponent-level theme variablesRecord<string, string>——
sxShorthand layout propsSxProps——

Switch events​

EventDescriptionCallback signatureVue equivalent
onChangeState change (two arguments)(checked: boolean, event: MouseEvent | KeyboardEvent) => void@change
Keyboard interaction

The switch responds to Enter / Space to toggle, consistent with a native checkbox; aria-checked tracks the current state.

Styles​

import '@lh-ui/react/style/switch'