Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing indexOf usage bug when selection-list handles changes in items. #28531

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/material/list/selection-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,21 @@ describe('MDC-based MatSelectionList with forms', () => {
.toBe(1);
}));

it('should focus the first option when the list items are changed', fakeAsync(() => {
fixture.componentInstance.options = ['first option', 'second option'];
fixture.detectChanges();

tick();

const listElements = fixture.debugElement
.queryAll(By.directive(MatListOption))
.map(optionDebugEl => optionDebugEl.nativeElement);

expect(listElements.length).toBe(2);
expect(listElements[0].tabIndex).toBe(0);
expect(listElements[1].tabIndex).toBe(-1);
}));

it('should not mark the model as touched when the list is blurred', fakeAsync(() => {
expect(ngModel.touched)
.withContext('Expected the selection-list to be untouched by default.')
Expand Down
2 changes: 1 addition & 1 deletion src/material/list/selection-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export class MatSelectionList
this._items.changes.pipe(takeUntil(this._destroyed)).subscribe(() => {
const activeItem = this._keyManager.activeItem;

if (!activeItem || !this._items.toArray().indexOf(activeItem)) {
if (!activeItem || this._items.toArray().indexOf(activeItem) === -1) {
this._resetActiveOption();
}
});
Expand Down
Loading