Skip to content

Commit 542fb4d

Browse files
docs(tray): update README with new properties/examples
1 parent 5d1e987 commit 542fb4d

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

packages/tray/README.md

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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-
```bash
10+
```zsh
1111
yarn add @spectrum-web-components/tray
1212
```
1313

@@ -71,9 +71,9 @@ A tray has a single default `slot`.
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.
7373

74-
#### Mobile screen reader support
74+
#### Auto-detection behavior
7575

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.
76+
By default, `<sp-tray>` automatically detects whether its slotted content includes keyboard-accessible dismiss buttons (like `<sp-button>`, `<sp-close-button>`, or HTML `<button>` elements). When no dismiss buttons are found, the tray renders visually hidden dismiss buttons before and after its content to support mobile screen readers, particularly VoiceOver on iOS where users navigate through interactive elements sequentially.
7777

7878
These built-in dismiss buttons:
7979

@@ -84,7 +84,11 @@ These built-in dismiss buttons:
8484

8585
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.
8686

87-
Simply place your content inside the tray - the dismiss buttons are automatically rendered:
87+
<sp-tabs selected="auto" auto label="Dismiss helper examples">
88+
<sp-tab value="auto">Content has no buttons</sp-tab>
89+
<sp-tab-panel value="auto">
90+
91+
This example shows the default behavior where the tray automatically detects that the menu content lacks dismiss buttons and renders visually hidden helpers. Screen readers will announce them as "Dismiss, button."
8892

8993
```html
9094
<overlay-trigger type="modal">
@@ -100,16 +104,47 @@ Simply place your content inside the tray - the dismiss buttons are automaticall
100104
</sp-menu>
101105
</sp-tray>
102106
</overlay-trigger>
107+
```
108+
109+
</sp-tab-panel>
110+
<sp-tab value="with-buttons">Content has buttons</sp-tab>
111+
<sp-tab-panel value="with-buttons">
112+
113+
This example shows auto-detection recognizing that the dialog has its own dismiss functionality, so no additional helpers are rendered.
103114

115+
```html
104116
<overlay-trigger type="modal">
105117
<sp-button slot="trigger" variant="secondary">
106118
Toggle dialog content
107119
</sp-button>
108120
<sp-tray slot="click-content">
109-
<sp-dialog size="s">
121+
<sp-dialog size="s" dismissable>
110122
<h2 slot="heading">New messages</h2>
111123
You have 5 new messages.
112124
</sp-dialog>
113125
</sp-tray>
114126
</overlay-trigger>
115127
```
128+
129+
</sp-tab-panel>
130+
<sp-tab value="force-hide">Manual override</sp-tab>
131+
<sp-tab-panel value="force-hide">
132+
133+
Set `has-keyboard-dismiss` (or `has-keyboard-dismiss="true"`) to prevent the tray from rendering visually hidden dismiss helpers, even when no buttons are detected. You are then responsible for ensuring that your tray content has keyboard-accessible dismiss functionality.
134+
135+
```html
136+
<overlay-trigger type="modal">
137+
<sp-button slot="trigger" variant="secondary">
138+
Toggle without helpers
139+
</sp-button>
140+
<sp-tray slot="click-content" has-keyboard-dismiss>
141+
<p>
142+
Custom content that should have custom dismiss functionality, even
143+
though the tray didn't detect buttons in this slot.
144+
</p>
145+
</sp-tray>
146+
</overlay-trigger>
147+
```
148+
149+
</sp-tab-panel>
150+
</sp-tabs>

0 commit comments

Comments
 (0)