Skip to content

ToggleButton ​

An aria-pressed two-state toggle button; the pressed state uses the primary color background. Supports size steps, icons (including icon-only form), selection color and validation status.

Basic Usage ​

Basic

BoldItalic

Events ​

Change events

Underline

Disabled ​

Disabled

StrikethroughStrikethrough (pressed)

Size Steps (size) ​

size has three steps: small / medium (default) / large; control height and font size follow global tokens. When not set explicitly, the config-provider size injection is respected (global density):

Size steps

SmallSmall (pressed)Medium (default)Medium (pressed)LargeLarge (pressed)

Icons (icon / icon-only) ​

icon takes an @oas-ui/icons registry name and renders the icon before the text (spacing via --oas-space-2). Without text it automatically becomes icon-only (square), with the icon name as the fallback accessible name — prefer providing a precise label via aria-label:

Icons and icon-only

FavoriteLike

Two-state icon (icon-toggled) ​

icon-toggled sets the pressed-state icon: while pressed that icon is rendered instead; on release it falls back to icon (with only icon-toggled set, nothing renders while unpressed). Orthogonal to color / variant / the icon-only form; the icon-only accessible-name fallback follows the active icon (prefer a stable aria-label):

Two-state icon (icon swaps when pressed)

FavoriteFavorite (pressed)

Selection Color (color) ​

color follows the unified ui-spec protocol: any CSS color value (text color auto black/white by luminance) takes precedence; the 11 preset names (magenta / red / volcano / orange / gold / lime / green / cyan / blue / geekblue / purple) resolve to --oas-preset-* tokens (light/dark adaptive); default is the primary color. Theme-level batch customization goes through the CSS variables --oas-toggle-color / --oas-toggle-on-color:

Selection color

PurpleGreenCustomLight (auto dark text)

Validation Status (status) ​

status has three states: success / warning / error: borders take the semantic color and the focus ring is dyed to match; error syncs the host aria-invalid (a host-set aria-invalid="true" is equivalent to the error visuals):

Validation status

SuccessWarningError

Variant ​

The variant dimension (aligned with the oas-button variant system, restricted to the subset meaningful for toggles): solid (default, bordered box, pressed = solid primary fill) / outlined (transparent background with border; pressed = primary border + faint tint) / filled (soft tinted background, no border; pressed = solid fill) / text (no border or background; pressed = faint tint + primary text). Invalid values silently fall back to solid; orthogonal to size / color / status (status colors win). Icon-only toolbar toggles suit text or outlined; filter panels suit filled.

Four variants (resting / pressed side by side)

Solid (default)Solid (pressed)OutlinedOutlined (pressed)FilledFilled (pressed)TextText (pressed)

Variants with real toggling (click for feedback)

MarkFilterPin

API ​

oas-toggle-button ​

Attributes ​

AttributeDescriptionTypeDefault
aria-labelAccessible name (host override channel, written to the inner button)——
colorSelected color: preset name (--oas-preset-* token) or any CSS color (auto text color)string—
disabledDisabledboolean—
iconIcon (oas-icon name); icon-only renders an equal squarestring—
icon-toggledPressed-state icon (oas-icon name): rendered while pressed, falls back to icon on release (with only icon-toggled set, nothing renders while unpressed); the icon-only accessible-name fallback follows the active iconstring—
pressedWhether pressed (controlled)boolean—
sizeSize preset small / medium (default) / largestringmedium
statusValidation status: error / warning / success; error mirrors aria-invalidstring—
valueValue (returned with events)string—
variantVariant (aligned with the button variant system): solid (default, bordered box, pressed = solid fill) / outlined (transparent bg + border; pressed = colored border + faint tint) / filled (soft tinted bg, no border; pressed = solid fill) / text (no border/background; pressed = faint tint + colored text); invalid values silently fall back to solidstring—

Property (JS property; see each row for attribute reflection) ​

PropertyDescriptionTypeDefault
valueCurrent value: the value identifier string (the pressed state is the separate pressed attribute)string—

Events ​

EventDescription
oas-changeToggle, detail: { value, pressed }

Slots ​

NameDescription
defaultButton content (label / icon)

CSS Variables ​

CSS VariableDefault
--oas-toggle-colorvar(--oas-color-primary)
--oas-toggle-on-colorvar(--oas-color-text-on-primary)
--oas-toggle-tint-textvar(--oas-color-primary-text)

Released under the MIT OR Apache-2.0 License.