# Native dialog

Host: No library. Path: transitions. Preset: `scale-fade`.

The backdrop fades in step, because overlay is in the transition list under allow-discrete and the element stays in the top layer for the whole exit.

The page this file mirrors mounts the component twice, once with the attribute and once without, so the only difference between the two is the library.

Upstream documentation: [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/dialog)

The same component in other hosts: [Radix UI](/radix/dialog.md), [Base UI](/base-ui/dialog.md).

## Where the attribute goes

The parts this demo composes, and the value each one carries. Everything inside an animated part is that part's content, so the tree stops there.

```text
button
dialog  data-motion="scale-fade"
```

## How the match works

| Step | Value |
| --- | --- |
| host writes | `[open], and the top layer` |
| easeful matches | `[data-motion~="scale-fade"]dialog:not([open])` |
| what runs | `transition: opacity, scale, display, overlay` |
| you write | `<dialog data-motion="scale-fade">` |

## Every value that works here

Every value the manifest allows on this host, single presets and the pairs that compose. The first is what this component ships with. Both stages are the same component, so anything that changes between them is the attribute.

| Value | Link |
| --- | --- |
| `scale-fade` | the default |
| `fade` | [fade](/native/dialog#motion=fade) |
| `slide-up` | [slide-up](/native/dialog#motion=slide-up) |
| `fade slide-up` | [fade slide-up](/native/dialog#motion=fade%20slide-up) |
| `scale-fade slide-up` | [scale-fade slide-up](/native/dialog#motion=scale-fade%20slide-up) |

## Source

`apps/docs/components/demos/native/dialog.tsx`

```tsx
"use client"

import { useRef } from "react"
import type { DemoProps } from "@/components/demos/props"

export function NativeDialog({ motion }: DemoProps) {
  const ref = useRef<HTMLDialogElement>(null)

  return (
    <>
      <button type="button" className="btn" onClick={() => ref.current?.showModal()}>
        Open dialog
      </button>
      <dialog ref={ref} className="modal" data-motion={motion}>
        <p className="panel__title">Top layer, with a backdrop</p>
        <p className="panel__body">
          The backdrop fades in step with the panel, because overlay is in the transition list
          under allow-discrete and the element stays in the top layer for the whole exit.
        </p>
        <div className="modal__actions">
          <button type="button" className="btn btn--primary" onClick={() => ref.current?.close()}>
            Close
          </button>
        </div>
      </dialog>
    </>
  )
}
```
