Button
Triggers an action. Four variants map to intent, and the label names the outcome.
Example
<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>import { Button } from '@focsd-dev/react';
export function Example() { return <Button variant="action">Save changes</Button>;}<script setup>import '@focsd-dev/components/focsd-button.js';</script>
<template> <focsd-button variant="action">Save changes</focsd-button></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-button.js';
// template<focsd-button variant="action">Save changes</focsd-button><script> import '@focsd-dev/components/focsd-button.js';</script>
<focsd-button variant="action">Save changes</focsd-button>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
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 | — |
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-button::part(icon).
| Part | Description |
|---|---|
icon | The icon wrapper (decorative; the label names the element). |
control | The control element. |
Accessibility
- Native parity:
popovertarget/popovertargetaction,commandfor/command(built-in dialog and popover commands, or a custom--namefired on the target as afocsd-commandevent) and the submit overridesformaction,formmethod,formenctype,formnovalidateandformtarget. 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
submitevent has run: readnew FormData(form, event.submitter)inside the handler, before anyawait. - 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. disabledusesaria-disabled: the button stays focusable so people can discover it, and activation is swallowed. Explain why nearby, or with a tooltip.type="submit"andtype="reset"act on the owning form, like a native button.- Name the outcome ("Save changes", "Remove Lukas"), never "OK" or "Submit".
Keyboard
| Key | Action |
|---|---|
| Enter / Space | Activates the button |
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.