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() + } } }