1 | # @reach/dialog
|
2 |
|
3 | [](https://npm.im/@reach/dialog) 
|
4 |
|
5 | [Docs](https://reach.tech/dialog) | [Source](https://github.com/reach/reach-ui/tree/main/packages/dialog) | [WAI-ARIA](https://www.w3.org/TR/wai-aria-practices-1.2/#dialog_modal)
|
6 |
|
7 | An accessible dialog or modal window.
|
8 |
|
9 | ```jsx
|
10 | import { Dialog } from "@reach/dialog";
|
11 | import "@reach/dialog/styles.css";
|
12 |
|
13 | function Example(props) {
|
14 | const [showDialog, setShowDialog] = React.useState(false);
|
15 | const open = () => setShowDialog(true);
|
16 | const close = () => setShowDialog(false);
|
17 |
|
18 | return (
|
19 | <div>
|
20 | <button onClick={open}>Open Dialog</button>
|
21 | <Dialog isOpen={showDialog} onDismiss={close}>
|
22 | <button className="close-button" onClick={close}>
|
23 | <VisuallyHidden>Close</VisuallyHidden>
|
24 | <span aria-hidden>×</span>
|
25 | </button>
|
26 | <p>Hello there. I am a dialog</p>
|
27 | </Dialog>
|
28 | </div>
|
29 | );
|
30 | }
|
31 | ```
|