# u-dialog

```ts
import '@iyulab/components/dist/components/dialog/UDialog.js';
```

**Tag:** `u-dialog`

Modal or non-modal dialog window. Supports focus-trap, scroll-lock, ESC/backdrop close, and configurable placement.

For programmatic usage (`Dialog.alert`, `Dialog.confirm`, `Dialog.prompt`), see [dialog.md](../utilities/dialog.md).

```html
<u-dialog id="dlg" closable placement="center">
  <span slot="header">Confirm Action</span>
  <p>Are you sure you want to delete this item?</p>
  <div slot="footer">
    <u-button appearance="plain" @click=${() => dlg.hide()}>Cancel</u-button>
    <u-button appearance="solid" @click=${handleConfirm}>Delete</u-button>
  </div>
</u-dialog>

<u-button @click=${() => dlg.show()}>Open</u-button>
```

---

## Sizing

The panel is **content-sized, capped at 90%** of the dialog's own box — 90% of the height and of
the width. Measured in an 896px-tall viewport: a short dialog renders a 235px panel, and the same
dialog carrying 3,000px of body content stops at 806px.

Past that cap the **body is the only scroll region**. The `header` and `footer` slots are
`flex-shrink: 0`, so the title and the actions stay visible however long the content grows.

There is no size property. To make the dialog smaller than 90% of the viewport, give the **host** a
height — that is what the 90% is measured against:

```css
u-dialog { height: 400px; }   /* the panel then caps at 360px */
```

⚠ That lever only shrinks: a height on the host lowers the panel's maximum, it does not reserve a
panel of that size. A short dialog stays short.

## Accessibility

The host is exposed as a **`dialog`**, with `aria-modal` when `mode="modal"`. Its name is whatever sits in the
`header` slot, and follows that content as it changes. Without a header, name it with `aria-label` (or
`aria-labelledby`) on the host — attributes on the host override the defaults, including `role="alertdialog"` for a
message that needs a response.

## Slots

| Name | Description |
|------|-------------|
| `header` | Dialog header area |
| *(default)* | Dialog body content |
| `footer` | Dialog footer area |

## Properties

| Property | Type | Default | Reflect | Description |
|----------|------|---------|---------|-------------|
| `open` | `boolean` | `false` | ✓ | Show/hide state |
| `closable` | `boolean` | `false` | ✓ | Show close button |
| `placement` | `'top-start'\|'top'\|'top-end'\|'start'\|'center'\|'end'\|'bottom-start'\|'bottom'\|'bottom-end'` | `'center'` | ✓ | Position on screen |
| `offset` | `number` | `0` | ✓ | Distance from screen edge in px |
| `mode` | `'modal'\|'non-modal'` | `'modal'` | ✓ | `modal` traps focus and places initial focus (`[autofocus]` → first input control → first tabbable, through shadow roots); `non-modal` does neither |
| `contained` | `boolean` | `false` | ✓ | Position relative to parent element |
| `closeOn` | `string[]` | `['escape','backdrop','button']` | ✓ | Close triggers |

## Events

| Event | Cancelable | Description |
|-------|------------|-------------|
| `show` | ✓ | Before the dialog opens |
| `hide` | ✓ | Before the dialog closes |

## Methods

| Method | Returns | Description |
|--------|---------|-------------|
| `show()` | `boolean` | Open the dialog |
| `hide()` | `boolean` | Close the dialog |
| `requestClose(source)` | `void` | Request close from a given source (checks `closeOn` policy) |

## CSS Parts

| Part | Description |
|------|-------------|
| `container` | Backdrop/positioning wrapper |
| `panel` | The dialog panel |
| `header` | Header area |
| `body` | Body area |
| `footer` | Footer area around the `footer` slot — its padding and top divider (not drawn when the slot is empty). They live here, not on the slotted element, so a document-wide reset such as Tailwind's preflight cannot strip them |
| `close-btn` | Close button |
