Skip to content

Commit df955ed

Browse files
committed
Updates focus styles
1 parent 321f526 commit df955ed

File tree

6 files changed

+50
-14
lines changed

6 files changed

+50
-14
lines changed

src/webviews/apps/plus/shared/components/account-chip.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { pluralize } from '../../../../../system/string';
1616
import type { State } from '../../../../home/protocol';
1717
import { stateContext } from '../../../home/context';
1818
import type { GlPopover } from '../../../shared/components/overlays/popover';
19+
import { focusableBaseStyles } from '../../../shared/components/styles/lit/a11y.css';
1920
import { elementBase, linkBase } from '../../../shared/components/styles/lit/base.css';
2021
import type { PromosContext } from '../../../shared/contexts/promos';
2122
import { promosContext } from '../../../shared/contexts/promos';
@@ -35,6 +36,7 @@ export class GLAccountChip extends LitElement {
3536
static override styles = [
3637
elementBase,
3738
linkBase,
39+
focusableBaseStyles,
3840
chipStyles,
3941
css`
4042
.chip {

src/webviews/apps/plus/shared/components/chipStyles.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { css } from 'lit';
2+
import { focusOutline } from '../../../shared/components/styles/lit/a11y.css';
23

34
export const chipStyles = css`
45
:host {
@@ -15,9 +16,8 @@ export const chipStyles = css`
1516
cursor: pointer;
1617
}
1718
18-
.chip:focus,
19-
.chip:focus-within {
20-
outline: 1px solid var(--vscode-focusBorder);
19+
.chip:focus-visible {
20+
${focusOutline}
2121
}
2222
2323
.content {

src/webviews/apps/plus/shared/components/vscode.css.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ export const linkStyles = css`
88
outline: none;
99
text-decoration: var(--link-decoration-default, none);
1010
}
11-
a:focus,
11+
1212
a:focus-visible {
13-
outline-color: var(--color-focus-border);
14-
outline-style: solid;
15-
outline-width: 1px;
13+
outline: 1px solid var(--color-focus-border);
1614
border-radius: 0.2rem;
1715
}
16+
1817
a:hover {
1918
color: var(--link-foreground-active);
2019
text-decoration: underline;

src/webviews/apps/shared/components/feature-badge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class GlFeatureBadge extends LitElement {
6161
white-space: nowrap;
6262
}
6363
64-
.badge:focus {
64+
.badge:focus-visible {
6565
${unsafeCSS(focusOutline)}
6666
}
6767

src/webviews/apps/shared/components/promo.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
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';
33
import { ifDefined } from 'lit/directives/if-defined.js';
44
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
55
import { until } from 'lit/directives/until.js';
66
import type { GlCommands } from '../../../../constants.commands';
77
import type { Source } from '../../../../constants.telemetry';
88
import type { Promo } from '../../../../plus/gk/models/promo';
99
import { createCommandLink } from '../../../../system/commands';
10+
import { focusOutline } from './styles/lit/a11y.css';
1011

1112
@customElement('gl-promo')
1213
export class GlPromo extends LitElement {
14+
static override shadowRootOptions: ShadowRootInit = {
15+
...LitElement.shadowRootOptions,
16+
delegatesFocus: true,
17+
};
18+
1319
static override styles = [
1420
css`
1521
:host {
@@ -45,13 +51,20 @@ export class GlPromo extends LitElement {
4551
white-space: nowrap;
4652
}
4753
54+
.link:focus-visible {
55+
${focusOutline}
56+
}
57+
4858
.link:hover {
4959
color: inherit;
5060
text-decoration: underline;
5161
}
5262
`,
5363
];
5464

65+
@query('a,button,[tabindex="0"]')
66+
private _focusable?: HTMLElement;
67+
5568
@property({ type: Object })
5669
promoPromise!: Promise<Promo | undefined>;
5770

@@ -61,6 +74,15 @@ export class GlPromo extends LitElement {
6174
@property({ reflect: true, type: String })
6275
type: 'link' | 'info' = 'info';
6376

77+
private _hasPromo = false;
78+
@property({ type: Boolean, reflect: true, attribute: 'has-promo' })
79+
get hasPromo() {
80+
return this._hasPromo;
81+
}
82+
private set hasPromo(value: boolean) {
83+
this._hasPromo = value;
84+
}
85+
6486
override render(): unknown {
6587
return html`${until(
6688
this.promoPromise.then(promo => this.renderPromo(promo)),
@@ -69,20 +91,23 @@ export class GlPromo extends LitElement {
6991
}
7092

7193
private renderPromo(promo: Promo | undefined) {
72-
if (!promo?.content?.webview) return;
94+
if (!promo?.content?.webview) {
95+
this.hasPromo = false;
96+
return;
97+
}
7398

7499
const content = promo.content.webview;
75100
switch (this.type) {
76101
case 'info':
77102
if (content.info) {
78-
this.setAttribute('has-promo', '');
103+
this.hasPromo = true;
79104
return html`<p class="promo">${unsafeHTML(content.info.html)}</p>`;
80105
}
81106
break;
82107

83108
case 'link':
84109
if (content.link) {
85-
this.setAttribute('has-promo', '');
110+
this.hasPromo = true;
86111
return html`<a
87112
class="link"
88113
href="${this.getCommandUrl(promo)}"
@@ -93,7 +118,7 @@ export class GlPromo extends LitElement {
93118
break;
94119
}
95120

96-
this.removeAttribute('has-promo');
121+
this.hasPromo = false;
97122
return nothing;
98123
}
99124

@@ -105,4 +130,8 @@ export class GlPromo extends LitElement {
105130

106131
return createCommandLink<Source>(command ?? 'gitlens.plus.upgrade', this.source);
107132
}
133+
134+
override focus(): void {
135+
this._focusable?.focus();
136+
}
108137
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const srOnlyStyles = css`
1212

1313
export const srOnly = css`
1414
.sr-only,
15-
.sr-only-focusable:not(:active):not(:focus):not(:focus-within) {
15+
.sr-only-focusable:not(:active):not(:focus-visible):not(:focus-within) {
1616
${srOnlyStyles}
1717
}
1818
`;
@@ -26,3 +26,9 @@ export const focusOutlineButton = css`
2626
outline: 1px solid var(--color-focus-border);
2727
outline-offset: 2px;
2828
`;
29+
30+
export const focusableBaseStyles = css`
31+
:focus-visible {
32+
${focusOutline}
33+
}
34+
`;

0 commit comments

Comments
 (0)