Skip to content
Focsd homeFocsd homeFocsd
Forms

Toggle

A button that stays pressed, for on/off formatting or view options.

  • Tag: focsd-toggle
  • Pattern: Toggle button (aria-pressed)
  • Category: Actions

Example

Bold Show grid
HTML
<focsd-toggle>Bold</focsd-toggle> <focsd-toggle pressed>Show grid</focsd-toggle>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-toggle.js';
</script>
<focsd-toggle>Bold</focsd-toggle>

API

Attributes

AttributePropertyTypeDefault
pressedpressedbooleanfalse
iconiconstring—
icon-libraryiconLibrarystring—
variantvariant'plain' | 'action' | 'quiet' | 'critical'plain
typetype'button' | 'submit' | 'reset'button
disableddisabledbooleanfalse
namenamestring—
valuevaluestring—
expandedexpandedboolean—
haspopuphaspopupstring—
descriptiondescriptionstring—
popovertargetpopoverTargetstring—
popovertargetactionpopoverTargetAction'toggle' | 'show' | 'hide'toggle
commandforcommandForstring—
commandcommandstring—
formactionformActionstring—
formmethodformMethodstring—
formenctypeformEnctypestring—
formnovalidateformNoValidatebooleanfalse
formtargetformTargetstring—

Events

EventDescription
changeFired when the user commits a change to the value or state.

Slots

SlotDescription
(default)Default content.
iconAny icon markup before the label (an SVG, an icon component, an icon-font element), instead of icon.

CSS parts

Style the inside of the component with ::part(), for example focsd-toggle::part(icon).

PartDescription
iconThe icon wrapper (decorative; the label names the element).
controlThe control element.

Accessibility

  • A <button aria-pressed>; the label stays the same while the pressed state changes.
  • Use a switch instead when the control changes a setting immediately and persistently.

Keyboard

KeyAction
Enter / SpaceToggles pressed