Skip to content

Commit

Permalink
fix(material-experimental/popover-edit): closing instantly when openi…
Browse files Browse the repository at this point in the history
…ng with enter key (#18444)

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.
  • Loading branch information
crisbeto authored and mmalerba committed Jun 17, 2020
1 parent 4eac5e8 commit 23b9145
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/cdk-experimental/popover-edit/lens-directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,14 @@ export class CdkEditClose<FormValue> {
// 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();
}
}

0 comments on commit 23b9145

Please sign in to comment.