Skip to content

Commit 1dd57ff

Browse files
authored
fix(material-experimental/popover-edit): closing instantly when opening 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.
1 parent fee5810 commit 1dd57ff

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/cdk-experimental/popover-edit/lens-directives.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,14 @@ export class CdkEditClose<FormValue> {
194194
// can move this back into `host`.
195195
// tslint:disable:no-host-decorator-in-concrete
196196
@HostListener('click')
197-
@HostListener('keyup.enter')
198-
@HostListener('keyup.space')
197+
@HostListener('keydown.enter')
198+
@HostListener('keydown.space')
199199
closeEdit(): void {
200200
// Note that we use `click` here, rather than a keyboard event, because some screen readers
201-
// will emit a fake click event instead of an enter keyboard event on buttons.
201+
// will emit a fake click event instead of an enter keyboard event on buttons. For the keyboard
202+
// events we use `keydown`, rather than `keyup`, because we use `keydown` to open the overlay
203+
// as well. If we were to use `keyup`, the user could end up opening and closing within
204+
// the same event sequence if focus was moved quickly.
202205
this.editRef.close();
203206
}
204207
}

0 commit comments

Comments
 (0)