Skip to content

Commit d38cefc

Browse files
fix: prevent modal closing when Escape pressed during IME composition
1 parent e66ab51 commit d38cefc

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/components/ModalPortal.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,31 @@ export default class ModalPortal extends Component {
288288
);
289289
};
290290

291-
handleKeyDown = event => {
292-
if (isTabKey(event)) {
293-
scopeTab(this.content, event);
294-
}
291+
handleKeyDown = event => {
292+
if (isTabKey(event)) {
293+
scopeTab(this.content, event);
294+
}
295+
296+
if (!this.props.shouldCloseOnEsc) {
297+
return;
298+
}
299+
300+
const nativeEvent = event.nativeEvent || event;
301+
302+
const isComposing =
303+
nativeEvent.isComposing === true ||
304+
nativeEvent.keyCode === 229 ||
305+
nativeEvent.code === "Process";
306+
307+
if (isComposing) {
308+
return;
309+
}
310+
if (isEscKey(event)) {
311+
event.stopPropagation();
312+
this.requestClose(event);
313+
}
314+
};
295315

296-
if (this.props.shouldCloseOnEsc && isEscKey(event)) {
297-
event.stopPropagation();
298-
this.requestClose(event);
299-
}
300-
};
301316

302317
handleOverlayOnClick = event => {
303318
if (this.shouldClose === null) {

0 commit comments

Comments
 (0)