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

# mds-modal

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

The `<mds-modal>` web component is the Magma Design System overlay container for dialogs, presenting content in a windowed surface layered above the page with an optional backdrop. It is the system equivalent of the native `<dialog>` element, adding managed open/close animations, body scroll locking, positioning, and a built-in close affordance.

#### Semantic Behavior

- **Open state**: Visibility is driven by the `opened` prop. Setting it `true` runs the intro animation and emits `mdsModalOpen`; clearing it runs the outro animation and emits `mdsModalClose`.
- **Programmatic close**: Exposes an async `close()` method that dismisses the modal regardless of `interaction`, mirroring the close-button action.
- **Show/hide events**: `mdsModalShow` fires when the intro finishes (fully visible) and `mdsModalHide` when the outro finishes (fully hidden), the latter being the safe point to detach the modal to reclaim memory.
- **Backdrop dismissal**: With `interaction="relaxed"` (default) a click on the backdrop or `Esc` closes the modal. The click counts when it is pressed and released on the backdrop once the window has stopped: a text selection dragged out of a field, a drag from the backdrop into the window or a click while the window is still coming in leave the modal open. With `interaction="strict"` both are ignored, and the touch swipe too (below): only the close button or `close()` can dismiss it.
- **Body scroll lock**: When `overflow="auto"` the component locks body scroll while open and restores it on close.
- **Touch dismissal**: On touch devices a horizontal swipe past a threshold closes a `relaxed` modal, respecting the swipe direction implied by edge `position` values.
- **Slot-driven layout**: With no `window` slot, the default slot renders centered content framed by optional `top` (header) and `bottom` (footer) slots, and a close button is rendered automatically, icon-only and named in the page language (the `lang` of `<html>`) ("Close"). Slotting a `window` element suppresses the built-in chrome and close button so the consumer supplies the entire surface.
- **Title of a banner window**: An `mds-banner` slotted as the `window` draws its `headline` in `h5`, the title of a dialog (`titles/dialog` of the design language), above the `h6` of the parts and the groups of fields the dialog holds; in the page the banner keeps `h6`. The headline is hidden from screen readers: the dialog takes its name from `aria-label` on the host.
- **Width of a slotted window**: The `window` element stops at the width of a dialog, `--magma-width-dialog` (the column of a form plus its inset, 580px at 16px: `widths/dialog` of the design language), and shrinks with a narrower screen, its margin around it. A class on the element wins over it, for a bespoke surface.
- **Close button placement**: The built-in close button sits on the backdrop, in a strip the window always leaves free, so a `strict` modal can be closed whatever its content. `left` and `right` leave it at their side at every width.
- **Narrow screens**: At a viewport of 480px or less a window that would fill the screen (`center` and the four corners) leaves a strip of backdrop at the top, where the close button shows, as `left` and `right` leave one at their side; `top` and `bottom` stay as tall as their content but never taller than the screen less that strip, which stays on their free side with the close button at its edge (top right for `bottom`, bottom right for `top`).
- **Wide screens**: Above 480px every window leaves a strip of backdrop at its side, with the close button at its top: `center`, `top` and `bottom` one on each side, the button at the top right; the corners one on the side away from their own, the button there.

#### Properties & Visual Configurations

This component does not use the shared `variant` / `tone` ladders; its configuration is structural and motion-oriented.

#### Other behavioral props

- **`position`** sets where the window animates from and rests, from `'center'` to edge and corner anchors (`'top'`, `'bottom-left'`, etc.); edge positions also define the valid swipe-to-dismiss direction.
- **`animation`** selects the motion style of the window: `'slide'` (default), `'3d'`, or `'custom'` (driven entirely by CSS custom properties).
- **`interaction`** governs how forgiving dismissal is - `'relaxed'` allows backdrop clicks, `'strict'` requires the close button.
- **`overflow`** chooses whether the component manages body scroll locking (`'auto'`) or leaves it to the consumer (`'manual'`).
- **`hideBackdrop`** removes the dimmed overlay behind the window (shown by default).

## 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-modal--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 |
| --- | --- | --- | --- | --- |
| `accessibleName` | `aria-label` | `string \| undefined` | - | The accessible name of the modal: the name a screen reader announces when the window opens. The `<dialog>` this component renders is the dialog, so the name goes there. |
| `animation` | `animation` | `"3d" \| "custom" \| "slide" \| undefined` | `'slide'` | Specifies the animation style of the modal window |
| `hideBackdrop` | `hide-backdrop` | `boolean \| undefined` | `false` | Hides the modal backdrop |
| `interaction` | `interaction` | `"relaxed" \| "strict"` | `'relaxed'` | Specifies if the component can be closed with close button, or also if the backdrop background is cliccked. If `strict` is selected only the close button can dismiss the component via UI. If `relaxed` is selected the component can be dismissed also by clicking the backdrop area: a click pressed and released on the backdrop, once the window has finished its entry. |
| `opened` | `opened` | `boolean \| undefined` | `false` | Specifies if the modal is opened or not |
| `overflow` | `overflow` | `"auto" \| "manual"` | `'auto'` | Specifies if the component prevents the body from scrolling when modal window is opened |
| `position` | `position` | `"bottom" \| "bottom-left" \| "bottom-right" \| "center" \| "left" \| "right" \| "top" \| "top-left" \| "top-right" \| undefined` | `'center'` | Specifies the animation position of the modal window |

## Events

| Event | Detail | Description |
| --- | --- | --- |
| `mdsModalClose` | `void` | Emits when a modal is closed |
| `mdsModalHide` | `void` | Emits when a modal is totally invisible, can be useful to detach the component when it's hidden and gain memory |
| `mdsModalOpen` | `void` | Emits when a modal is opened, as its intro animation starts: `mdsModalShow` follows once it is totally visible |
| `mdsModalShow` | `void` | Emits when a modal is totally visible, when the modal intro animation is finished |

## Methods

| Method | Signature | Description |
| --- | --- | --- |
| `close` | `close() => Promise<void>` | Closes the modal. |

## Slots

| Slot | Description |
| --- | --- |
| (default) | Contents that will be placed in the center of the window. Add `text string`, `HTML elements` or `components` to this slot. |
| `bottom` | Contents that will be placed on bottom of the window. Add `text string`, `HTML elements` or `components` to this slot. |
| `top` | Contents that will be placed on top of the window. Add `text string`, `HTML elements` or `components` to this slot. |
| `window` | Use directly a window component if you need it. Add `text string`, `HTML elements` or `components` to this slot. |

## Parts

| Part | Description |
| --- | --- |
| `action-close` | Selects the close button of the modal. |
| `dialog` | The native `<dialog>` that covers the viewport and places the window in it |
| `window` | Selects the default window element of the modal when used. |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-modal-custom-closed-transform` | Sets the transform position of the custom window when it's outside the viewport, to it's default position |
| `--mds-modal-custom-window-distance` | Set the distance between the slotted modal window and the screen bounds |
| `--mds-modal-window-distance` | Set the distance between the modal window and the screen bounds |
| `--mds-modal-window-max-width` | If the viewport is greather than mobile, max-width will be considered with this value; |
| `--mds-modal-window-min-width` | If the viewport is greather than mobile, min-width will be considered with this value; |
| `--mds-modal-window-overflow` | Set the overflow of the window |
| `--mds-modal-z-index` | Set the z-index of the window when the component is opened |

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

## Dependencies

Uses: `mds-button`.
Used by: `mds-header`, `mds-status-bar`.
