Skip to content

Commit cd1ab2f

Browse files
authored
docs(dialog): updated dialog docs for accessbility (#5411)
1 parent 2ce369b commit cd1ab2f

File tree

5 files changed

+603
-97
lines changed

5 files changed

+603
-97
lines changed

packages/dialog/README.md

Lines changed: 105 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,59 @@
1-
## Description
1+
## Overview
22

33
`sp-dialog` displays important information that users need to acknowledge. They appear over the interface and block further interactions. When used directly the `sp-dialog` element surfaces a `slot` based API for deep customization of the content to be included in the overlay.
44

5+
Note: the `sp-dialog` element is a component that is used to create a dialog layout. For modal and popover behavior, it should be used within a component that manages the overlay state.
6+
57
### Usage
68

79
[![See it on NPM!](https://img.shields.io/npm/v/@spectrum-web-components/dialog?style=for-the-badge)](https://www.npmjs.com/package/@spectrum-web-components/dialog)
810
[![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/dialog?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/dialog)
911
[![Try it on webcomponents.dev](https://img.shields.io/badge/Try%20it%20on-webcomponents.dev-green?style=for-the-badge)](https://webcomponents.dev/edit/collection/fO75441E1Q5ZlI0e9pgq/RSDikStPmUPSioVpCsYb/src/index.ts)
1012

11-
```
13+
```bash
1214
yarn add @spectrum-web-components/dialog
1315
```
1416

1517
Import the side effectful registration of `<sp-dialog>` via:
1618

17-
```
19+
```ts
1820
import '@spectrum-web-components/dialog/sp-dialog.js';
1921
```
2022

2123
When looking to leverage the `Dialog` base class as a type and/or for extension purposes, do so via:
2224

23-
```
25+
```ts
2426
import { Dialog } from '@spectrum-web-components/dialog';
2527
```
2628

27-
## Sizes
29+
### Anatomy
30+
31+
The dialog consists of several key parts:
32+
33+
- A heading (via `slot="heading"`)
34+
- Content (via default slot)
35+
- Optional hero content (via `slot="hero"`)
36+
- Optional buttons (via `slot="button"`)
37+
- Optional footer content (via `slot="footer"`)
38+
- Optional dismiss button (via `dismissable` attribute)
39+
40+
```html
41+
<sp-dialog size="s">
42+
<div
43+
slot="hero"
44+
style="background-image: url(https://picsum.photos/1400/260)"
45+
></div>
46+
<h2 slot="heading">Disclaimer</h2>
47+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
48+
tempor incididunt ut labore et dolore magna aliqua.
49+
<div slot="footer">Footer information</div>
50+
<sp-button slot="button">Button</sp-button>
51+
</sp-dialog>
52+
```
53+
54+
### Options
55+
56+
#### Sizes
2857

2958
<sp-tabs selected="m" auto label="Size Attribute Options">
3059
<sp-tab value="s">Small</sp-tab>
@@ -89,16 +118,14 @@ import { Dialog } from '@spectrum-web-components/dialog';
89118
</sp-tab-panel>
90119
</sp-tabs>
91120

92-
## Variants
93-
94-
### Dismissable
121+
#### Dismissable
95122

96123
When supplied with the `dissmissable` attribute an `<sp-dialog>` element will surface a "close" button afordance that will dispatch a DOM event with the name of `close` when pressed.
97124

98125
Note: the `dissmissable` attribute will not be followed when `mode="fullscreen"` or `mode="fullscreenTakeover"` are applies in accordance with the Spectrum specification.
99126

100127
```html
101-
<sp-dialog size="m" dismissable>
128+
<sp-dialog dismissable>
102129
<h2 slot="heading">Disclaimer</h2>
103130
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
104131
tempor incididunt ut labore et dolore magna aliqua. Auctor augue mauris
@@ -113,10 +140,10 @@ Note: the `dissmissable` attribute will not be followed when `mode="fullscreen"`
113140
</sp-dialog>
114141
```
115142

116-
### No Divider
143+
#### No Divider
117144

118145
```html
119-
<sp-dialog size="m" dismissable no-divider>
146+
<sp-dialog dismissable no-divider>
120147
<h2 slot="heading">Disclaimer</h2>
121148
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
122149
tempor incididunt ut labore et dolore magna aliqua. Auctor augue mauris
@@ -131,24 +158,73 @@ Note: the `dissmissable` attribute will not be followed when `mode="fullscreen"`
131158
</sp-dialog>
132159
```
133160

134-
### Hero
161+
### Behaviors
162+
163+
Use the dialog with an overlay to create a dialog that appears over the current page. The dialog manages several behaviors:
164+
165+
1. Animation of the dialog content when opening/closing
166+
2. Focus management when the dialog opens
167+
3. Event handling for closing the dialog
135168

136169
```html
137-
<sp-dialog size="medium" dismissable no-divider>
138-
<div
139-
slot="hero"
140-
style="background-image: url(https://picsum.photos/1400/260)"
141-
></div>
142-
<h2 slot="heading">Disclaimer</h2>
143-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
144-
tempor incididunt ut labore et dolore magna aliqua. Auctor augue mauris
145-
augue neque gravida. Libero volutpat sed ornare arcu. Quisque egestas diam
146-
in arcu cursus euismod quis viverra. Posuere ac ut consequat semper viverra
147-
nam libero justo laoreet. Enim ut tellus elementum sagittis vitae et leo
148-
duis ut. Neque laoreet suspendisse interdum consectetur libero id faucibus
149-
nisl. Diam volutpat commodo sed egestas egestas. Dolor magna eget est lorem
150-
ipsum dolor. Vitae suscipit tellus mauris a diam maecenas sed. Turpis in eu
151-
mi bibendum neque egestas congue. Rhoncus est pellentesque elit ullamcorper
152-
dignissim cras lobortis.
153-
</sp-dialog>
170+
<sp-button id="trigger">Overlay Trigger</sp-button>
171+
<sp-overlay trigger="trigger@click" placement="bottom">
172+
<sp-popover>
173+
<sp-dialog>
174+
<h2 slot="heading">Overlay 1</h2>
175+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
176+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Auctor
177+
augue mauris augue neque gravida. Libero volutpat sed ornare arcu.
178+
</sp-dialog>
179+
</sp-popover>
180+
</sp-overlay>
181+
<overlay-trigger placement="top" type="replace">
182+
<sp-button slot="trigger">Overlay Trigger 2</sp-button>
183+
<sp-popover slot="click-content" open>
184+
<sp-dialog size="s">
185+
<h2 slot="heading">Overlay 2</h2>
186+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
187+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Auctor
188+
augue mauris augue neque gravida. Libero volutpat sed ornare arcu.
189+
<sp-button
190+
slot="button"
191+
onclick="javascript: this.dispatchEvent(new Event('close', {bubbles: true, composed: true}));"
192+
>
193+
I understand
194+
</sp-button>
195+
</sp-dialog>
196+
</sp-popover>
197+
</overlay-trigger>
198+
```
199+
200+
#### Receives focus
201+
202+
The `receives-focus` attribute can be used to control whether the dialog should receive focus when it is opened. Leverage the `type="modal"` and `receives-focus="auto"` settings in the Overlay API to ensure that focus is thrown into the dialog content when opened and that the tab order will be trapped within it while open.
203+
204+
The `receives-focus` attribute on `overlay-trigger` has three possible values:
205+
206+
- `auto` (default): Focus will automatically move to the first focusable element in the dialog
207+
- `true`: Forces focus to move to the overlay content
208+
- `false`: Prevents focus from moving to the overlay
209+
210+
For accessible dialogs, always use `receives-focus="auto"` or `receives-focus="true"` to ensure keyboard users can interact with the dialog content.
211+
212+
```html
213+
<sp-button id="focus">Overlay Trigger</sp-button>
214+
<sp-overlay trigger="focus@click" type="modal" receives-focus="auto">
215+
<sp-popover>
216+
<sp-dialog>
217+
<h2 slot="heading">Dialog Heading</h2>
218+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
219+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Auctor
220+
augue mauris augue neque gravida. Libero volutpat sed ornare arcu.
221+
</sp-dialog>
222+
</sp-popover>
223+
</sp-overlay>
154224
```
225+
226+
### Accessibility
227+
228+
#### Include a heading
229+
230+
The `heading` slot is of the `sp-dialog` dialog element is used to label the dialog content for screen readers.

0 commit comments

Comments
 (0)