Skip to contents

Toggle

A two-state button that can be on or off.

View as Markdown

Anatomy

Import the component and use it as a single part:

Anatomy

API reference

value
string
Name
Description

A unique string that identifies the toggle when used inside a toggle group.

Type
string | undefined
defaultPressed
boolean
false
Description

Whether the toggle button is currently pressed. This is the uncontrolled counterpart of pressed.

Type
boolean | undefined
Default
false
pressed
boolean
Description

Whether the toggle button is currently pressed. This is the controlled counterpart of defaultPressed.

Type
boolean | undefined
onPressedChange
function
Description

Callback fired when the pressed state is changed.

Type
nativeButton
boolean
true
Description

Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).

Type
boolean | undefined
Default
true
disabled
boolean
false
Description

Whether the component should ignore user interaction.

Type
boolean | undefined
Default
false
className
string | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
style
React.CSSProperties | function
Name
Type
render
ReactElement | function
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
data-pressed
Present when the toggle button is pressed.

Additional Types

Toggle.Props

Re-Export of Toggle props as ToggleProps

Toggle.State
Toggle.ChangeEventReason
Toggle.ChangeEventDetails