Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
fix: correct behavior of checkboxes/radios in a list.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 524854269
  • Loading branch information
material-web-copybara authored and copybara-github committed Apr 17, 2023
1 parent a094dd9 commit f771b09
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions packages/mdc-list/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,7 @@ export class MDCList extends MDCComponent<MDCListFoundation> {
private handleClickEvent(evt: MouseEvent) {
const index = this.getListItemIndex(evt.target as Element);
const target = evt.target as Element;
// Toggle the checkbox only if it's not the target of the event, or the
// checkbox will have 2 change events.
const toggleCheckbox = !matches(target, strings.CHECKBOX_RADIO_SELECTOR);
this.foundation.handleClick(index, toggleCheckbox, evt);
this.foundation.handleClick(
index, matches(target, strings.CHECKBOX_RADIO_SELECTOR), evt);
}
}
2 changes: 1 addition & 1 deletion packages/mdc-list/test/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ describe('MDCList', () => {
root.querySelector<HTMLElement>('.mdc-deprecated-list-item')!;
listElementItem.dispatchEvent(event);
expect(mockFoundation.handleClick)
.toHaveBeenCalledWith(0, true, jasmine.any(Event));
.toHaveBeenCalledWith(0, false, jasmine.any(Event));
expect(mockFoundation.handleClick).toHaveBeenCalledTimes(1);
document.body.removeChild(root);
});
Expand Down

0 comments on commit f771b09

Please sign in to comment.