Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 4346b75

Browse files
victoringvarssonboilund
authored andcommitted
feat(modal): allowoutsideclick optional prop
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.
1 parent d20f6f9 commit 4346b75

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/core/src/Modal/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,19 @@ export interface ModalProps extends BaseProps {
123123
* When `true` the dialog is rendered, `false` removes the dialog.
124124
*/
125125
readonly open: boolean
126+
/**
127+
* If `true`, clicking outside the modal is possible, `false` does not allow
128+
* clicking outside the modal.
129+
*/
130+
readonly allowOutsideClick?: boolean
126131
}
127132

128133
export const Modal: FC<ModalProps> = ({
129134
open,
130135
onClose,
131136
focusDialog = true,
132137
children,
138+
allowOutsideClick = true,
133139
...props
134140
}) => {
135141
useEffect(() => {
@@ -156,7 +162,7 @@ export const Modal: FC<ModalProps> = ({
156162
focusTrapOptions={{
157163
initialFocus: focusDialog ? `#${id}` : undefined,
158164
escapeDeactivates: false, // We use our own stack
159-
clickOutsideDeactivates: true, // 😱😱😱 We need this to prevent click capturing
165+
clickOutsideDeactivates: allowOutsideClick,
160166
}}
161167
>
162168
<FocusWrapper tabIndex={-1} id={id}>

0 commit comments

Comments
 (0)