From 1664a2377ab8b5f98370b3c81ef9291b87486f71 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Wed, 6 Jan 2021 11:12:41 -0300 Subject: [PATCH] Retry to focus --- lib/focus-trap.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/focus-trap.tsx b/lib/focus-trap.tsx index b3ab38006..c52ace001 100644 --- a/lib/focus-trap.tsx +++ b/lib/focus-trap.tsx @@ -3,9 +3,10 @@ import { tabbable } from 'tabbable' interface Props { children: React.ReactNode | any + focusFirst: boolean } -export default function FocusTrap({ children }: Props) { +export default function FocusTrap({ children, focusFirst = false }: Props) { const root: RefObject = React.useRef() const anchor: RefObject = React.useRef(document.activeElement) @@ -17,9 +18,12 @@ export default function FocusTrap({ children }: Props) { } const trapFocus = () => { + // Focus the container element if (root.current) { root.current.focus() - selectFirstFocusableEl() + if (focusFirst) { + selectFirstFocusableEl() + } } }