Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(modal): add preventCloseOnClickOutside prop to Modal #6886

Merged
merged 4 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3100,6 +3100,7 @@ Map {
"onRequestClose": [Function],
"onRequestSubmit": [Function],
"passiveModal": false,
"preventCloseOnClickOutside": false,
"primaryButtonDisabled": false,
"selectorPrimaryFocus": "[data-modal-primary-focus]",
},
Expand Down Expand Up @@ -3157,6 +3158,9 @@ Map {
"passiveModal": Object {
"type": "bool",
},
"preventCloseOnClickOutside": Object {
"type": "bool",
},
"primaryButtonDisabled": Object {
"type": "bool",
},
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/components/Modal/Modal-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ const props = () => ({
onRequestClose: action('onRequestClose'),
onRequestSubmit: action('onRequestSubmit'),
onSecondarySubmit: action('onSecondarySubmit'),
preventCloseOnClickOutside: boolean(
'Prevent closing on click outside of modal (preventCloseOnClickOutside)',
false
),
});

const titleOnlyProps = () => {
Expand Down
10 changes: 9 additions & 1 deletion packages/react/src/components/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ export default class Modal extends Component {
*/
passiveModal: PropTypes.bool,

/**
* Prevent closing on click outside of modal
*/
preventCloseOnClickOutside: PropTypes.bool,

/**
* Specify whether the Button should be disabled, or not
*/
Expand Down Expand Up @@ -179,6 +184,7 @@ export default class Modal extends Component {
iconDescription: 'Close',
modalHeading: '',
modalLabel: '',
preventCloseOnClickOutside: false,
selectorPrimaryFocus: '[data-modal-primary-focus]',
hasScrollingContent: false,
};
Expand Down Expand Up @@ -211,7 +217,8 @@ export default class Modal extends Component {
!elementOrParentIsFloatingMenu(
evt.target,
this.props.selectorsFloatingMenus
)
) &&
!this.props.preventCloseOnClickOutside
) {
this.props.onRequestClose(evt);
}
Expand Down Expand Up @@ -321,6 +328,7 @@ export default class Modal extends Component {
shouldSubmitOnEnter, // eslint-disable-line
size,
hasScrollingContent,
preventCloseOnClickOutside, // eslint-disable-line
...other
} = this.props;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ exports[`ModalWrapper should render 1`] = `
onRequestSubmit={[Function]}
open={false}
passiveModal={false}
preventCloseOnClickOutside={false}
primaryButtonDisabled={false}
primaryButtonText="Save"
secondaryButtonText="Cancel"
Expand Down