Skip to content

Commit

Permalink
fix(menusurface): Fixing bug where body click listener is not being p…
Browse files Browse the repository at this point in the history
…roperly deregistered.

closes: #6557
PiperOrigin-RevId: 339893099
  • Loading branch information
sayris authored and copybara-github committed Oct 30, 2020
1 parent 710f97b commit cec8587
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/mdc-menu-surface/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export class MDCMenuSurface extends MDCComponent<MDCMenuSurfaceFoundation> {
'click', this.handleBodyClick, {capture: true});
};
this.deregisterBodyClickListener = () => {
document.body.removeEventListener('click', this.handleBodyClick);
document.body.removeEventListener(
'click', this.handleBodyClick, {capture: true});
};

this.listen('keydown', this.handleKeydown);
Expand Down
1 change: 1 addition & 0 deletions packages/mdc-menu-surface/test/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ describe('MDCMenuSurface', () => {
it(`${strings.CLOSED_EVENT} causes the body click handler to be deregistered`,
() => {
const {root, mockFoundation} = setupTest();
emitEvent(root, strings.OPENED_EVENT);
emitEvent(root, strings.CLOSED_EVENT);
emitEvent(document.body, 'click');
expect(mockFoundation.handleBodyClick)
Expand Down

0 comments on commit cec8587

Please sign in to comment.