eds-switch
Explore the Interactive Component
Use the playground below to experiment with the component. Click the button to view the full Storybook deployment for additional examples and configurations.
See It in Use with Code
Check out this practical implementation of component.
Plain HTML
In React
Segmented Variant with Options
Pass two or more options (an array, or a JSON string in HTML) and a variant of segmented, segmented-dark or segmented-light to render one segment per option. value holds the selected option. The toggle emits uiswitch ({ value: boolean }); with options the component emits uiselect ({ value: string }) instead.
Properties
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
checked | checked | Indicates whether the switch is checked. | boolean | false |
disabled | disabled | Disables the switch if true. | boolean | false |
fullWidth | full-width | Segments share the full width in equal parts (e.g. on phones). | boolean | false |
groupLabel | group-label | Accessible name of the group of segments. | string | 'View toggle' |
labelOff | label-off | Label to display when the switch is OFF. | string | '' |
labelOn | label-on | Label to display when the switch is ON. | string | '' |
options | options | Two or more choices instead of on/off: [{ value, label, title? }], as an array or a JSON string. With options the switch renders one segment each (in the segmented look of variant) and emits uiselect. | string | { value: string; label: string; title?: string; }[] | '' |
size | size | Segment size for the segmented variants: ‘medium’ (default) stands 44px tall, level with EDS inputs and large buttons (Forms’ AI builder switch); ‘small’ is the compact one. | "medium" | "small" | 'medium' |
value | value | The selected option’s value, when options is set. | string | '' |
variant | variant | Variant of the switch: - ’toggle’ (default): the classic on/off switch - ‘segmented’: pill-style buttons — light container, green active pill - ‘segmented-dark’: pill-style buttons — white container with a hairline border and a dark (brand-black) active pill - ‘segmented-light’: pill-style buttons — light grey track with a hairline border; the active segment is raised in white (Forms’ mode switch) | "segmented" | "segmented-dark" | "segmented-light" | "toggle" | 'toggle' |
Events
| Event | Description | Type |
|---|---|---|
uiselect | Emitted when another option is chosen (with options). | CustomEvent<{ value: string; }> |
uiswitch | Emitted when the switch is toggled. | CustomEvent<{ value: boolean; }> |
Built with StencilJS