Skip to content

Commit

Permalink
Fixed foucus not moving along with input chain. Addresses #163.
Browse files Browse the repository at this point in the history
  • Loading branch information
michielvandergeest committed Sep 19, 2024
1 parent 67fdc0e commit 966d8da
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,24 @@ export default {
focusedComponent && focusedComponent !== component.parent && focusedComponent.unfocus()
focusChain.reverse().forEach((cmp) => cmp.unfocus())
if (component !== focusedComponent) {
setFocusTimeout = setTimeout(
() => {
focusedComponent = component
focusedComponent.lifecycle.state = 'focus'
if (event instanceof KeyboardEvent) {
document.dispatchEvent(new KeyboardEvent('keydown', event))
} else {
focusChain = []
}
},
this.hold ? Settings.get('holdTimeout', DEFAULT_HOLD_TIMEOUT_MS) : 0
)
if (this.hold === false) {
focus(component, event)
} else {
setFocusTimeout = setTimeout(() => {
focus(component, event)
}, Settings.get('holdTimeout', DEFAULT_HOLD_TIMEOUT_MS))
}
}
},
input(key, event) {
if (navigating === true) return
focusChain = walkChain([focusedComponent], key)
const componentWithInputEvent = focusChain.shift()

if (componentWithInputEvent) {
if (componentWithInputEvent !== undefined) {
if (componentWithInputEvent !== focusedComponent) {
this.set(componentWithInputEvent)
}
if (componentWithInputEvent[symbols.inputEvents][key]) {
componentWithInputEvent[symbols.inputEvents][key].call(componentWithInputEvent, event)
} else if (componentWithInputEvent[symbols.inputEvents].any) {
Expand All @@ -81,3 +79,13 @@ const walkChain = (components, key) => {
return walkChain(components, key)
} else return []
}

const focus = (component, event) => {
focusedComponent = component
focusedComponent.lifecycle.state = 'focus'
if (event !== undefined && event instanceof KeyboardEvent) {
document.dispatchEvent(new KeyboardEvent('keydown', event))
} else {
focusChain = []
}
}

0 comments on commit 966d8da

Please sign in to comment.