TSK-1600 Fix focus leaking from focus manager (#3516)

Signed-off-by: Alexander Onnikov <alexander.onnikov@xored.com>
This commit is contained in:
Alexander Onnikov
2023-07-20 15:40:56 +06:00
committed by GitHub
parent 4afe81d9b8
commit bfbfd074f7
2 changed files with 8 additions and 10 deletions
@@ -6,11 +6,9 @@
function handleKey (evt: KeyboardEvent): void {
if (evt.code === 'Tab' && isEnabled) {
const result = manager.next(evt.shiftKey ? -1 : 1)
if (result) {
evt.preventDefault()
evt.stopPropagation()
}
evt.preventDefault()
evt.stopPropagation()
manager.next(evt.shiftKey ? -1 : 1)
}
}
</script>
+5 -5
View File
@@ -4,7 +4,7 @@ import { getContext, onDestroy, setContext } from 'svelte'
* @public
*/
export interface FocusManager {
next: (inc?: 1 | -1) => boolean
next: (inc?: 1 | -1) => void
setFocus: (idx: number) => void
setFocusPos: (order: number) => void
updateFocus: (idx: number, order: number) => void
@@ -43,15 +43,15 @@ class FocusManagerImpl implements FocusManager {
})
}
next (inc?: 1 | -1): boolean {
next (inc?: 1 | -1): void {
const current = this.elements[this.current]
if (!(current?.canBlur?.() ?? false)) {
return false
if (!(current?.canBlur?.() ?? true)) {
return
}
while (true) {
this.current = this.current + (inc ?? 1)
if (this.elements[Math.abs(this.current) % this.elements.length].focus()) {
return true
return
}
}
}