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 {
|
function handleKey (evt: KeyboardEvent): void {
|
||||||
if (evt.code === 'Tab' && isEnabled) {
|
if (evt.code === 'Tab' && isEnabled) {
|
||||||
evt.preventDefault()
|
const result = manager.next(evt.shiftKey ? -1 : 1)
|
||||||
evt.stopPropagation()
|
if (result) {
|
||||||
manager.next(evt.shiftKey ? -1 : 1)
|
evt.preventDefault()
|
||||||
|
evt.stopPropagation()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -4,7 +4,7 @@ import { getContext, onDestroy, setContext } from 'svelte'
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export interface FocusManager {
|
export interface FocusManager {
|
||||||
next: (inc?: 1 | -1) => void
|
next: (inc?: 1 | -1) => boolean
|
||||||
setFocus: (idx: number) => void
|
setFocus: (idx: number) => void
|
||||||
setFocusPos: (order: number) => void
|
setFocusPos: (order: number) => void
|
||||||
updateFocus: (idx: number, 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]
|
const current = this.elements[this.current]
|
||||||
if (!(current?.canBlur?.() ?? false)) {
|
if (!(current?.canBlur?.() ?? false)) {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
this.current = this.current + (inc ?? 1)
|
this.current = this.current + (inc ?? 1)
|
||||||
if (this.elements[Math.abs(this.current) % this.elements.length].focus()) {
|
if (this.elements[Math.abs(this.current) % this.elements.length].focus()) {
|
||||||
break
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user