|
7 | 7 | [](https://www.npmjs.com/package/@spectrum-web-components/tray) |
8 | 8 | [](https://bundlephobia.com/result?p=@spectrum-web-components/tray) |
9 | 9 |
|
10 | | -``` |
| 10 | +```bash |
11 | 11 | yarn add @spectrum-web-components/tray |
12 | 12 | ``` |
13 | 13 |
|
14 | 14 | Import the side effectful registration of `<sp-tray>` via: |
15 | 15 |
|
16 | | -``` |
| 16 | +```js |
17 | 17 | import '@spectrum-web-components/tray/sp-tray.js'; |
18 | 18 | ``` |
19 | 19 |
|
20 | 20 | When looking to leverage the `Tray` base class as a type and/or for extension purposes, do so via: |
21 | 21 |
|
22 | | -``` |
| 22 | +```js |
23 | 23 | import { Tray } from '@spectrum-web-components/tray'; |
24 | 24 | ``` |
25 | 25 |
|
@@ -70,3 +70,57 @@ A tray has a single default `slot`. |
70 | 70 | ### Accessibility |
71 | 71 |
|
72 | 72 | `<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