<!-- Generated from the custom elements manifest by scripts/agent. Contract: /components/focsd-button.md -->

# Button (`<focsd-button>`)

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

Headless button. Renders a native <button part="control">; `disabled` keeps it focusable (aria-disabled) but swallows activation. `type="submit" | "reset"` acts on the owning form. Native button parity: `popovertarget`/`popovertargetaction` (target: an element with `popover`), `commandfor`/`command` (built-ins `show-modal`, `close`, `request-close`, `show-popover`, `hide-popover`, `toggle-popover`, or a custom `--name` dispatched on the target as a `focsd-command` event with the `CommandEvent` shape, `command` and `source`), and the submit overrides `formaction`, `formmethod`, `formenctype`, `formnovalidate`, `formtarget`. Targets are found by id in the button's tree.

- Package: `@focsd-dev/components`
- Import: `import '@focsd-dev/components/focsd-button.js';`
- Category: Actions; pattern: Button
- JSON Schema: [/schema/components/focsd-button.json](/schema/components/focsd-button.json)

## Usage

```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>
```

## Attributes and properties

| Attribute | Property | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `icon` | `icon` | `string` | `''` | An icon before the label: a name from the default icon library (or `icon-library`). For any other icon kit, put it in `slot="icon"`. |
| `icon-library` | `iconLibrary` | `string` | `''` | The registered icon library `icon` comes from; empty for the default. |
| `variant` | `variant` | `'plain' \| 'action' \| 'quiet' \| 'critical'` | `'plain'` | The visual style: `action` for the main action, `critical` for destructive ones, `quiet` for low emphasis. |
| `type` | `type` | `'button' \| 'submit' \| 'reset'` | `'button'` | What the button does in a form, as on `<button>`. |
| `disabled` | `disabled` | `boolean` | `false` | Disables the button. |
| `name` | `name` | `string` | `''` | The name submitted with `value` when this button submits the form. |
| `value` | `value` | `string` | `''` | The value submitted with `name` when this button submits the form. |
| `expanded` | `expanded` | `boolean` | `undefined` | Forwarded to the inner button as aria-expanded (set by menus, popovers, disclosures). |
| `haspopup` | `haspopup` | `string` | `''` | Forwarded as aria-haspopup. |
| `description` | `description` | `string` | `''` | Forwarded as aria-description (set by focsd-tooltip). |
| `popovertarget` | `popoverTarget` | `string` | `''` | The ID of a popover the button shows, hides or toggles, as on `<button>`. |
| `popovertargetaction` | `popoverTargetAction` | `'toggle' \| 'show' \| 'hide'` | `'toggle'` | What the button does to its `popovertarget`. |
| `commandfor` | `commandFor` | `string` | `''` | The ID of the element the button sends `command` to, as on `<button>`. |
| `command` | `command` | `string` | `''` | The command sent to the `commandfor` element, such as `show-modal` or `close`. |
| `formaction` | `formAction` | `string` | `''` | Overrides the form's `action` when this button submits it. |
| `formmethod` | `formMethod` | `string` | `''` | Overrides the form's `method` when this button submits it. |
| `formenctype` | `formEnctype` | `string` | `''` | Overrides the form's `enctype` when this button submits it. |
| `formnovalidate` | `formNoValidate` | `boolean` | `false` | Submits the form without validating it. |
| `formtarget` | `formTarget` | `string` | `''` | Overrides the form's `target` when this button submits it. |

| Property (JS only) | Type | Read-only | Description |
| --- | --- | --- | --- |
| `form` |  | yes | The form the button belongs to, or null. |
| `isDisabled` |  | yes | True when `disabled` is set or an ancestor fieldset is disabled. |
| `internals` |  | no | The element's `ElementInternals`, for subclasses. |
| `localize` |  | no | Translated strings: `this.localize.term(key, ...args)`. |

## Events

_None._

## 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

| Part | Description |
| --- | --- |
| `icon` | The icon wrapper (decorative; the label names the element). |
| `control` | The control element. |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--focsd-button-background` | Background (default the surface; `--focsd-action` for `variant="action"`). |
| `--focsd-button-background-hover` | Background on hover (default the sunk surface; `--focsd-action-hover` for `variant="action"`). |
| `--focsd-button-color` | Text color (default the ink; `--focsd-on-action` for `variant="action"`). |
| `--focsd-button-border-color` | Border color (default `--focsd-edge`; `--focsd-action` for `variant="action"`). |
| `--focsd-button-radius` | Corner radius (default `--focsd-radius-control`). |

## 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".

| Key | Action |
| --- | --- |
| Enter / Space | Activates the button |

## Do and don't

- Do: load it once with `import '@focsd-dev/components/focsd-button.js';` before using `<focsd-button>`.
- Do: set `name` so the value submits with its form, and listen for `input` and `change` as on a native control.
- Do: restyle with the `--focsd-*` custom properties and `::part()` listed above.
- Don't: use attributes, slots or events that are not listed in this contract.
- Don't: set `variant`, `type`, `popovertargetaction` to values outside the listed options.
- Don't: expect a `detail` on the native `input`, `change`, `toggle`, `close` or `cancel` events; they carry none.
- Don't: style shadow DOM internals or hard-code colors; use the `--focsd-*` tokens.
