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

Added close modal on right click #961

Closed
Closed
Show file tree
Hide file tree
Changes from all 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 docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ import ReactModal from 'react-modal';
true
/* Boolean indicating if the overlay should close the modal */}

shouldCloseOnOverlayRightClick={
true
/* Boolean indicating if the overlay should close the modal on right click*/}

shouldCloseOnEsc={
true
/* Boolean indicating if pressing the esc key should close the modal
Expand Down
2 changes: 2 additions & 0 deletions src/components/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Modal extends Component {
ariaHideApp: PropTypes.bool,
shouldFocusAfterRender: PropTypes.bool,
shouldCloseOnOverlayClick: PropTypes.bool,
shouldCloseOnOverlayRightClick:PropTypes.bool,
shouldReturnFocusAfterClose: PropTypes.bool,
preventScroll: PropTypes.bool,
parentSelector: PropTypes.func,
Expand All @@ -96,6 +97,7 @@ class Modal extends Component {
shouldFocusAfterRender: true,
shouldCloseOnEsc: true,
shouldCloseOnOverlayClick: true,
shouldCloseOnOverlayRightClick:false,
shouldReturnFocusAfterClose: true,
preventScroll: false,
parentSelector: () => document.body,
Expand Down
13 changes: 12 additions & 1 deletion src/components/ModalPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,16 @@ export default class ModalPortal extends Component {
this.shouldClose = null;
};

handleOverlayOnContextMenu = event => {
if(this.shouldClose===null)this.shouldClose=true;
else if(!this.shouldClose) this.shouldClose=null;
if(this.shouldClose && this.props.shouldCloseOnOverlayRightClick)
{
event.preventDefault();
this.requestClose(event);
}
};

handleContentOnMouseUp = () => {
this.shouldClose = false;
};
Expand Down Expand Up @@ -375,7 +385,8 @@ export default class ModalPortal extends Component {
className: this.buildClassName("overlay", overlayClassName),
style: { ...overlayStyles, ...this.props.style.overlay },
onClick: this.handleOverlayOnClick,
onMouseDown: this.handleOverlayOnMouseDown
onMouseDown: this.handleOverlayOnMouseDown,
onContextMenu: this.handleOverlayOnContextMenu,
};

const contentProps = {
Expand Down