From d38cefcbd94f74318458db6da36aaed2ece67ee2 Mon Sep 17 00:00:00 2001 From: Rajnish kumar <100439674+Rajnishkr8541@users.noreply.github.com> Date: Mon, 8 Dec 2025 10:34:42 +0530 Subject: [PATCH] fix: prevent modal closing when Escape pressed during IME composition --- src/components/ModalPortal.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/components/ModalPortal.js b/src/components/ModalPortal.js index 7f20df67..533297aa 100644 --- a/src/components/ModalPortal.js +++ b/src/components/ModalPortal.js @@ -288,16 +288,31 @@ export default class ModalPortal extends Component { ); }; - handleKeyDown = event => { - if (isTabKey(event)) { - scopeTab(this.content, event); - } + handleKeyDown = event => { + if (isTabKey(event)) { + scopeTab(this.content, event); + } + + if (!this.props.shouldCloseOnEsc) { + return; + } + + const nativeEvent = event.nativeEvent || event; + + const isComposing = + nativeEvent.isComposing === true || + nativeEvent.keyCode === 229 || + nativeEvent.code === "Process"; + + if (isComposing) { + return; + } + if (isEscKey(event)) { + event.stopPropagation(); + this.requestClose(event); + } +}; - if (this.props.shouldCloseOnEsc && isEscKey(event)) { - event.stopPropagation(); - this.requestClose(event); - } - }; handleOverlayOnClick = event => { if (this.shouldClose === null) {