From 17e15b89e50052b9d2c63c441173bece864559eb Mon Sep 17 00:00:00 2001 From: Daniel Macak Date: Tue, 2 Jul 2024 12:56:04 +0200 Subject: [PATCH] fix: propagate Escape out of dialog Previously, the Escape key was swallowed and in turn, if the picker was displayed in a dialog, the dialog would not close. Relates to PS-21279. --- .../emoji-mart/src/components/Navigation/Navigation.tsx | 5 ++++- packages/emoji-mart/src/components/Picker/Picker.tsx | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/emoji-mart/src/components/Navigation/Navigation.tsx b/packages/emoji-mart/src/components/Navigation/Navigation.tsx index 5287ab4d..194432be 100644 --- a/packages/emoji-mart/src/components/Navigation/Navigation.tsx +++ b/packages/emoji-mart/src/components/Navigation/Navigation.tsx @@ -24,7 +24,10 @@ export default class Navigation extends PureComponent { } handleKeyDown = (e: KeyboardEvent) => { - e.stopImmediatePropagation() + // Escape should still propagate up since it can be used in a dialog + if (e.key !== 'Escape') { + e.stopImmediatePropagation() + } switch (e.key) { case 'ArrowLeft': diff --git a/packages/emoji-mart/src/components/Picker/Picker.tsx b/packages/emoji-mart/src/components/Picker/Picker.tsx index 8f33f809..84414d57 100644 --- a/packages/emoji-mart/src/components/Picker/Picker.tsx +++ b/packages/emoji-mart/src/components/Picker/Picker.tsx @@ -406,10 +406,14 @@ export default class Picker extends Component { this.setState({ searchResults: grid, pos }, afterRender) } - handleEmojisKeyDown = (e) => { + handleEmojisKeyDown = (e: KeyboardEvent) => { // const specialKey = e.altKey || e.ctrlKey || e.metaKey const input = this.refs.searchInput.current - e.stopImmediatePropagation() + + // Escape should still propagate up since it can be used in a dialog + if (e.key !== 'Escape') { + e.stopImmediatePropagation() + } switch (e.key) { case 'ArrowLeft':