Skip to content

Commit 6c026d2

Browse files
committed
don't change tabindex on child elements of list-item
1 parent cd39d23 commit 6c026d2

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/material-experimental/mdc-list/list-base.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,6 @@ export abstract class MatListItemBase implements AfterContentInit, OnDestroy, Ri
7171
this._rippleRenderer._removeTriggerEvents();
7272
}
7373

74-
/**
75-
* Changes the tabindex of all button and anchor children of this item.
76-
*
77-
* This method is used by the `MatInteractiveBaseList` to implement the
78-
* `setTabIndexForListItemChildren` method on the `MDCListAdapter`
79-
*/
80-
_setTabIndexForChildren(value: number) {
81-
this._elementRef.nativeElement.querySelectorAll<HTMLElement>('a, button')
82-
.forEach(el => el.tabIndex = value);
83-
}
84-
8574
/**
8675
* Subscribes to changes in `MatLine` content children and annotates them appropriately when they
8776
* change.
@@ -148,13 +137,20 @@ export abstract class MatInteractiveListBase extends MatListBase
148137
getAttributeForElementIndex: (index, attr) => this._elementAtIndex(index).getAttribute(attr),
149138
setAttributeForElementIndex:
150139
(index, attr, value) => this._elementAtIndex(index).setAttribute(attr, value),
151-
setTabIndexForListItemChildren:
152-
(index, value) => this._itemAtIndex(index)._setTabIndexForChildren(Number(value)),
153140
getFocusedElementIndex: () => this._indexForElement(this._document?.activeElement),
154141
isFocusInsideList: () => this._element.nativeElement.contains(this._document?.activeElement),
155142
isRootFocused: () => this._element.nativeElement === this._document?.activeElement,
156143
focusItemAtIndex: index => this._elementAtIndex(index).focus(),
157144

145+
// MDC uses this method to disable focusable children of list items. However, we believe that
146+
// this is not an accessible pattern and should be avoided, therefore we intentionally do not
147+
// implement this method. In addition, implementing this would require violating Angular
148+
// Material's general principle of not having components modify DOM elements they do not own.
149+
// A user who feels they really need this feature can simply listen to the `(focus)` and
150+
// `(blur)` events on the list item and enable/disable focus on the children themselves as
151+
// appropriate.
152+
setTabIndexForListItemChildren: () => {},
153+
158154
// The following methods have a dummy implementation in the base class because they are only
159155
// applicable to certain types of lists. They should be implemented for the concrete classes
160156
// where they are applicable.
@@ -185,13 +181,14 @@ export abstract class MatInteractiveListBase extends MatListBase
185181

186182
ngAfterViewInit() {
187183
this._foundation.init();
188-
const first = this._itemAtIndex(0);
184+
const first = this._items.first;
189185
if (first) {
190186
first._elementRef.nativeElement.tabIndex = 0;
191187
}
192188
this._foundation.layout();
193189
this._subscriptions.add(
194-
this._items.changes.subscribe(() => this._itemsArr = this._items.toArray()));
190+
this._items.changes.pipe(startWith(null))
191+
.subscribe(() => this._itemsArr = this._items.toArray()));
195192
}
196193

197194
ngOnDestroy() {

0 commit comments

Comments
 (0)