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
4 changes: 2 additions & 2 deletions hotkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ function findHotKey(event, window, transformers) {
if (
!hotkey &&
(event.key.length > 1 || NON_ENGLISH_LAYOUT.test(event.key)) &&
/^Key.$/.test(event.code)
/^(Key.|Digit\d)$/.test(event.code)
) {
let enKey = event.code.replace(/^Key/, '').toLowerCase()
let enKey = event.code.replace(/^Key|^Digit/, '').toLowerCase()
hotkey = checkHotkey(window, prefix + enKey, transformers)
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"import": {
"./index.js": "{ startKeyUX, hotkeyKeyUX, pressKeyUX, focusGroupKeyUX, jumpKeyUX, hiddenKeyUX, likelyWithKeyboard, getHotKeyHint, hotkeyOverrides, hotkeyMacCompat }"
},
"limit": "2202 B"
"limit": "2210 B"
}
],
"clean-publish": {
Expand Down
18 changes: 18 additions & 0 deletions test/demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ const Counter: FC = () => {
)
}

const Numbers: FC = () => {
return (
<div className="toolbar" role="toolbar">
<div className="toolbar_group">
{Array(10)
.fill(0)
.map((_, i) => (
<button aria-keyshortcuts={`alt+${i}`} key={i}>
Digit <strong>{i}</strong>
<HotKeyHint hotkey={`alt+${i}`} />
</button>
))}
</div>
</div>
)
}

const Search: FC = () => {
return (
<div>
Expand Down Expand Up @@ -481,6 +498,7 @@ const App: FC = () => {
<FocusGroup />
<FocusGroupInline />
<FocusGroupBlock />
<Numbers />
</>
)
}
Expand Down
14 changes: 12 additions & 2 deletions test/hotkey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,28 @@ test('does not ignore hotkeys with Alt on focus in text field', () => {
test('supports non-English keyboard layouts', () => {
let window = new JSDOM().window
startKeyUX(window, [hotkeyKeyUX()])
window.document.body.innerHTML = '<button aria-keyshortcuts="Alt+B"></button>'
window.document.body.innerHTML =
'<button id="button1" aria-keyshortcuts="Alt+B"></button>' +
'<button id="button2" aria-keyshortcuts="Alt+0"></button>'

let clicked = 0
window.document.querySelector('button')!.addEventListener('click', () => {
window.document.querySelector('#button1')!.addEventListener('click', () => {
clicked += 1
})

let digitClicked = 0
window.document.querySelector('#button2')!.addEventListener('click', () => {
digitClicked += 1
})

press(window, { altKey: true, code: 'KeyB', key: 'и' })
equal(clicked, 1)

press(window, { altKey: true, code: 'KeyB', key: 'Unidentified' })
equal(clicked, 2)

press(window, { altKey: true, code: 'Digit0', key: 'º' })
equal(digitClicked, 1)
})

test('allows to override hotkeys', () => {
Expand Down