ctify

Switch

Switches toggle the state of an item on or off

Usage

Props

NameTypeDefaultDescription
iconsboolean—Show x or √ icon
colorprimary secondary tertiaray error—The color of the switch
defaultSelectedboolean—Whether the Switch should be selected (uncontrolled).
isSelectedboolean—Whether the Switch should be selected (controlled).
isDisabledboolean—Whether the input is disabled.
isReadOnlyboolean—Whether the input can be selected but not changed by the user.
autoFocusboolean—Whether the element should receive focus on render.
namestring—The name of the input element, used when submitting an HTML form. See MDN.
childrenstring React.ReactNode—The children of the component. A function may be provided to alter the children based on component state.
classNamestring (values: SwitchRenderProps & { defaultClassName: string | undefined}) => string—The CSS className for the element. A function may be provided to compute the class based on component state.
styleReact.CSSProperties—The 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.