Skip to content

Commit ea8387a

Browse files
authored
docs(alert-dialog): fixed modal example (#5666)
* docs(alert-dialog): fixed modal example * docs(alert-dialog): fixed typo * docs(alert-dialog): added dialog base example * docs(alert-dialog): added links to overlay and modal
1 parent 538b93e commit ea8387a

File tree

1 file changed

+89
-43
lines changed

1 file changed

+89
-43
lines changed

packages/alert-dialog/README.md

Lines changed: 89 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import { AlertDialog } from '@spectrum-web-components/alert-dialog';
2727

2828
The alert dialog consists of several key parts:
2929

30-
- **Title:** All alert dialogs must have a title, using `slot="heading"`, that uses a few words to convey the outcome of what will happen if a user continues with an action
31-
- **Content:** Alert dialogs can include a description using the default slot. A description briefly communicates any additional information or context that a user needs to know to continue with an action
32-
- Action buttons, using `slot="button"`, that allow users to respond
30+
- **Title:** All alert dialogs must have a title, using `slot="heading"`, that uses a few words to convey the outcome of what will happen if a user continues with an action
31+
- **Content:** Alert dialogs can include a description using the default slot. A description briefly communicates any additional information or context that a user needs to know to continue with an action
32+
- Action buttons, using `slot="button"`, that allow users to respond
3333

3434
```html
3535
<sp-alert-dialog
@@ -63,12 +63,12 @@ The alert dialog consists of several key parts:
6363

6464
Use `slot="button"` to render your action button(s) that allow users to respond
6565

66-
- An alert dialog must have one primary action button (with `variant="primary"`) with the option to include a secondary action and/or a cancel action.
67-
- Non-primary action buttons should be `variant="secondary"` and `treatment="outline"`.
68-
- The three buttons should be rendered in the DOM in the following order:
69-
- **Cancel action:** Offers an option to go back and cancel the action.
70-
- **Secondary action:** Offers a secondary action. e.g. "Remind me later"
71-
- **Primary action:** The first (right-most) button communicates what the button will do if selected, or to acknowledge and dismiss the dialog. Check [variants](#variants) for the correct primary button styling. See also the [Alert Dialog design options](https://spectrum.adobe.com/page/alert-dialog/#Options).
66+
- An alert dialog must have one primary action button (with `variant="primary"`) with the option to include a secondary action and/or a cancel action.
67+
- Non-primary action buttons should be `variant="secondary"` and `treatment="outline"`.
68+
- The three buttons should be rendered in the DOM in the following order:
69+
- **Cancel action:** Offers an option to go back and cancel the action.
70+
- **Secondary action:** Offers a secondary action. e.g. "Remind me later"
71+
- **Primary action:** The first (right-most) button communicates what the button will do if selected, or to acknowledge and dismiss the dialog. Check [variants](#variants) for the correct primary button styling. See also the [Alert Dialog design options](https://spectrum.adobe.com/page/alert-dialog/#Options).
7272

7373
```html
7474
<sp-alert-dialog
@@ -296,57 +296,103 @@ Destructive alert dialogs are for when a user needs to confirm an action that wi
296296

297297
#### Context
298298

299-
An alert dialog should be placed inside a modal overaly:
299+
An alert dialog should be placed inside a modal [overlay](../overlay/) or a [dialog base](../dialog-base/):
300+
301+
<sp-tabs selected="modal" auto label="Alert dialogs in context">
302+
<sp-tab value="modal">Modal overlay</sp-tab>
303+
<sp-tab-panel value="modal">
300304

301305
```html
302306
<sp-button id="trigger">open modal</sp-button>
303-
<sp-overlay trigger="trigger@click" type="modal">
304-
<sp-alert-dialog
305-
role="alertdialog"
306-
aria-labelledby="modal-heading"
307-
aria-describedby="modal-message"
308-
variant="confirmation"
309-
>
310-
<h2 id="modal-heading" slot="heading">Important Notice</h2>
311-
<p id="modal-message">This action requires your confirmation.</p>
312-
<sp-button
313-
slot="button"
314-
variant="secondary"
315-
treatment="outline"
316-
onclick="this.dispatchEvent(new Event('close', { bubbles: true, composed: true }));"
317-
>
318-
Cancel
319-
</sp-button>
320-
<sp-button
321-
slot="button"
322-
variant="accent"
323-
treatment="fill"
324-
onclick="this.dispatchEvent(new Event('close', { bubbles: true, composed: true }));"
307+
<sp-overlay trigger="trigger@click" type="modal" placement="bottom">
308+
<sp-popover>
309+
<sp-alert-dialog
310+
role="alertdialog"
311+
aria-labelledby="modal-heading"
312+
aria-describedby="modal-message"
313+
variant="confirmation"
325314
>
326-
Confirm
327-
</sp-button>
328-
</sp-alert-dialog>
315+
<h2 id="modal-heading" slot="heading">Important Notice</h2>
316+
<p id="modal-message">This action requires your confirmation.</p>
317+
<sp-button
318+
slot="button"
319+
variant="secondary"
320+
treatment="outline"
321+
onclick="this.dispatchEvent(new Event('close', { bubbles: true, composed: true }));"
322+
>
323+
Cancel
324+
</sp-button>
325+
<sp-button
326+
slot="button"
327+
variant="accent"
328+
treatment="fill"
329+
onclick="this.dispatchEvent(new Event('close', { bubbles: true, composed: true }));"
330+
>
331+
Confirm
332+
</sp-button>
333+
</sp-alert-dialog>
334+
</sp-popover>
329335
</sp-overlay>
330336
```
331337

338+
</sp-tab-panel>
339+
<sp-tab value="dialog">Dialog base</sp-tab>
340+
<sp-tab-panel value="dialog">
341+
342+
```html
343+
<overlay-trigger type="modal">
344+
<sp-dialog-base underlay slot="click-content">
345+
<sp-alert-dialog
346+
role="alertdialog"
347+
aria-labelledby="modal-heading"
348+
aria-describedby="modal-message"
349+
variant="confirmation"
350+
>
351+
<h2 id="modal-heading" slot="heading">Important Notice</h2>
352+
<p id="modal-message">This action requires your confirmation.</p>
353+
<sp-button
354+
slot="button"
355+
variant="secondary"
356+
treatment="outline"
357+
onclick="this.dispatchEvent(new Event('close', { bubbles: true, composed: true }));"
358+
>
359+
Cancel
360+
</sp-button>
361+
<sp-button
362+
slot="button"
363+
variant="accent"
364+
treatment="fill"
365+
onclick="this.dispatchEvent(new Event('close', { bubbles: true, composed: true }));"
366+
>
367+
Confirm
368+
</sp-button>
369+
</sp-alert-dialog>
370+
</sp-dialog-base>
371+
<sp-button slot="trigger" variant="primary">Toggle Dialog</sp-button>
372+
</overlay-trigger>
373+
```
374+
375+
</sp-tab-panel>
376+
</sp-tabs>
377+
332378
### Accessibility
333379

334380
#### `<sp-alert-banner>` Element
335381

336-
- Use `role="alertdialog"` on the alert dialog
337-
- Make sure the alert dialog has an `aria-labelledby` attribute that references the title's `id`.
338-
- Make sure the alert dialog has an `aria-describedby` attribute that references the content's `id`.
382+
- Use `role="alertdialog"` on the alert dialog
383+
- Make sure the alert dialog has an `aria-labelledby` attribute that references the title's `id`.
384+
- Make sure the alert dialog has an `aria-describedby` attribute that references the content's `id`.
339385

340386
#### Title
341387

342-
- Consider the appropriate variant based on the message's importance and urgency
343-
- Use concise, meaningful dialog title that clearly states the purpose
344-
- Use semantic heading elements (`<h2>`) for the dialog title
388+
- Consider the appropriate variant based on the message's importance and urgency
389+
- Use concise, meaningful dialog title that clearly states the purpose
390+
- Use semantic heading elements (`<h2>`) for the dialog title
345391

346392
#### Content
347393

348-
- Provide clear, concise content that explains the situation and required actions
394+
- Provide clear, concise content that explains the situation and required actions
349395

350396
####Buttons
351397

352-
- Ensure button labels clearly indicate the action they will perform
398+
- Ensure button labels clearly indicate the action they will perform

0 commit comments

Comments
 (0)