mirror of
https://github.com/vercel/commerce.git
synced 2025-06-18 13:11:23 +00:00
Retry to focus
This commit is contained in:
parent
d53e517f8b
commit
1664a2377a
@ -3,9 +3,10 @@ import { tabbable } from 'tabbable'
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
children: React.ReactNode | any
|
children: React.ReactNode | any
|
||||||
|
focusFirst: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function FocusTrap({ children }: Props) {
|
export default function FocusTrap({ children, focusFirst = false }: Props) {
|
||||||
const root: RefObject<any> = React.useRef()
|
const root: RefObject<any> = React.useRef()
|
||||||
const anchor: RefObject<any> = React.useRef(document.activeElement)
|
const anchor: RefObject<any> = React.useRef(document.activeElement)
|
||||||
|
|
||||||
@ -17,9 +18,12 @@ export default function FocusTrap({ children }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const trapFocus = () => {
|
const trapFocus = () => {
|
||||||
|
// Focus the container element
|
||||||
if (root.current) {
|
if (root.current) {
|
||||||
root.current.focus()
|
root.current.focus()
|
||||||
selectFirstFocusableEl()
|
if (focusFirst) {
|
||||||
|
selectFirstFocusableEl()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user