mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-24 20:13:00 +03:00
Fix TAB behaviour for forms: add a condition when to prevent default behaviour (#3508)
Signed-off-by: Maksim Karmatskikh <mkarmatskih@gmail.com> Co-authored-by: Maxim Karmatskih <mk@jetstyle.co>
This commit is contained in:
parent
92ab38456b
commit
f8e00ed880
@ -6,9 +6,11 @@
|
||||
|
||||
function handleKey (evt: KeyboardEvent): void {
|
||||
if (evt.code === 'Tab' && isEnabled) {
|
||||
evt.preventDefault()
|
||||
evt.stopPropagation()
|
||||
manager.next(evt.shiftKey ? -1 : 1)
|
||||
const result = manager.next(evt.shiftKey ? -1 : 1)
|
||||
if (result) {
|
||||
evt.preventDefault()
|
||||
evt.stopPropagation()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -4,7 +4,7 @@ import { getContext, onDestroy, setContext } from 'svelte'
|
||||
* @public
|
||||
*/
|
||||
export interface FocusManager {
|
||||
next: (inc?: 1 | -1) => void
|
||||
next: (inc?: 1 | -1) => boolean
|
||||
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): void {
|
||||
next (inc?: 1 | -1): boolean {
|
||||
const current = this.elements[this.current]
|
||||
if (!(current?.canBlur?.() ?? false)) {
|
||||
return
|
||||
return false
|
||||
}
|
||||
while (true) {
|
||||
this.current = this.current + (inc ?? 1)
|
||||
if (this.elements[Math.abs(this.current) % this.elements.length].focus()) {
|
||||
break
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user