Skip to content

Commit 8ed9fa8

Browse files
docs(tray): add tray docs with visually hidden dismiss
1 parent 209eedd commit 8ed9fa8

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

packages/tray/README.md

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
[![See it on NPM!](https://img.shields.io/npm/v/@spectrum-web-components/tray?style=for-the-badge)](https://www.npmjs.com/package/@spectrum-web-components/tray)
88
[![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/tray?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/tray)
99

10-
```
10+
```bash
1111
yarn add @spectrum-web-components/tray
1212
```
1313

1414
Import the side effectful registration of `<sp-tray>` via:
1515

16-
```
16+
```js
1717
import '@spectrum-web-components/tray/sp-tray.js';
1818
```
1919

2020
When looking to leverage the `Tray` base class as a type and/or for extension purposes, do so via:
2121

22-
```
22+
```js
2323
import { Tray } from '@spectrum-web-components/tray';
2424
```
2525

@@ -70,3 +70,57 @@ A tray has a single default `slot`.
7070
### Accessibility
7171

7272
`<sp-tray>` presents a page blocking experience and should be opened with the `Overlay` API using the `modal` interaction to ensure that the content appropriately manages the presence of other content in the tab order of the page and the availability of that content for a screen reader.
73+
74+
#### Mobile screen reader support
75+
76+
The `<sp-tray>` component automatically includes visually hidden dismiss buttons before and after its content to support mobile screen readers. This is particularly important for VoiceOver on iOS, where users navigate through interactive elements sequentially.
77+
78+
These built-in dismiss buttons:
79+
80+
- Are visually hidden but accessible to screen readers
81+
- Use `tabindex="-1"` to prevent keyboard tab navigation interference
82+
- Allow mobile screen reader users to easily dismiss the tray from either the beginning or end of the content
83+
- Are labeled "Dismiss" for clear screen reader announcements
84+
85+
This dismiss helper pattern is also implemented in the [`<sp-picker>`](https://opensource.adobe.com/spectrum-web-components/components/picker/) component, which uses the same approach when rendering menu content in a tray on mobile devices.
86+
87+
<sp-tabs selected="menu" auto label="Tray content examples">
88+
<sp-tab value="menu">Menu</sp-tab>
89+
<sp-tab-panel value="menu">
90+
91+
Simply place your menu content inside the tray - the dismiss buttons are automatically rendered:
92+
93+
```html
94+
<overlay-trigger type="modal">
95+
<sp-button slot="trigger" variant="secondary">Toggle menu</sp-button>
96+
<sp-tray slot="click-content">
97+
<sp-menu style="width: 100%">
98+
<sp-menu-item>Deselect</sp-menu-item>
99+
<sp-menu-item>Select Inverse</sp-menu-item>
100+
<sp-menu-item>Feather...</sp-menu-item>
101+
<sp-menu-item>Select and Mask...</sp-menu-item>
102+
</sp-menu>
103+
</sp-tray>
104+
</overlay-trigger>
105+
```
106+
107+
</sp-tab-panel>
108+
<sp-tab value="dialog">Dialog</sp-tab>
109+
<sp-tab-panel value="dialog">
110+
111+
When using `<sp-dialog>` with the `dismissable` attribute inside a tray, both the tray's built-in dismiss helpers and the dialog's dismiss button work together to provide multiple accessible ways to close the overlay:
112+
113+
```html
114+
<overlay-trigger type="modal">
115+
<sp-button slot="trigger" variant="secondary">Toggle tray</sp-button>
116+
<sp-tray slot="click-content">
117+
<sp-dialog size="s" dismissable>
118+
<h2 slot="heading">New messages</h2>
119+
You have 5 new messages.
120+
</sp-dialog>
121+
</sp-tray>
122+
</overlay-trigger>
123+
```
124+
125+
</sp-tab-panel>
126+
</sp-tabs>

0 commit comments

Comments
 (0)