Skip to content
Open
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
10 changes: 10 additions & 0 deletions packages/hooks/src/useKeyPress/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,14 @@ describe('useKeyPress ', () => {
hook2.unmount();
hook1.unmount();
});

it('test single special key when use exactMatch', async () => {
const { unmount } = renderHook(() => useKeyPress(['shift'], callback,{
events: ["keyup"],
exactMatch: true,
}));
fireEvent.keyDown(document, { key: 'shift', keyCode: 16 });
expect(callback.mock.calls.length).toBe(1);
unmount();
});
});
6 changes: 6 additions & 0 deletions packages/hooks/src/useKeyPress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ function genFilterKey(event: KeyboardEvent, keyFilter: KeyType, exactMatch: bool

// 字符串依次判断是否有组合键
const genArr = keyFilter.split('.');

// 如果只有一个则不需要判断是不是组合按键
if (genArr.length === 1){
return aliasKeyCodeMap[keyFilter.toLowerCase()]=== event.keyCode
}

let genLen = 0;

for (const key of genArr) {
Expand Down
Loading