-
Notifications
You must be signed in to change notification settings - Fork 235
fix(tray): add visually hidden dismiss buttons #5814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
790cfdb
209eedd
7fecbc7
be0a5e6
26d42d2
225faf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,6 +125,7 @@ export class DialogWrapper extends DialogBase { | |
} | ||
|
||
return html` | ||
${this.dismissHelper} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first dismissHelper is always shown, regardless of The one at the end of this render function is conditional, so that at most a dialog would only have 2 options for dismissal- a visible close button, and a visually-hidden one for screen readers. Is that still too redundant for screen readers users when |
||
<sp-dialog | ||
?dismissable=${this.dismissable} | ||
dismiss-label=${this.dismissLabel} | ||
|
@@ -199,6 +200,7 @@ export class DialogWrapper extends DialogBase { | |
` | ||
: nothing} | ||
</sp-dialog> | ||
${!this.dismissable ? this.dismissHelper : nothing} | ||
`; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,16 @@ | |
.modal { | ||
overflow: visible; | ||
} | ||
|
||
.visually-hidden { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to add the visually hidden styles to modal because I couldn't get the styles through the shadow DOM when these were in dialog.css/spectrum-dialog.css. |
||
border: 0; | ||
clip: rect(0, 0, 0, 0); | ||
clip-path: inset(50%); | ||
height: 1px; | ||
margin: 0 -1px -1px 0; | ||
overflow: hidden; | ||
padding: 0; | ||
position: absolute; | ||
width: 1px; | ||
white-space: nowrap; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,19 +7,19 @@ | |
[](https://www.npmjs.com/package/@spectrum-web-components/tray) | ||
[](https://bundlephobia.com/result?p=@spectrum-web-components/tray) | ||
|
||
``` | ||
```bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be |
||
yarn add @spectrum-web-components/tray | ||
``` | ||
|
||
Import the side effectful registration of `<sp-tray>` via: | ||
|
||
``` | ||
```js | ||
import '@spectrum-web-components/tray/sp-tray.js'; | ||
``` | ||
|
||
When looking to leverage the `Tray` base class as a type and/or for extension purposes, do so via: | ||
|
||
``` | ||
```js | ||
import { Tray } from '@spectrum-web-components/tray'; | ||
``` | ||
|
||
|
@@ -70,3 +70,46 @@ A tray has a single default `slot`. | |
### Accessibility | ||
|
||
`<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. | ||
|
||
#### Mobile screen reader support | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we like how this additional documentation sounds, want me to add it to the dialog-wrapper docs as well? |
||
|
||
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. | ||
|
||
These built-in dismiss buttons: | ||
|
||
- Are visually hidden but accessible to screen readers | ||
- Use `tabindex="-1"` to prevent keyboard tab navigation interference | ||
- Allow mobile screen reader users to easily dismiss the tray from either the beginning or end of the content | ||
- Are labeled "Dismiss" for clear screen reader announcements | ||
|
||
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. | ||
|
||
Simply place your content inside the tray - the dismiss buttons are automatically rendered: | ||
|
||
```html | ||
<overlay-trigger type="modal"> | ||
<sp-button slot="trigger" variant="secondary"> | ||
Toggle menu content | ||
</sp-button> | ||
<sp-tray slot="click-content"> | ||
<sp-menu style="width: 100%"> | ||
<sp-menu-item>Deselect</sp-menu-item> | ||
<sp-menu-item>Select Inverse</sp-menu-item> | ||
<sp-menu-item>Feather...</sp-menu-item> | ||
<sp-menu-item>Select and Mask...</sp-menu-item> | ||
</sp-menu> | ||
</sp-tray> | ||
</overlay-trigger> | ||
|
||
<overlay-trigger type="modal"> | ||
<sp-button slot="trigger" variant="secondary"> | ||
Toggle dialog content | ||
</sp-button> | ||
<sp-tray slot="click-content"> | ||
<sp-dialog size="s"> | ||
<h2 slot="heading">New messages</h2> | ||
You have 5 new messages. | ||
</sp-dialog> | ||
</sp-tray> | ||
</overlay-trigger> | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added dismissHelper here because
sp-dialog-wrapper
extendssp-dialog-base
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up: we might elect to change this to a full-fledged
sp-close-button
that is visually hidden, instead of a plain ol' button tag.