# Modal

> Accessible dialog overlay with focus trap, escape handling, and scroll lock.

- Tier: free, MIT
- Category: Overlays
- Docs: https://ui.mlola.com/docs/components/modal

## Install

```bash
npx mlola-ui add modal
```

```tsx
import { Modal } from "@/components/ui/modal";
```

## Props with fixed values

| Component | Prop | Values | Default | Description |
| --- | --- | --- | --- | --- |
| Modal | `size` | `sm`, `md`, `lg`, `xl`, `full` | `md` |  |

## Example

```tsx
"use client";

import * as React from "react";
import { Button } from "@/components/ui/button";
import { Modal, ModalBody, ModalFooter, ModalHeader } from "@/components/ui/modal";

export default function Example() {
  const [open, setOpen] = React.useState(false);
  const close = () => setOpen(false);
  return (
    <>
      <Button variant="danger" onClick={() => setOpen(true)}>Delete project</Button>
      <Modal open={open} onClose={close} size="sm" role="alertdialog">
        <ModalHeader title="Delete project" onClose={close} />
        <ModalBody>This removes the project and every deployment attached to it.</ModalBody>
        <ModalFooter>
          <Button variant="secondary" onClick={close}>Keep it</Button>
          <Button variant="danger" onClick={close}>Delete</Button>
        </ModalFooter>
      </Modal>
    </>
  );
}
```

## The same markup without React

```html
<button class="ml-button" type="button" data-variant="danger" data-ml-opens="delete-project">
  <span class="ml-button-label">Delete project</span>
</button>

<div class="ml-modal-overlay" data-ml-for="delete-project" hidden></div>
<div class="ml-modal" id="delete-project" data-ml="modal" role="alertdialog" aria-modal="true" aria-labelledby="delete-project-title" data-size="sm" tabindex="-1" hidden>
  <div class="ml-modal-header">
    <h2 class="ml-modal-title" id="delete-project-title">Delete project</h2>
    <button class="ml-modal-close" type="button" aria-label="Close dialog"><svg class="mlola-glyph" width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M18 6 6 18M6 6l12 12"/></svg></button>
  </div>
  <div class="ml-modal-body">This removes the project and every deployment attached to it.</div>
  <div class="ml-modal-footer">
    <button class="ml-button" type="button" data-variant="secondary" data-ml-close><span class="ml-button-label">Keep it</span></button>
    <button class="ml-button" type="button" data-variant="danger"><span class="ml-button-label">Delete</span></button>
  </div>
</div>
```

Load `@mlola-ui/behavior` and call `observe()` to give this markup its keyboard and state handling.
