Skip to content

Commit 431ba18

Browse files
asynclizcopybara-github
authored andcommitted
chore(chips): remove unnecessary tabindex logic
PiperOrigin-RevId: 540977179
1 parent f2ad219 commit 431ba18

File tree

3 files changed

+5
-28
lines changed

3 files changed

+5
-28
lines changed

chips/lib/input-chip.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export class InputChip extends MultiActionChip {
106106
return renderRemoveButton({
107107
ariaLabel: this.ariaLabelRemove,
108108
disabled: this.disabled,
109+
tabbable: this.removeOnly,
109110
});
110111
}
111112
}

chips/lib/multi-action-chip.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ export abstract class MultiActionChip extends Chip {
4545
constructor() {
4646
super();
4747
if (!isServer) {
48-
this.addEventListener('focusin', this.updateTabIndices.bind(this));
49-
this.addEventListener('focusout', this.updateTabIndices.bind(this));
5048
this.addEventListener('keydown', this.handleKeyDown.bind(this));
5149
}
5250
}
@@ -60,10 +58,6 @@ export abstract class MultiActionChip extends Chip {
6058
super.focus(options);
6159
}
6260

63-
protected override firstUpdated() {
64-
this.updateTabIndices();
65-
}
66-
6761
protected override renderActions() {
6862
return html`
6963
${super.renderActions()}
@@ -103,25 +97,5 @@ export abstract class MultiActionChip extends Chip {
10397
event.stopPropagation();
10498
const actionToFocus = forwards ? this.trailingAction : this.primaryAction;
10599
actionToFocus.focus();
106-
this.updateTabIndices();
107-
}
108-
109-
private updateTabIndices() {
110-
const {primaryAction, trailingAction} = this;
111-
if (!primaryAction || !trailingAction) {
112-
// Does not have multiple actions.
113-
primaryAction?.removeAttribute('tabindex');
114-
trailingAction?.removeAttribute('tabindex');
115-
return;
116-
}
117-
118-
if (trailingAction.matches(':focus-within')) {
119-
trailingAction.removeAttribute('tabindex');
120-
primaryAction.tabIndex = -1;
121-
return;
122-
}
123-
124-
primaryAction.removeAttribute('tabindex');
125-
trailingAction.tabIndex = -1;
126100
}
127101
}

chips/lib/trailing-icons.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@
77
import '../../focus/focus-ring.js';
88
import '../../ripple/ripple.js';
99

10-
import {html} from 'lit';
10+
import {html, nothing} from 'lit';
1111

1212
import {Chip} from './chip.js';
1313

1414
interface RemoveButtonProperties {
1515
ariaLabel: string;
1616
disabled: boolean;
17+
tabbable?: boolean;
1718
}
1819

1920
/** @protected */
2021
export function renderRemoveButton(
21-
{ariaLabel, disabled}: RemoveButtonProperties) {
22+
{ariaLabel, disabled, tabbable = false}: RemoveButtonProperties) {
2223
return html`
2324
<button class="trailing action"
2425
aria-label=${ariaLabel}
2526
?disabled=${disabled}
27+
tabindex=${!tabbable ? -1 : nothing}
2628
@click=${handleRemoveClick}
2729
>
2830
<md-focus-ring></md-focus-ring>

0 commit comments

Comments
 (0)