Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/examples/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default () => {

return (
<React.StrictMode>
<input type="text" />
<div style={{ height: '200vh' }}>
<div style={{ border: '2px solid red' }}>
Real Version: {version}
Expand Down
2 changes: 1 addition & 1 deletion src/useEscKeyDown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
13 changes: 13 additions & 0 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,19 @@ describe('Portal', () => {
expect(onEscB).not.toHaveBeenCalled();
});

it('should not trigger onEsc when IME composing', () => {
const onEsc = jest.fn();

render(
<Portal open onEsc={onEsc}>
<input type="text" />
</Portal>,
);

fireEvent.keyDown(window, { key: 'Escape', isComposing: true });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试中其实无法模拟真实世界中IME的行为,这里有点脱裤子放屁的嫌疑(

expect(onEsc).not.toHaveBeenCalled();
});

it('should clear stack when unmount', () => {
const { unmount } = render(
<Portal open>
Expand Down