Toggle
A button that stays pressed until it is clicked again.
Installation
Needs the arene setup first. Also adds Button.
Install the packages it imports:
Set up the token layer and the StyleX compiler. See Installation
for states.ts, state-styles.ts and interop.css for icon sizing.
Install Button for buttonStyles and ButtonGroupContext.
Paste this source into the file named in its title.
Change the @/ imports if your project uses different aliases.
Usage
Use defaultPressed for an initial selection, or pressed and onPressedChange
to control it. Give an icon-only toggle an aria-label.
RTL support is not included.
Outline
variant="outline" draws a border around the toggle.
With text
Place text beside the icon to label the toggle.
Size
Use size to change the height and minimum width.
Disabled
Use disabled to prevent interaction.
API reference
Toggle accepts Base UI Toggle props,
including render, plus xstyle, className and real inline style.
Toggle
| Prop | Type | Default |
|---|---|---|
variant | "default" | "outline" | "default" |
size | "sm" | "default" | "lg" | "default" |
A surrounding ToggleGroup supplies variant and size when set on the group.
toggleStyles
| Key | What it is |
|---|---|
base | Button base paired with the shared focus ring |
variants | Default ghost and outline button styles |
sizes | Button heights and minimum widths |
pressed | The flat fill and its text colour |
pressedKey | The raised key a pressed toggle is in a well |
onWell | Row-highlight hover for a ghost toggle on a well |
pressedOnWell | The flat pill face a pressed toggle takes in a well |
segment | Corner nested in a segmented group's well |
disabled | Shared disabled opacity and pointer handling |
ToggleGroupContext carries group-level variant and size to the toggle, and
tells it when it sits in a well: a Toolbar or a
segmented Toggle Group.
Data attributes
| Attribute | On | Effect |
|---|---|---|
data-slot="toggle" | button | Targets the toggle |
data-variant, data-size | button | Mirror the resolved variant and size |
data-pressed, data-disabled | button | Base UI writes the current state |