Skip to content

Commit 642619c

Browse files
feat(dialog): add dismissHelper and visually-hidden buttons
1 parent b033a69 commit 642619c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

packages/dialog/src/Dialog.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,26 @@ export class Dialog extends ObserveSlotPresence(AlertDialog, [
134134
`;
135135
}
136136

137+
/**
138+
* Returns a visually hidden dismiss button for mobile screen reader accessibility.
139+
* This button is placed before and after dialog content to allow mobile screen reader
140+
* users (particularly VoiceOver on iOS) to easily dismiss the overlay.
141+
*/
142+
protected get dismissHelper(): TemplateResult {
143+
return html`
144+
<div class="visually-hidden">
145+
<button
146+
tabindex="-1"
147+
aria-label="Dismiss"
148+
@click=${this.close}
149+
></button>
150+
</div>
151+
`;
152+
}
153+
137154
protected override render(): TemplateResult {
138155
return html`
156+
${this.dismissHelper}
139157
<div class="grid">
140158
${this.renderHero()} ${this.renderHeading()}
141159
${this.error
@@ -153,6 +171,7 @@ export class Dialog extends ObserveSlotPresence(AlertDialog, [
153171
${this.hasButtons ? this.renderButtons() : nothing}
154172
${this.dismissable ? this.renderDismiss() : nothing}
155173
</div>
174+
${this.dismissHelper}
156175
`;
157176
}
158177

packages/dialog/src/dialog.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,17 @@
6666
inline-size: 100%;
6767
display: grid;
6868
}
69+
70+
.visually-hidden {
71+
border: 0;
72+
clip: rect(0, 0, 0, 0);
73+
clip-path: inset(50%);
74+
height: 10px;
75+
margin: 0 -1px -1px 0;
76+
overflow: hidden;
77+
padding: 0;
78+
position: absolute;
79+
width: 10px;
80+
white-space: nowrap;
81+
appearance: none;
82+
}

0 commit comments

Comments
 (0)