Switch

A switch is used to quickly switch between two possible states.

Props

Switch

size?

A Switch can vary in size.

Defaults to md.
style?

The inline style for the element. A function may be provided to compute the style based on component state.

children?

The children of the component. A function may be provided to alter the children based on component state.

defaultSelected?

Whether the Switch should be selected (uncontrolled).

isSelected?

Whether the Switch should be selected (controlled).

onChange?

Handler that is called when the Switch's selection state changes.

value?

The value of the input element, used when submitting an HTML form. See MDN.

isDisabled?

Whether the input is disabled.

isReadOnly?

Whether the input can be selected but not changed by the user.

autoFocus?

Whether the element should receive focus on render.

id?

The element's unique identifier. See MDN.

name?

The name of the input element, used when submitting an HTML form. See MDN.

inputRef?

A ref for the HTML input element.

className?

The CSS className for the element. A function may be provided to compute the class based on component state.

onFocus?

Handler that is called when the element receives focus.

onBlur?

Handler that is called when the element loses focus.

onFocusChange?

Handler that is called when the element's focus status changes.

onKeyDown?

Handler that is called when a key is pressed.

onKeyUp?

Handler that is called when a key is released.

onHoverStart?

Handler that is called when a hover interaction starts.

onHoverEnd?

Handler that is called when a hover interaction ends.

onHoverChange?

Handler that is called when the hover state changes.

aria-controls?

Identifies the element (or elements) whose contents or presence are controlled by the current element.

excludeFromTabOrder?

Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available.

aria-label?

Defines a string value that labels the current element.

aria-labelledby?

Identifies the element (or elements) that labels the current element.

aria-describedby?

Identifies the element (or elements) that describes the object.

aria-details?

Identifies the element (or elements) that provide a detailed, extended description for the object.

slot?

A slot name for the component. Slots allow the component to receive props from a parent component. An explicit null value indicates that the local props completely override all props received from a parent.

SwitchField

size?

A switch field can vary in size.

Defaults to md.
isDisabled?

Whether the switch field is disabled.

children?

The children of the component. A function may be provided to alter the children based on component state.

className?

The CSS className for the element. A function may be provided to compute the class based on component state.

style?

The inline style for the element. A function may be provided to compute the style based on component state.

aria-label?

Defines a string value that labels the current element.

aria-labelledby?

Identifies the element (or elements) that labels the current element.

aria-describedby?

Identifies the element (or elements) that describes the object.

aria-details?

Identifies the element (or elements) that provide a detailed, extended description for the object.

slot?

A slot name for the component. Slots allow the component to receive props from a parent component. An explicit null value indicates that the local props completely override all props received from a parent.

Anatomy

Composed Components

Switch

A Switch uses the following components.

SwitchField

A SwitchField uses the following components.

Switch Examples

Selected

A switch can be selected.

No label

A switch can be rendered without a label.

Disabled

A switch can be disabled.

Sizes

A switch can vary in size.

Icon

A switch can be rendered with an icon or an icon list.

SwitchField Examples

Disabled

A switch field can be disabled.

Sizes

A switch field can vary in size.

Migration Notes

Coming from Orbiter, you should be aware of the following changes:

  • onChange signature has been changed – no events are passed.
  • onValueChange has been deleted, use onChange instead.
  • checked has been renamed to isSelected.
  • disabled has been renamed to isDisabled.
  • The Counter component is no longer allowed as a specialized slot.
  • reverse is not supported, use flex-direction or row-reverse instead.
  • validationState has been removed. A Switch cannot be invalid.