ctify

Switch

Switches toggle the state of an item on or off

Usage

Props

NameTypeDefaultDescription
iconsbooleanShow x or √ icon
colorprimary secondary tertiaray errorThe color of the switch
defaultSelectedbooleanWhether the Switch should be selected (uncontrolled).
isSelectedbooleanWhether the Switch should be selected (controlled).
isDisabledbooleanWhether the input is disabled.
isReadOnlybooleanWhether the input can be selected but not changed by the user.
autoFocusbooleanWhether the element should receive focus on render.
namestringThe name of the input element, used when submitting an HTML form. See MDN.
childrenstring React.ReactNodeThe children of the component. A function may be provided to alter the children based on component state.
classNamestring (values: SwitchRenderProps & { defaultClassName: string | undefined}) => stringThe CSS className for the element. A function may be provided to compute the class based on component state.
styleReact.CSSPropertiesThe inline style for the element. A function may be provided to compute the style based on component state.

Events

NameTypeDescription
onChange(isSelected: boolean) => voidHandler that is called when the Switch's selection state changes.
onFocus(e: FocusEvent<Target>) => voidHandler that is called when the element receives focus.
onBlur(e: FocusEvent<Target>) => voidHandler that is called when the element loses focus.
onFocusChange(isFocused: boolean) => voidHandler that is called when the element's focus status changes.
onKeyDown(e: KeyboardEvent) => voidHandler that is called when a key is pressed.
onKeyUp(e: KeyboardEvent) => voidHandler that is called when a key is released.
onHoverStart(e: HoverEvent) => voidHandler that is called when a hover interaction starts.
onHoverEnd(e: HoverEvent) => voidHandler that is called when a hover interaction ends.
onHoverChange(isHovering: boolean) => voidHandler that is called when the hover state changes.