Hone UI
Components

Switch

An on and off switch for a setting that applies at once.

Switch has the same contract as Checkbox, drawn as a track and a thumb. Use it for settings that take effect immediately. It is a client component and reads components.Switch.defaultProps.

import Switch from '@hone-ui/react/Switch';

Examples

<FormControlLabel control={<Switch defaultChecked />} label="Wi-Fi" />
<FormControlLabel control={<Switch />} label="Bluetooth" />

A controlled switch reads checked from your state:

<Switch
  edge="end"
  checked={on}
  onChange={(event, checked) => setOn(checked)}
  inputProps={{ 'aria-label': 'Wi-Fi' }}
/>

Props

PropTypeDefaultDescription
checked, defaultCheckedbooleannone, falseControlled and starting state.
onChange(event, checked) => voidnoneThe real change event and the new state.
color'default', 'primary', 'secondary', 'error', 'info', 'success', 'warning''primary'The on color.
size'small', 'medium''medium'The size.
edge'start', 'end', falsefalsePulls the switch toward its edge.
disabled, required, readOnlybooleanfalseAs in Checkbox.
name, value, autoFocus, id, inputRef, slotProps, inputProps, disableRippleExactly as in Checkbox.
sx, className, style, refStandard. They go to the root label.

Inside a FormControl, disabled follows it and error colors the switch. required does not.

Notes

  • No slots, icon or checkedIcon.
  • The real input covers the whole switch, so test tools can click it directly, with no force.

Accessibility

The input has role="switch", and Space toggles it. Name it with FormControlLabel or inputProps['aria-label'].

On this page