Skip to content

Commit 4d6bcb3

Browse files
authored
a11y improvements for gists (#576)
- MWC now requires `aria-label` instead of `label` - Don't close flyout when clicking buttons with keyboard (bugfix) - Recover from not being allowed to write to clipboard (actually just affects Safari generally) Part of #533
1 parent 205f372 commit 4d6bcb3

File tree

7 files changed

+36
-14
lines changed

7 files changed

+36
-14
lines changed

packages/lit-dev-content/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default [
9595
// We compile them separately here because they include imports for a small
9696
// amount of code that we want to inline directly (again, because we want to
9797
// execute immediately), even though that code is technically duplicated into
98-
// the asyncronously-loaded module bundles above.
98+
// the asynchronously-loaded module bundles above.
9999
{
100100
input: [
101101
'lib/global/apply-mods.js',

packages/lit-dev-content/src/components/copy-button.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class CopyButton extends LitElement {
2828
return html`<mwc-icon-button
2929
outlined
3030
@click=${this._click}
31-
label="Copy to clipboard"
31+
aria-label="Copy to clipboard"
3232
>
3333
${copyIcon}
3434
</mwc-icon-button>`;

packages/lit-dev-content/src/components/litdev-drawer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class LitDevDrawer extends LitElement {
112112
113113
<mwc-icon-button-toggle
114114
id="openCloseButton"
115-
label="Open or close examples drawer"
115+
aria-label="Open or close examples drawer"
116116
.on=${!this.open}
117117
@click=${this._onClickToggleButton}
118118
>

packages/lit-dev-content/src/components/litdev-flyout.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ export class LitDevFlyout extends LitElement {
121121
// Defer a microtask so that the click that opened this flyout won't cause
122122
// it to close.
123123
if (this.open) {
124-
window.addEventListener('click', this._onWindowClick);
124+
window.addEventListener('mouseup', this._onWindowMouseup);
125125
}
126126
});
127127
}
128128

129129
private _removeEventListeners() {
130130
window.removeEventListener('keydown', this._onWindowKeydown);
131131
this.removeEventListener('mousedown', this._onThisMousedown);
132-
window.removeEventListener('click', this._onWindowClick);
132+
window.removeEventListener('mouseup', this._onWindowMouseup);
133133
}
134134

135135
private _clickStartedWithinThis = false;
@@ -143,7 +143,7 @@ export class LitDevFlyout extends LitElement {
143143
this._clickStartedWithinThis = true;
144144
};
145145

146-
private readonly _onWindowClick = () => {
146+
private readonly _onWindowMouseup = () => {
147147
if (this._clickStartedWithinThis) {
148148
this._clickStartedWithinThis = false;
149149
} else {

packages/lit-dev-content/src/components/litdev-playground-share-gist.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,20 @@ export class LitDevPlaygroundShareGist extends LitElement {
289289
});
290290

291291
window.location.hash = '#gist=' + gist.id;
292-
await navigator.clipboard.writeText(window.location.toString());
292+
let statusText = 'Gist created';
293+
try {
294+
await navigator.clipboard.writeText(window.location.toString());
295+
statusText += ' and URL copied to clipboard';
296+
} catch {
297+
// The browser isn't allowing us to copy. This could happen because it's
298+
// disabled in settings, or because we're in a browser like Safari that
299+
// only allows copying from a synchronous event handler.
300+
statusText += ' and URL bar updated';
301+
}
293302
this.dispatchEvent(new Event('created'));
294303
this.dispatchEvent(
295304
new CustomEvent('status', {
296-
detail: {text: 'Gist created and URL copied to clipboard'},
305+
detail: {text: statusText},
297306
bubbles: true,
298307
})
299308
);
@@ -350,11 +359,15 @@ export class LitDevPlaygroundShareGist extends LitElement {
350359
});
351360

352361
window.location.hash = '#gist=' + gist.id;
353-
await navigator.clipboard.writeText(window.location.toString());
362+
let statusText = 'Gist updated';
363+
try {
364+
await navigator.clipboard.writeText(window.location.toString());
365+
statusText += ' and URL copied to clipboard';
366+
} catch {}
354367
this.dispatchEvent(new Event('created'));
355368
this.dispatchEvent(
356369
new CustomEvent('status', {
357-
detail: {text: 'Gist updated and URL copied to clipboard'},
370+
detail: {text: statusText},
358371
bubbles: true,
359372
})
360373
);

packages/lit-dev-content/src/components/litdev-playground-share-long-url.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,20 @@ export class LitDevPlaygroundShareLongUrl extends LitElement {
7777

7878
async save() {
7979
history.pushState({}, '', this._url);
80-
await navigator.clipboard.writeText(this._url);
80+
let statusText;
81+
try {
82+
await navigator.clipboard.writeText(window.location.toString());
83+
statusText = 'URL copied to clipboard';
84+
} catch {
85+
// The browser isn't allowing us to copy. This could happen because it's
86+
// disabled in settings, or because we're in a browser like Safari that
87+
// only allows copying from a synchronous event handler.
88+
statusText += 'URL bar updated';
89+
}
8190
this.dispatchEvent(new Event('copied'));
8291
this.dispatchEvent(
8392
new CustomEvent('status', {
84-
detail: {text: 'URL copied to clipboard'},
93+
detail: {text: statusText},
8594
bubbles: true,
8695
})
8796
);

packages/lit-dev-content/src/components/litdev-tutorial.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class LitDevTutorial extends LitElement {
9191
<nav>
9292
<mwc-icon-button
9393
id="prevButton"
94-
label="Previous step"
94+
aria-label="Previous step"
9595
.disabled=${this._idx <= 0}
9696
@click=${this._onClickPrevButton}
9797
>
@@ -105,7 +105,7 @@ export class LitDevTutorial extends LitElement {
105105
106106
<mwc-icon-button
107107
id="nextButton"
108-
label="Next step"
108+
aria-label="Next step"
109109
.disabled=${this._idx >= manifest.steps.length - 1}
110110
@click=${this._onClickNextButton}
111111
>

0 commit comments

Comments
 (0)