From cc6ddde4283c2b5ce92d0d11ea5465aeebf03543 Mon Sep 17 00:00:00 2001 From: aojunhao123 <1844749591@qq.com> Date: Wed, 24 Dec 2025 17:10:41 +0800 Subject: [PATCH 1/2] fix: should not trigger onEsc when IME composing --- docs/examples/basic.tsx | 1 + src/useEscKeyDown.ts | 2 +- tests/index.test.tsx | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/examples/basic.tsx b/docs/examples/basic.tsx index b1bb1ea..a19bb1e 100644 --- a/docs/examples/basic.tsx +++ b/docs/examples/basic.tsx @@ -22,6 +22,7 @@ export default () => { return ( +
Real Version: {version} diff --git a/src/useEscKeyDown.ts b/src/useEscKeyDown.ts index 0044231..90e31c6 100644 --- a/src/useEscKeyDown.ts +++ b/src/useEscKeyDown.ts @@ -9,7 +9,7 @@ export default function useEscKeyDown(open: boolean, onEsc?: EscCallback) { const id = useId(); const handleEscKeyDown = useEvent((event: KeyboardEvent) => { - if (event.key === 'Escape') { + if (event.key === 'Escape' && !event.isComposing) { const top = stack[stack.length - 1] === id; onEsc?.({ top, event }); } diff --git a/tests/index.test.tsx b/tests/index.test.tsx index 40b5eba..a7d5db6 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -357,6 +357,19 @@ describe('Portal', () => { expect(onEscB).not.toHaveBeenCalled(); }); + it('should not trigger onEsc when IME composing', async () => { + const onEsc = jest.fn(); + + render( + + + , + ); + + fireEvent.keyDown(window, { key: 'Escape', isComposing: true }); + expect(onEsc).not.toHaveBeenCalled(); + }); + it('should clear stack when unmount', () => { const { unmount } = render( From a890c0906bc32a60841ef7e670244ac8832ef3ad Mon Sep 17 00:00:00 2001 From: aojunhao123 <1844749591@qq.com> Date: Wed, 24 Dec 2025 17:24:03 +0800 Subject: [PATCH 2/2] Update tests/index.test.tsx Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- tests/index.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/index.test.tsx b/tests/index.test.tsx index a7d5db6..f95eeba 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -357,7 +357,7 @@ describe('Portal', () => { expect(onEscB).not.toHaveBeenCalled(); }); - it('should not trigger onEsc when IME composing', async () => { + it('should not trigger onEsc when IME composing', () => { const onEsc = jest.fn(); render(