<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-button/ in the magma monorepo (usage/*.md and the
  component's JSDoc). Regenerated on every stencil build (scripts/component-docs.ts).
-->

# mds-button

> `@maggioli-design-system/magma` 2.15.0. Shadow DOM: style it only through the public CSS custom properties and the parts below.

The `<mds-button>` web component is the primary interactive action control of the Magma Design System. It renders as a button, or as a link when `href` is set, handling form association, accessibility, loading state, and iconography natively.

#### Semantic Behavior

- **Button vs. link**: Providing `href` renders a real anchor inside the component and gives the host `role="link"`. The browser follows the link, so a modifier or middle click opens it in a new tab and the context menu offers the link actions; `target="blank"` opens a new tab on a plain click too. A `click` listener on the host cancels the navigation with `preventDefault()`, which is how a client-side router takes over. A click from the keyboard, a script or an assistive technology lands on the host and is followed the same way, unless cancelled.
- **Download**: with `href`, `download` saves the file instead of opening it, as on a native `<a download>`: with no value the file keeps the name the server gives it, a value names the saved file. Browsers apply it to the URLs of the origin of the page, `blob:` and `data:` only. A download never goes to the router: the click of the pointer, of the keyboard and of a script all reach the anchor, which saves the file.
- **Form association**: Inside a `<form>` the component submits (`type="submit"`, default) or resets (`type="reset"`) it like a native button, with no extra wiring; use `type="button"` to opt out. With `name` set, a submit sends `name=value`, so buttons that submit the same form tell the receiver which one was chosen. A custom element cannot be a submitter, so `event.submitter` is a hidden native button that stands in for the component: it carries the same `name` and `value`, but it is not the `mds-button` element.
- **Active state**: Mirrors a visual pressed state through the `active` attribute, safe to drive from CSS attribute selectors. It is cleared when the pointer is released: it does not mark the view you are in, `current` does.
- **Current state**: `current` marks the button that leads to the view you are in, the current section of a bar or the current view of a switcher. `current` (or `current="page"`) is that view: the button takes no pointer, Enter does nothing, and a click from a script neither navigates nor submits, so going there again never reloads it; it stays in the Tab order, announced with `aria-current="page"` on a link and `aria-current="true"` otherwise. `current="section"` is a view inside it, a record of its list: the same look, but the button stays a link that brings you back, announced with `aria-current="true"`. An `aria-current` written on the host (`step`, `date`) stays as written. The look: an area that weighs less than the hover of the tone, never its ring, so the hover of the other buttons still weighs more. `weak` takes the selected wash of its family (`--magma-accent-surface-selected`, `-wash-soft` for a status variant), `strong` keeps its fill, `outline` and `text` take the wash of their hover, and a variant whose hover keeps the area (`dark` and `light` weak, `light` strong) keeps it too. The label is one weight heavier (`xl` is black already), which marks the state where the area stays under 3:1; the look holds on hover. Never mark the current button with `disabled`, `aria-disabled` or a style of your own.
- **Disabled state**: Blocks pointer and keyboard activation and removes the host from the tab sequence. A disabled `<fieldset>` around the button disables it the same way, as it does a native button, without setting `disabled`.
- **Await state**: Renders an inline spinner, blocks pointer and keyboard activation, and sets `aria-busy="true"` for assistive tech. The button keeps the focus it had, and a click from a script or an assistive technology neither submits nor resets its form again. Remove the attribute when done - do not set `await="false"`.
- **Keyboard**: Enter activates the button as a click does, and so does Space, on release, as on a native button; a button with `href` is a link, which Enter follows and Space does not.
- **Accessibility**: Sets `role="button"` on the host, `role="link"` when `href` is set, whatever the format of the icon; the `label` prop (or slotted text) is rendered as the button text, which names it. Without a label, an `aria-label` or a `title`, the component sets `title` from the last segment of the icon slug (`mi/baseline/delete` -> "delete"), which names the icon, not the action; an icon given as inline SVG or base64 has no slug, and leaves the button with no name at all: icon-only buttons need an explicit `aria-label` (or `title`), or an `mds-tooltip` with `relation="label"`. A host with `aria-labelledby` gets no name from the slug, and loses the one it had when the attribute comes later, as it does from the tooltip.
- **Sizing**: The `size` prop drives padding, font size, and minimum hit area. Do not override dimensions with inline `width` / `height`.
- **Linking constraint**: `target` is effective only when `href` is set.

#### Component-specific variants and tones

The shared `variant` / `tone` ladders are defined in [`agents/variants.md`](../../../../agents/variants.md). `<mds-button>` adds:

- **`variant="google"` / `variant="apple"`**: brand-correct chrome for SSO entry points. Do not reuse them for non-SSO buttons.
- **`tone="box"`**: the `strong` fill with an embossed, raised shadow (`--shadow-box-solid-strong`) and a brighter hover: more marked than `strong`, not less.

#### Other behavioral props

- **`icon`** is an SVG filename slug from the Magma icon library; **`iconPosition`** places the glyph relative to the label (use `right` for forward-motion CTAs).
- **`iconCurrent`** and **`iconHover`** take the place of `icon` in their state: `iconCurrent` on the current button, `iconHover` under the pointer, which falls back on `iconCurrent`. One attribute gives the common pair, an outline icon at rest and the filled one on the current button, which the pointer previews on the others. Set `iconHover` to the `icon` to keep the icon still under the pointer, when `iconCurrent` says something the click does not do (a check). A pointer that cannot hover, a finger, never shows `iconHover`; the current button shows `iconCurrent` under the pointer too. Both need `icon`, which gives the icon its room, and the name taken from the slug stays the one of `icon`. Write every slug out whole, as for `icon`: the icons a product serves are the ones read in its sources.
- **`truncate`**: `word` (default) keeps the label on one line and cuts it with an ellipsis, `all` clamps it with `line-clamp` (one line in the button), `none` lets it wrap onto more lines.
- **`animation`**: `yugop` progressively reveals characters; otherwise text renders immediately.
- **The first letter** of the label is uppercased. For a name or an identifier that must stay as written (`rdsysadmin`), set `--mds-button-label-transform: none` on the button or on any ancestor: the property inherits, so it also reaches the buttons that other components, `mds-button-dropdown` among them, render in their shadow root.

## Read next

- [`examples.md`](examples.md) - correct usage, from the most common case
- [`mistakes.md`](mistakes.md) - the wrong forms, each with the right one
- [Storybook](https://magma-design-system.github.io/magma/storybook/?path=/docs/ui-button--docs) - the live examples, in the published Storybook of `main`
- [`conventions.md`](../../../../agents/conventions.md), [`variants.md`](../../../../agents/variants.md), [`mistakes.md`](../../../../agents/mistakes.md) - the rules shared by every component

## Props

| Prop | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `active` | `active` | `boolean` | - | Specifies if the button is active or not |
| `animation` | `animation` | `"none" \| "yugop" \| undefined` | `'none'` | Specifies if the text is animated when it is rendered |
| `autoFocus` | `auto-focus` | `boolean` | - | Specifies if the component is focused when is loaded on the viewport |
| `await` | `await` | `boolean \| undefined` | - | Specifies if the button is awaiting for a response |
| `current` | `current` | `"page" \| "section" \| boolean \| undefined` | - | Marks the button that leads to the view you are in, as the current section of a bar or the current view of a switcher, with a look of its own: an area that weighs less than the hover of its tone, never its ring, and a heavier label. `current`, or `current="page"`, is that view: the button neither navigates nor submits, a click and Enter do nothing, but it stays in the Tab order, announced with `aria-current` (`"page"` on a link, `"true"` otherwise). `current="section"` is a view inside it, as a record of its list: the same look, and the button stays a link that brings you back, announced with `aria-current="true"`. An `aria-current` written on the host stays as written. |
| `disabled` | `disabled` | `boolean \| undefined` | - | Specifies if the component is disabled or not |
| `download` | `download` | `boolean \| string \| undefined` | - | With `href`, saves its file instead of opening it, as the `download` attribute of `<a>`: present with no value, or `true`, the file takes the name the server gives it; a string is the name of the saved file. Browsers apply it to the URLs of the origin of the page, `blob:` and `data:`: a link to another origin opens the file as without it. A download never goes to the router registered with `NavigationService` |
| `href` | `href` | `string \| undefined` | - | Turns the button into a link to this URL: a real anchor in its shadow root, so the browser gives it what it gives every link (new tab on a modifier or middle click, the context menu, drag). A client-side router takes the plain clicks over once registered with `NavigationService.setHandler()` (from `@maggioli-design-system/magma/services`); without one, a click listener on the host can still cancel the navigation with `preventDefault()`. |
| `icon` | `icon` | `string \| undefined` | - | The icon displayed in the button; `iconCurrent` and `iconHover` take its place in their states |
| `iconCurrent` | `icon-current` | `string \| undefined` | - | The icon of the current button, in place of `icon`: the filled icon, say, of an `icon` drawn as an outline. It is the icon under the pointer too, unless `iconHover` says otherwise, so the pointer previews it on the buttons that are not current. It takes the place of `icon`: without `icon` it shows nothing |
| `iconHover` | `icon-hover` | `string \| undefined` | - | The icon under the pointer, in place of `icon`, and `iconCurrent` when it is not set. Set it to the `icon` to keep the icon still under the pointer, when `iconCurrent` says something the click does not do (a check, say). A pointer that cannot hover, as a finger, never shows it. It takes the place of `icon`: without `icon` it shows nothing |
| `iconPosition` | `icon-position` | `"left" \| "right" \| undefined` | `'left'` | Specifies the horizontal position of the icon displayed in the button |
| `label` | `label` | `string \| undefined` | - | The label of the button |
| `name` | `name` | `string \| undefined` | - | The name sent with `value` to the form the button submits, as a native submit button does: buttons that submit the same form tell the receiver which one was chosen |
| `size` | `size` | `"lg" \| "md" \| "sm" \| "xl"` | `'md'` | Specifies the size for the button |
| `target` | `target` | `"blank" \| "self"` | `'self'` | Specifies the target of the URL, if self or blank |
| `tone` | `tone` | `"box" \| "outline" \| "strong" \| "text" \| "weak" \| undefined` | `'strong'` | Specifies the tone variant for the button |
| `truncate` | `truncate` | `"all" \| "none" \| "word" \| undefined` | `'word'` | Specifies if the text shoud be truncated or should behave as a normal text |
| `type` | `type` | `"a" \| "button" \| "reset" \| "submit" \| undefined` | `'submit'` | The type of the button element |
| `value` | `value` | `string \| undefined` | - | The value sent under `name` to the form the button submits |
| `variant` | `variant` | `"ai" \| "apple" \| "dark" \| "error" \| "google" \| "info" \| "light" \| "primary" \| "secondary" \| "success" \| "warning" \| undefined` | `'primary'` | Specifies the color variant for the button |

## Slots

| Slot | Description |
| --- | --- |
| (default) | Add `text string` to this slot, **avoid** to add `HTML elements` or `components` here. |
| `notification` | Add `HTML elements` or `components`, it is **recommended** to use `mds-notification` element. |

## Parts

| Part | Description |
| --- | --- |
| `icon` | The icon inside the component |
| `label` | The text of the button: the `label`, or the default slot when `label` is not set |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-button-background` | Sets the background-color of the component |
| `--mds-button-color` | Sets the text color of the component |
| `--mds-button-gap` | Sets the distance betwen element inside the components, use it instead of setting gap property directly. |
| `--mds-button-label-transform` | Sets the text-transform of the first letter of the label, `uppercase` by default; `none` shows the label as written. It inherits: set on `mds-button-dropdown` or any ancestor, it reaches the buttons inside other components too |
| `--mds-button-radius` | Sets the border-radius of the component |

Only these are public. Its other 11 are internal: they may change in any release, do not set them.

## Dependencies

Uses: `mds-icon`, `mds-spinner`, `mds-text`.
Used by: `mds-banner`, `mds-breadcrumb`, `mds-breadcrumb-item`, `mds-button-dropdown`, `mds-calendar`, `mds-calendar-cell`, `mds-chip`, `mds-file-preview`, `mds-header-bar`, `mds-horizontal-scroll`, `mds-img`, `mds-input`, `mds-input-date`, `mds-input-date-range`, `mds-input-date-range-preselection`, `mds-input-upload`, `mds-keyboard`, `mds-label`, `mds-mention`, `mds-modal`, `mds-note`, `mds-policy-ai`, `mds-pref-language-item`, `mds-pref-theme-item`, `mds-push-notification`, `mds-push-notification-item`, `mds-radial-menu`, `mds-radial-menu-item`, `mds-tab-item`, `mds-table-header-cell`, `mds-toast`, `mds-tree-item`, `mds-url-view`.
