Skip to content

Commit

Permalink
feat(modal): add preventCloseOnClickOutside prop to Modal (#6886)
Browse files Browse the repository at this point in the history
Co-authored-by: DAK <40970507+dakahn@users.noreply.github.com>
  • Loading branch information
Laszlo Moczo and dakahn committed Sep 23, 2020
1 parent fcb44ac commit 9743681
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
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

0 comments on commit 9743681

Please sign in to comment.