From 3da58cbb8c53244d7a142712037001f9f5ac8095 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Sun, 9 Feb 2020 17:19:46 +0100 Subject: [PATCH] fix(material-experimental/popover-edit): closing instantly when opening with enter key We use `keydown` to open the popover edit overlay and `keyup` to close it which can lead to situations where the user opens and closes the popup immediately. Seems to have been introduced by #18194. --- src/cdk-experimental/popover-edit/lens-directives.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cdk-experimental/popover-edit/lens-directives.ts b/src/cdk-experimental/popover-edit/lens-directives.ts index 7f1865af4302..5772fdea78d3 100644 --- a/src/cdk-experimental/popover-edit/lens-directives.ts +++ b/src/cdk-experimental/popover-edit/lens-directives.ts @@ -194,11 +194,14 @@ export class CdkEditClose { // can move this back into `host`. // tslint:disable:no-host-decorator-in-concrete @HostListener('click') - @HostListener('keyup.enter') - @HostListener('keyup.space') + @HostListener('keydown.enter') + @HostListener('keydown.space') closeEdit(): void { // Note that we use `click` here, rather than a keyboard event, because some screen readers - // will emit a fake click event instead of an enter keyboard event on buttons. + // will emit a fake click event instead of an enter keyboard event on buttons. For the keyboard + // events we use `keydown`, rather than `keyup`, because we use `keydown` to open the overlay + // as well. If we were to use `keyup`, the user could end up opening and closing within + // the same event sequence if focus was moved quickly. this.editRef.close(); } }