Skip to content

Commit f5daadc

Browse files
asyncLizcopybara-github
authored andcommitted
chore: update components to use mixinFocusable
PiperOrigin-RevId: 576982507
1 parent f94de5d commit f5daadc

File tree

7 files changed

+23
-69
lines changed

7 files changed

+23
-69
lines changed

chips/internal/chip-set.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {html, isServer, LitElement} from 'lit';
88
import {queryAssignedElements} from 'lit/decorators.js';
99

1010
import {
11+
polyfillARIAMixin,
1112
polyfillElementInternalsAria,
12-
setupHostAria,
1313
} from '../../internal/aria/aria.js';
1414

1515
import {Chip} from './chip.js';
@@ -19,7 +19,7 @@ import {Chip} from './chip.js';
1919
*/
2020
export class ChipSet extends LitElement {
2121
static {
22-
setupHostAria(ChipSet, {focusable: false});
22+
polyfillARIAMixin(ChipSet);
2323
}
2424

2525
get chips() {

internal/aria/aria.ts

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -315,59 +315,6 @@ export function polyfillARIAMixin(ctor: typeof ReactiveElement) {
315315
ctor.createProperty('role', {reflect: true});
316316
}
317317

318-
/**
319-
* Enables a host custom element to be the target for aria roles and attributes.
320-
* Components should set the `elementInternals.role` property.
321-
*
322-
* By default, aria components are tab focusable. Provide a `focusable: false`
323-
* option for components that should not be tab focusable, such as
324-
* `role="listbox"`.
325-
*
326-
* This function will also polyfill aria `ElementInternals` properties for
327-
* Firefox.
328-
*
329-
* @param ctor The `ReactiveElement` constructor to set up.
330-
* @param options Options to configure the element's host aria.
331-
* @deprecated use `mixinFocusable()` and `polyfillARIAMixin()`
332-
* TODO(b/307785469): remove after updating components to use mixinFocusable
333-
*/
334-
export function setupHostAria(
335-
ctor: typeof ReactiveElement,
336-
{focusable}: SetupHostAriaOptions = {},
337-
) {
338-
if (focusable !== false) {
339-
ctor.addInitializer((host) => {
340-
host.addController({
341-
hostConnected() {
342-
if (host.hasAttribute('tabindex')) {
343-
return;
344-
}
345-
346-
host.tabIndex = 0;
347-
},
348-
});
349-
});
350-
}
351-
352-
polyfillARIAMixin(ctor);
353-
}
354-
355-
/**
356-
* Options for setting up a host element as an aria target.
357-
* @deprecated use `mixinFocusable()` and `polyfillARIAMixin()`
358-
* TODO(b/307785469): remove after updating components to use mixinFocusable
359-
*/
360-
export interface SetupHostAriaOptions {
361-
/**
362-
* Whether or not the element can be focused with the tab key. Defaults to
363-
* true.
364-
*
365-
* Set this to false for aria roles that should not be tab focusable, such as
366-
* `role="listbox"`.
367-
*/
368-
focusable?: boolean;
369-
}
370-
371318
/**
372319
* Polyfills an element and its `ElementInternals` to support `ARIAMixin`
373320
* properties on internals. This is needed for Firefox.

list/internal/list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {html, isServer, LitElement} from 'lit';
88
import {queryAssignedElements} from 'lit/decorators.js';
99

1010
import {
11+
polyfillARIAMixin,
1112
polyfillElementInternalsAria,
12-
setupHostAria,
1313
} from '../../internal/aria/aria.js';
1414

1515
import {ListController, NavigableKeys} from './list-controller.js';
@@ -24,7 +24,7 @@ interface ListItem extends SharedListItem {
2424
// tslint:disable-next-line:enforce-comments-on-exported-symbols
2525
export class List extends LitElement {
2626
static {
27-
setupHostAria(List, {focusable: false});
27+
polyfillARIAMixin(List);
2828
}
2929

3030
/**

menu/internal/menu.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import {classMap} from 'lit/directives/class-map.js';
1313
import {styleMap} from 'lit/directives/style-map.js';
1414

1515
import {
16+
polyfillARIAMixin,
1617
polyfillElementInternalsAria,
17-
setupHostAria,
1818
} from '../../internal/aria/aria.js';
1919
import {createAnimationSignal, EASING} from '../../internal/motion/animation.js';
2020
import {
@@ -91,8 +91,7 @@ function getFocusedElement(
9191
*/
9292
export abstract class Menu extends LitElement {
9393
static {
94-
// We want to manage tabindex ourselves.
95-
setupHostAria(Menu, {focusable: false});
94+
polyfillARIAMixin(Menu);
9695
}
9796

9897
@query('.menu') private readonly surfaceEl!: HTMLElement | null;

radio/internal/radio.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ import {property} from 'lit/decorators.js';
1212
import {classMap} from 'lit/directives/class-map.js';
1313

1414
import {
15+
polyfillARIAMixin,
1516
polyfillElementInternalsAria,
16-
setupHostAria,
1717
} from '../../internal/aria/aria.js';
1818
import {isActivationClick} from '../../internal/controller/events.js';
19+
import {mixinFocusable} from '../../labs/behaviors/focusable.js';
1920

2021
import {SingleSelectionController} from './single-selection-controller.js';
2122

2223
const CHECKED = Symbol('checked');
2324
let maskId = 0;
2425

26+
// Separate variable needed for closure.
27+
const radioBaseClass = mixinFocusable(LitElement);
28+
2529
/**
2630
* A radio component.
2731
*
@@ -30,9 +34,9 @@ let maskId = 0;
3034
* @fires change Dispatched when the value changes from user interaction.
3135
* --bubbles --composed
3236
*/
33-
export class Radio extends LitElement {
37+
export class Radio extends radioBaseClass {
3438
static {
35-
setupHostAria(Radio);
39+
polyfillARIAMixin(Radio);
3640
}
3741

3842
/** @nocollapse */
@@ -116,7 +120,7 @@ export class Radio extends LitElement {
116120
}
117121

118122
protected override render() {
119-
const classes = {checked: this.checked};
123+
const classes = {'checked': this.checked};
120124
return html`
121125
<div class="container ${classMap(classes)}" aria-hidden="true">
122126
<md-ripple

tabs/internal/tab.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ import {
1919
import {classMap} from 'lit/directives/class-map.js';
2020

2121
import {
22+
polyfillARIAMixin,
2223
polyfillElementInternalsAria,
23-
setupHostAria,
2424
} from '../../internal/aria/aria.js';
2525
import {EASING} from '../../internal/motion/animation.js';
26+
import {mixinFocusable} from '../../labs/behaviors/focusable.js';
2627

2728
/**
2829
* Symbol for tabs to use to animate their indicators based off another tab's
@@ -36,12 +37,15 @@ const INDICATOR = Symbol('indicator');
3637
*/
3738
export const ANIMATE_INDICATOR = Symbol('animateIndicator');
3839

40+
// Separate variable needed for closure.
41+
const tabBaseClass = mixinFocusable(LitElement);
42+
3943
/**
4044
* Tab component.
4145
*/
42-
export class Tab extends LitElement {
46+
export class Tab extends tabBaseClass {
4347
static {
44-
setupHostAria(Tab);
48+
polyfillARIAMixin(Tab);
4549
}
4650

4751
/**

tabs/internal/tabs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {html, isServer, LitElement} from 'lit';
1010
import {property, query, queryAssignedElements} from 'lit/decorators.js';
1111

1212
import {
13+
polyfillARIAMixin,
1314
polyfillElementInternalsAria,
14-
setupHostAria,
1515
} from '../../internal/aria/aria.js';
1616

1717
import {ANIMATE_INDICATOR, Tab} from './tab.js';
@@ -42,7 +42,7 @@ import {ANIMATE_INDICATOR, Tab} from './tab.js';
4242
*/
4343
export class Tabs extends LitElement {
4444
static {
45-
setupHostAria(Tabs, {focusable: false});
45+
polyfillARIAMixin(Tabs);
4646
}
4747

4848
/**

0 commit comments

Comments
 (0)