Skip to content

Commit 62718d4

Browse files
authored
Document RAC Dialog close button slot (#7405)
1 parent 16153ed commit 62718d4

File tree

2 files changed

+47
-43
lines changed

2 files changed

+47
-43
lines changed

packages/react-aria-components/docs/Dialog.mdx

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,20 @@ import {DialogTrigger, Modal, Dialog, Button, Heading, TextField, Label, Input}
5050
<Button>Sign up…</Button>
5151
<Modal>
5252
<Dialog>
53-
{({close}) => (
54-
<form>
55-
<Heading slot="title">Sign up</Heading>
56-
<TextField autoFocus>
57-
<Label>First Name</Label>
58-
<Input />
59-
</TextField>
60-
<TextField>
61-
<Label>Last Name</Label>
62-
<Input />
63-
</TextField>
64-
<Button onPress={close} style={{marginTop: 8}}>
65-
Submit
66-
</Button>
67-
</form>
68-
)}
53+
<form>
54+
<Heading slot="title">Sign up</Heading>
55+
<TextField autoFocus>
56+
<Label>First Name</Label>
57+
<Input />
58+
</TextField>
59+
<TextField>
60+
<Label>Last Name</Label>
61+
<Input />
62+
</TextField>
63+
<Button slot="close" style={{marginTop: 8}}>
64+
Submit
65+
</Button>
66+
</form>
6967
</Dialog>
7068
</Modal>
7169
</DialogTrigger>
@@ -113,7 +111,7 @@ building fully accessible custom dialogs from scratch is very difficult and erro
113111

114112
<Anatomy />
115113

116-
A dialog consists of a container element and an optional title. It can be placed within a [Modal](Modal.html) or [Popover](Popover.html), to create modal dialogs, popovers, and other types of overlays. A `DialogTrigger` can be used to open a dialog overlay in response to a user action, e.g. clicking a button.
114+
A dialog consists of a container element and an optional title and close button. It can be placed within a [Modal](Modal.html) or [Popover](Popover.html), to create modal dialogs, popovers, and other types of overlays. A `DialogTrigger` can be used to open a dialog overlay in response to a user action, e.g. clicking a button.
117115

118116
```tsx
119117
import {DialogTrigger, Modal, Dialog, Button, Heading} from 'react-aria-components';
@@ -123,6 +121,7 @@ import {DialogTrigger, Modal, Dialog, Button, Heading} from 'react-aria-componen
123121
<Modal>
124122
<Dialog>
125123
<Heading slot="title" />
124+
<Button slot="close" />
126125
</Dialog>
127126
</Modal>
128127
</DialogTrigger>
@@ -199,6 +198,17 @@ Alert dialogs are a special type of dialog meant to present a prompt that the us
199198

200199
A `<Heading>` accepts all HTML attributes.
201200

201+
### Button
202+
203+
A `<Button slot="close">` element can be placed inside a `<Dialog>` to close it when pressed.
204+
205+
<details>
206+
<summary style={{fontWeight: 'bold'}}><ChevronRight size="S" /> Show props</summary>
207+
208+
<PropTable component={docs.exports.Button} links={docs.links} />
209+
210+
</details>
211+
202212
## Styling
203213

204214
React Aria components can be styled in many ways, including using CSS classes, inline styles, utility classes (e.g. Tailwind), CSS-in-JS (e.g. Styled Components), etc. By default, all components include a builtin `className` attribute which can be targeted using CSS selectors. These follow the `react-aria-ComponentName` naming convention.

packages/react-aria-components/docs/Modal.mdx

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,20 @@ import {DialogTrigger, Modal, Dialog, Button, Heading, TextField, Label, Input}
4949
<Button>Sign up…</Button>
5050
<Modal>
5151
<Dialog>
52-
{({close}) => (
53-
<form>
54-
<Heading slot="title">Sign up</Heading>
55-
<TextField autoFocus>
56-
<Label>First Name: </Label>
57-
<Input />
58-
</TextField>
59-
<TextField>
60-
<Label>Last Name: </Label>
61-
<Input />
62-
</TextField>
63-
<Button onPress={close}>
64-
Submit
65-
</Button>
66-
</form>
67-
)}
52+
<form>
53+
<Heading slot="title">Sign up</Heading>
54+
<TextField autoFocus>
55+
<Label>First Name: </Label>
56+
<Input />
57+
</TextField>
58+
<TextField>
59+
<Label>Last Name: </Label>
60+
<Input />
61+
</TextField>
62+
<Button slot="close">
63+
Submit
64+
</Button>
65+
</form>
6866
</Dialog>
6967
</Modal>
7068
</DialogTrigger>
@@ -209,11 +207,9 @@ By default, modals can be closed by pressing the <Keyboard>Escape</Keyboard> key
209207
<Button>Open dialog</Button>
210208
<Modal isKeyboardDismissDisabled>
211209
<Dialog>
212-
{({close}) => <>
213-
<Heading slot="title">Notice</Heading>
214-
<p>You must close this dialog using the button below.</p>
215-
<Button onPress={close}>Close</Button>
216-
</>}
210+
<Heading slot="title">Notice</Heading>
211+
<p>You must close this dialog using the button below.</p>
212+
<Button slot="close">Close</Button>
217213
</Dialog>
218214
</Modal>
219215
</DialogTrigger>
@@ -231,11 +227,9 @@ import {ModalOverlay} from 'react-aria-components';
231227
<ModalOverlay className="my-overlay">
232228
<Modal className="my-modal">
233229
<Dialog>
234-
{({close}) => <>
235-
<Heading slot="title">Notice</Heading>
236-
<p>This is a modal with a custom modal overlay.</p>
237-
<Button onPress={close}>Close</Button>
238-
</>}
230+
<Heading slot="title">Notice</Heading>
231+
<p>This is a modal with a custom modal overlay.</p>
232+
<Button slot="close">Close</Button>
239233
</Dialog>
240234
</Modal>
241235
</ModalOverlay>

0 commit comments

Comments
 (0)