Skip to content

Commit

Permalink
shouldCloseOnEsc: Add prop and logical check to keyHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
spen committed Aug 27, 2017
1 parent 1685e59 commit f94481c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export default class Modal extends Component {
parentSelector: PropTypes.func,
aria: PropTypes.object,
role: PropTypes.string,
contentLabel: PropTypes.string.isRequired
contentLabel: PropTypes.string.isRequired,
shouldCloseOnEsc: PropTypes.bool
};
/* eslint-enable react/no-unused-prop-types */

Expand Down
7 changes: 5 additions & 2 deletions src/components/ModalPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const ESC_KEY = 27;

export default class ModalPortal extends Component {
static defaultProps = {
shouldCloseOnEsc: true,
style: {
overlay: {},
content: {}
Expand Down Expand Up @@ -52,7 +53,8 @@ export default class ModalPortal extends Component {
role: PropTypes.string,
contentLabel: PropTypes.string,
aria: PropTypes.object,
children: PropTypes.node
children: PropTypes.node,
shouldCloseOnEsc: PropTypes.bool
};

constructor(props) {
Expand Down Expand Up @@ -196,7 +198,8 @@ export default class ModalPortal extends Component {
if (event.keyCode === TAB_KEY) {
scopeTab(this.content, event);
}
if (event.keyCode === ESC_KEY) {

if (this.props.shouldCloseOnEsc && event.keyCode === ESC_KEY) {
event.preventDefault();
this.requestClose(event);
}
Expand Down

0 comments on commit f94481c

Please sign in to comment.