mirror of
https://github.com/vercel/commerce.git
synced 2025-06-18 13:11:23 +00:00
Test: Add support for n attempts for dynamic components
This commit is contained in:
parent
a78d667031
commit
0b16b80dbe
@ -29,12 +29,11 @@ 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
|
||||||
// Up to 4 seconds of load time threshold
|
// Up to 6 seconds of load time threshold
|
||||||
let match = false
|
let match = false
|
||||||
let end = 22 // Try to find match at least n times
|
let end = 60 // Try to find match at least n times
|
||||||
let i = 0
|
let i = 0
|
||||||
const timer = setInterval(
|
const timer = setInterval(() => {
|
||||||
() => {
|
|
||||||
console.log('-----------', i)
|
console.log('-----------', i)
|
||||||
if (!match !== i > end) {
|
if (!match !== i > end) {
|
||||||
match = !!tabbable(root.current).length
|
match = !!tabbable(root.current).length
|
||||||
@ -42,14 +41,12 @@ export default function FocusTrap({ children, focusFirst = false }: Props) {
|
|||||||
// Attempt to focus the first el
|
// Attempt to focus the first el
|
||||||
tabbable(root.current)[0].focus()
|
tabbable(root.current)[0].focus()
|
||||||
}
|
}
|
||||||
i = i + 1
|
i = i++
|
||||||
} else {
|
} else {
|
||||||
// Clear interval after n attempts
|
// Clear interval after n attempts
|
||||||
clearInterval(timer)
|
clearInterval(timer)
|
||||||
}
|
}
|
||||||
},
|
}, 1000)
|
||||||
i < 2 ? 0 : 200
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user