Skip to content
Focsd homeFocsd homeFocsd
Forms

Button

Triggers an action. Four variants map to intent, and the label names the outcome.

  • Tag: focsd-button
  • Pattern: Button
  • Category: Actions

Example

Save changes Cancel Preview email Delete workspace Export (no data yet)
HTML
<focsd-button variant="action">Save changes</focsd-button>
<focsd-button>Cancel</focsd-button>
<focsd-button variant="quiet">Preview email</focsd-button>
<focsd-button variant="critical">Delete workspace</focsd-button>
<focsd-button disabled>Export (no data yet)</focsd-button>

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-button.js';
</script>
<focsd-button variant="action">Save changes</focsd-button>

API

Attributes

AttributePropertyTypeDefault
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—

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-button::part(icon).

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

Accessibility

  • Native parity: popovertarget/popovertargetaction, commandfor/command (built-in dialog and popover commands, or a custom --name fired on the target as a focsd-command event) and the submit overrides formaction, formmethod, formenctype, formnovalidate and formtarget. Targets are found by id in the same tree.
  • With submit overrides, the button submits through a temporary native submitter that is removed once the submit event has run: read new FormData(form, event.submitter) inside the handler, before any await.
  • Renders a native <button> in its shadow root and delegates focus to it, so it is announced as a button with its slotted text as the name.
  • disabled uses aria-disabled: the button stays focusable so people can discover it, and activation is swallowed. Explain why nearby, or with a tooltip.
  • type="submit" and type="reset" act on the owning form, like a native button.
  • Name the outcome ("Save changes", "Remove Lukas"), never "OK" or "Submit".

Keyboard

KeyAction
Enter / SpaceActivates the button