Skip to content

Commit a8be2ba

Browse files
docs(tray): update README with new properties/examples
1 parent 43a466e commit a8be2ba

File tree

1 file changed

+59
-4
lines changed

1 file changed

+59
-4
lines changed

packages/tray/README.md

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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">Auto-detection (default)</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,67 @@ 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">`has-keyboard-dismiss="true"`</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. This tells the tray that your content already 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="true">
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-tab value="force-show">`has-keyboard-dismiss="false"`</sp-tab>
151+
<sp-tab-panel value="force-show">
152+
153+
Use `has-keyboard-dismiss="false"` to force the tray to always render visually hidden dismiss helpers, even when buttons are detected in the content:
154+
155+
```html
156+
<overlay-trigger type="modal">
157+
<sp-button slot="trigger" variant="secondary">
158+
Toggle with forced helpers
159+
</sp-button>
160+
<sp-tray slot="click-content" has-keyboard-dismiss="false">
161+
<sp-dialog size="s" dismissable>
162+
<h2 slot="heading">Settings</h2>
163+
<sp-button slot="button">Save</sp-button>
164+
</sp-dialog>
165+
</sp-tray>
166+
</overlay-trigger>
167+
```
168+
169+
</sp-tab-panel>
170+
</sp-tabs>

0 commit comments

Comments
 (0)