Adding delay for dynamic

This commit is contained in:
Belen Curcio 2021-01-06 11:54:19 -03:00
parent f3aab45390
commit 725ba0b4d2

View File

@ -32,7 +32,7 @@ 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 = setInterval(
() => { () => {
if (!match !== i > end) { if (!match !== i > end) {
match = !!tabbable(root.current).length match = !!tabbable(root.current).length
@ -40,7 +40,7 @@ export default function FocusTrap({ children, focusFirst = false }: Props) {
tabbable(root.current)[0].focus() tabbable(root.current)[0].focus()
} }
} else { } else {
clearTimeout(timer) clearInterval(timer)
} }
i = i++ i = i++
console.log('-----------', i) console.log('-----------', i)