Adding delay for dynamic

This commit is contained in:
Belen Curcio 2021-01-06 11:53:31 -03:00
parent 4594945e02
commit f3aab45390

View File

@ -32,15 +32,21 @@ export default function FocusTrap({ children, focusFirst = false }: Props) {
let match = false let match = false
let end = 20 // Try to find match at least n times. let end = 20 // Try to find match at least n times.
let i = 0 let i = 0
const timer = setTimeout(() => { const timer = setTimeout(
() => {
if (!match !== i > end) { if (!match !== i > end) {
match = !!tabbable(root.current).length match = !!tabbable(root.current).length
if (root.current) {
tabbable(root.current)[0].focus() tabbable(root.current)[0].focus()
}
} else { } else {
clearTimeout(timer) clearTimeout(timer)
} }
i = i++
console.log('-----------', i) console.log('-----------', i)
}, 100) },
i < 2 ? 0 : 200
)
} }
useEffect(() => { useEffect(() => {