Skip to content

Commit 508cd5a

Browse files
committed
Fixes keyboard a11y on home branch actions
1 parent 25474ce commit 508cd5a

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

src/webviews/apps/plus/home/components/branch-section.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { when } from 'lit/directives/when.js';
44
import type { Commands } from '../../../../../constants.commands';
55
import type { GitTrackingState } from '../../../../../git/models/branch';
66
import type { GetOverviewBranch } from '../../../../home/protocol';
7+
import { srOnlyStyles } from '../../../shared/components/styles/lit/a11y.css';
78
import '../../../shared/components/code-icon';
89
import '../../../shared/components/avatar/avatar';
910
import '../../../shared/components/avatar/avatar-list';
@@ -173,7 +174,7 @@ export const branchCardStyles = css`
173174
}
174175
175176
.branch-item:not(:focus-within):not(:hover) .branch-item__actions {
176-
display: none;
177+
${srOnlyStyles}
177178
}
178179
179180
.pill {

src/webviews/apps/shared/components/actions/action-item.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { css, html, LitElement, nothing } from 'lit';
2-
import { customElement, property } from 'lit/decorators.js';
2+
import { customElement, property, query } from 'lit/decorators.js';
3+
import { focusOutline } from '../styles/lit/a11y.css';
34
import '../overlays/tooltip';
45
import '../code-icon';
56

67
@customElement('action-item')
78
export class ActionItem extends LitElement {
9+
static override shadowRootOptions: ShadowRootInit = {
10+
...LitElement.shadowRootOptions,
11+
delegatesFocus: true,
12+
};
13+
814
static override styles = css`
915
:host {
1016
box-sizing: border-box;
@@ -21,9 +27,8 @@ export class ActionItem extends LitElement {
2127
cursor: pointer;
2228
}
2329
24-
:host(:focus) {
25-
outline: 1px solid var(--vscode-focusBorder);
26-
outline-offset: -1px;
30+
:host(:focus-within) {
31+
${focusOutline}
2732
}
2833
2934
:host(:hover) {
@@ -42,6 +47,9 @@ export class ActionItem extends LitElement {
4247
a {
4348
color: inherit;
4449
}
50+
a:focus {
51+
outline: none;
52+
}
4553
`;
4654

4755
@property()
@@ -56,6 +64,9 @@ export class ActionItem extends LitElement {
5664
@property({ type: Boolean })
5765
disabled = false;
5866

67+
@query('a')
68+
private defaultFocusEl!: HTMLAnchorElement;
69+
5970
override render() {
6071
return html`
6172
<gl-tooltip hoist content="${this.label ?? nothing}">
@@ -71,4 +82,8 @@ export class ActionItem extends LitElement {
7182
</gl-tooltip>
7283
`;
7384
}
85+
86+
override focus(options?: FocusOptions) {
87+
this.defaultFocusEl.focus(options);
88+
}
7489
}

src/webviews/apps/shared/components/styles/lit/a11y.css.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { css } from 'lit';
22

3+
export const srOnlyStyles = css`
4+
clip: rect(0 0 0 0);
5+
clip-path: inset(50%);
6+
width: 1px;
7+
height: 1px;
8+
overflow: hidden;
9+
position: absolute;
10+
white-space: nowrap;
11+
`;
12+
313
export const srOnly = css`
414
.sr-only,
5-
.sr-only-focusable:not(:active):not(:focus) {
6-
clip: rect(0 0 0 0);
7-
clip-path: inset(50%);
8-
width: 1px;
9-
height: 1px;
10-
overflow: hidden;
11-
position: absolute;
12-
white-space: nowrap;
15+
.sr-only-focusable:not(:active):not(:focus):not(:focus-within) {
16+
${srOnlyStyles}
1317
}
1418
`;
1519

0 commit comments

Comments
 (0)