mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-25 01:39:53 +00:00
TSK-1600 Fix focus leaking from focus manager (#3516)
Signed-off-by: Alexander Onnikov <alexander.onnikov@xored.com>
This commit is contained in:
parent
4afe81d9b8
commit
bfbfd074f7
packages/ui/src
@ -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>
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user