Skip to content

Commit

Permalink
feat(modal): allowoutsideclick optional prop
Browse files Browse the repository at this point in the history
Adding prop allowOutsideClick which is optional.
Default value is true, changing it to false stops the user from
clicking outside the component, which stops the behavior of
tabbing outside a component to be possible.
  • Loading branch information
victoringvarsson authored and boilund committed Mar 1, 2023
1 parent d20f6f9 commit 4346b75
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/core/src/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,19 @@ export interface ModalProps extends BaseProps {
* When `true` the dialog is rendered, `false` removes the dialog.
*/
readonly open: boolean
/**
* If `true`, clicking outside the modal is possible, `false` does not allow
* clicking outside the modal.
*/
readonly allowOutsideClick?: boolean
}

export const Modal: FC<ModalProps> = ({
open,
onClose,
focusDialog = true,
children,
allowOutsideClick = true,
...props
}) => {
useEffect(() => {
Expand All @@ -156,7 +162,7 @@ export const Modal: FC<ModalProps> = ({
focusTrapOptions={{
initialFocus: focusDialog ? `#${id}` : undefined,
escapeDeactivates: false, // We use our own stack
clickOutsideDeactivates: true, // 😱😱😱 We need this to prevent click capturing
clickOutsideDeactivates: allowOutsideClick,
}}
>
<FocusWrapper tabIndex={-1} id={id}>
Expand Down

0 comments on commit 4346b75

Please sign in to comment.