Toggle
A button that stays pressed, for on/off formatting or view options.
Example
<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>import { Toggle } from '@focsd-dev/react';
export function Example() { return <Toggle onChange={(e) => console.log(e.target)}>Bold</Toggle>;}<script setup>import '@focsd-dev/components/focsd-toggle.js';</script>
<template> <focsd-toggle @change="onChange">Bold</focsd-toggle></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-toggle.js';
// template<focsd-toggle (change)="onChange($event)">Bold</focsd-toggle><script> import '@focsd-dev/components/focsd-toggle.js';</script>
<focsd-toggle onchange={(e) => console.log(e.target)}>Bold</focsd-toggle>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
pressed | pressed | boolean | false |
icon | icon | string | — |
icon-library | iconLibrary | string | — |
variant | variant | 'plain' | 'action' | 'quiet' | 'critical' | plain |
type | type | 'button' | 'submit' | 'reset' | button |
disabled | disabled | boolean | false |
name | name | string | — |
value | value | string | — |
expanded | expanded | boolean | — |
haspopup | haspopup | string | — |
description | description | string | — |
popovertarget | popoverTarget | string | — |
popovertargetaction | popoverTargetAction | 'toggle' | 'show' | 'hide' | toggle |
commandfor | commandFor | string | — |
command | command | string | — |
formaction | formAction | string | — |
formmethod | formMethod | string | — |
formenctype | formEnctype | string | — |
formnovalidate | formNoValidate | boolean | false |
formtarget | formTarget | string | — |
Events
| Event | Description |
|---|---|
change | Fired when the user commits a change to the value or state. |
Slots
| Slot | Description |
|---|---|
(default) | Default content. |
icon | Any 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).
| Part | Description |
|---|---|
icon | The icon wrapper (decorative; the label names the element). |
control | The 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
| Key | Action |
|---|---|
| Enter / Space | Toggles pressed |
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.