Adding delay for dynamic

This commit is contained in:
Belen Curcio 2021-01-06 11:44:38 -03:00
parent e42880b088
commit 4594945e02

View File

@ -29,21 +29,18 @@ export default function FocusTrap({ children, focusFirst = false }: Props) {
const selectFirstFocusableEl = () => {
// Try to find focusable elements, if match then focus.
let match = null
let end = 20 // Try to find match at least 10 times.
let match = false
let end = 20 // Try to find match at least n times.
let i = 0
while (!match !== i > end) {
console.log('-----------', i)
const timer = setTimeout(() => {
if (!match !== i > end) {
match = !!tabbable(root.current).length
if (match) {
const delay = i === 0 ? 0 : 200
setTimeout(() => {
tabbable(root.current)[0].focus()
}, delay)
}
i = i + 1
} else {
clearTimeout(timer)
}
console.log('-----------', i)
}, 100)
}
useEffect(() => {