Toggle
A two-state button that can be on or off.
The Stencil example uses fs-toggle. The component owns its uncontrolled pressed state;
the visible pressedChange listener only chooses the icon, replacing React’s render callback.
The shared stencil-toggle-view.tsx is used by both the live example and its server-rendered preview.
native-button="false" uses a span with button semantics. React’s render callback is not a
Web Component property: use slotted content and the public change event instead. type and
form overrides are ignored, and value is not submitted as a native button value, matching Base UI.
Inside fs-toggle-group, selection, disabled inheritance, and the roving tab stop are managed
by the migrated group. Grouped Space activation occurs on keydown, matching Base UI’s composite
behavior. Inside fs-toolbar-root, the toolbar supplies the outer roving tab stop.
Use fs-toolbar-button asChild to compose a focusable-when-disabled toolbar toggle.
Anatomy
Import the component and use it as a single part:
API reference
valuestring—
- Name
- Description
A unique string that identifies the toggle when used inside a toggle group.
- Type
defaultPressedbooleanfalse
- Name
- Description
Whether the toggle button is currently pressed. This is the uncontrolled counterpart of
pressed.- Type
- Default
false
pressedboolean—
- Name
- Description
Whether the toggle button is currently pressed. This is the controlled counterpart of
defaultPressed.- Type
onPressedChangefunction—
- Name
- Description
Callback fired when the pressed state is changed.
- Type
nativeButtonbooleantrue
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (for example,<div>).- Type
- Default
true
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
- Default
false
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-pressed
Present when the toggle button is pressed.
data-disabled
Present when the toggle button is disabled.
Attribute | Description | |
|---|---|---|
data-pressed | Present when the toggle button is pressed. | |
data-disabled | Present when the toggle button is disabled. | |