mirror of
https://github.com/vercel/commerce.git
synced 2025-06-18 21:21:21 +00:00
Adding delay for dynamic
This commit is contained in:
parent
e42880b088
commit
4594945e02
@ -29,21 +29,18 @@ export default function FocusTrap({ children, focusFirst = false }: Props) {
|
|||||||
|
|
||||||
const selectFirstFocusableEl = () => {
|
const selectFirstFocusableEl = () => {
|
||||||
// Try to find focusable elements, if match then focus.
|
// Try to find focusable elements, if match then focus.
|
||||||
let match = null
|
let match = false
|
||||||
let end = 20 // Try to find match at least 10 times.
|
let end = 20 // Try to find match at least n times.
|
||||||
let i = 0
|
let i = 0
|
||||||
|
const timer = setTimeout(() => {
|
||||||
while (!match !== i > end) {
|
if (!match !== i > end) {
|
||||||
console.log('-----------', i)
|
|
||||||
match = !!tabbable(root.current).length
|
match = !!tabbable(root.current).length
|
||||||
if (match) {
|
|
||||||
const delay = i === 0 ? 0 : 200
|
|
||||||
setTimeout(() => {
|
|
||||||
tabbable(root.current)[0].focus()
|
tabbable(root.current)[0].focus()
|
||||||
}, delay)
|
} else {
|
||||||
}
|
clearTimeout(timer)
|
||||||
i = i + 1
|
|
||||||
}
|
}
|
||||||
|
console.log('-----------', i)
|
||||||
|
}, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user