Skip to content

fix(material-experimental/mdc-list): ensure selection change event fires properly #24174

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

Merged
merged 1 commit into from
Jan 10, 2022
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
9 changes: 1 addition & 8 deletions src/material-experimental/mdc-list/selection-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,7 @@ describe('MDC-based MatSelectionList without forms', () => {
expect(listOptions.every(option => option.componentInstance.selected)).toBe(false);
});

// This is temporarily disabled as the MDC list does not emit a proper event when
// items are interactively toggled with e.g. `CTRL + A`.
// TODO(devversion): look more into this. MDC does not expose an `onChange` adapter
// function. Authors are required to emit a change event on checkbox/radio change, but
// that is not an viable option for us since we also allow for programmatic selection updates.
// https://github.com/material-components/material-components-web/blob/a986df922b6b4c1ef5c59925107281d1d40287a8/packages/mdc-list/component.ts#L300-L308.
// tslint:disable-next-line:ban
xit('should dispatch the selectionChange event when selecting via ctrl + a', () => {
it('should dispatch the selectionChange event when selecting via ctrl + a', () => {
const spy = spyOn(fixture.componentInstance, 'onSelectionChange');
listOptions.forEach(option => (option.componentInstance.disabled = false));
fixture.detectChanges();
Expand Down
4 changes: 2 additions & 2 deletions src/material-experimental/mdc-list/selection-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ function getSelectionListAdapter(list: MatSelectionList): MDCListAdapter {

baseAdapter.setAttributeForElementIndex(index, attribute, value);
},
notifyAction(index: number): void {
list._emitChangeEvent([list._itemsArr[index]]);
notifySelectionChange(changedIndices: number[]): void {
list._emitChangeEvent(changedIndices.map(index => list._itemsArr[index]));
},
};
}