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) { () => {
match = !!tabbable(root.current).length if (!match !== i > end) {
tabbable(root.current)[0].focus() match = !!tabbable(root.current).length
} else { if (root.current) {
clearTimeout(timer) tabbable(root.current)[0].focus()
} }
console.log('-----------', i) } else {
}, 100) clearTimeout(timer)
}
i = i++
console.log('-----------', i)
},
i < 2 ? 0 : 200
)
} }
useEffect(() => { useEffect(() => {