TSK-1600 Fix focus leaking from focus manager ()

Signed-off-by: Alexander Onnikov <alexander.onnikov@xored.com>
This commit is contained in:
Alexander Onnikov 2023-07-20 16:40:56 +07:00 committed by GitHub
parent 4afe81d9b8
commit bfbfd074f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 10 deletions
packages/ui/src

View File

@ -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>

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
}
}
}