Skip to content

Commit

Permalink
Be ready for slow next menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Apr 2, 2024
1 parent e03ced1 commit c991530
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
36 changes: 19 additions & 17 deletions jump.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,34 @@ export function jumpKeyUX() {
}
}

function jumpIfFound(area) {
let next = area.querySelector(
'a, button, select, textarea, ' +
'input:not([type=radio]), [type=radio]:checked, ' +
'[tabindex]:not([tabindex="-1"])'
)
if (next) focus(next)
return next
}
let tries = 0
let finding

function jump(from) {
clearInterval(finding)
let ariaControls = from.getAttribute('aria-controls')
if (!ariaControls) return
setTimeout(() => {
finding = setInterval(() => {
if (tries++ > 50) {
clearInterval(finding)
return
}
let area = window.document.getElementById(ariaControls)
if (area) {
area.dispatchEvent(
new window.CustomEvent('keyuxJump', { bubbles: true })
let next = area.querySelector(
'a, button, select, textarea, ' +
'input:not([type=radio]), [type=radio]:checked, ' +
'[tabindex]:not([tabindex="-1"])'
)
if (!jumpIfFound(area)) {
setTimeout(() => {
jumpIfFound(area)
}, 100)
if (next) {
clearInterval(finding)
area.dispatchEvent(
new window.CustomEvent('keyuxJump', { bubbles: true })
)
focus(next)
}
}
}, 10)
}, 50)
}

function click(event) {
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 }"
},
"limit": "1957 B"
"limit": "1967 B"
}
],
"clean-publish": {
Expand Down

0 comments on commit c991530

Please sign in to comment.