Close modal on escape keypress (#12428)

* tooltips 1.0.1

* tooltips 1.0.1

* close on esc

* simpler
This commit is contained in:
ludwiczakpawel 2021-01-26 15:12:54 +01:00 committed by GitHub
parent 6b0505dc47
commit bf72758c4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -30,8 +30,7 @@ export class Help extends Component {
};
};
toggleModal = (varShowing) => (e) => {
e.preventDefault();
toggleModal = (varShowing) => () => {
this.setState((prevState) => ({
...this.setCommonProps({
[varShowing]: !prevState[varShowing],

View file

@ -1,5 +1,6 @@
import { h } from 'preact';
import PropTypes from 'prop-types';
import { KeyboardShortcuts } from '../../shared/components/useKeyboardShortcuts';
import { defaultChildrenPropTypes } from '../../common-prop-types';
import { Button } from '@crayons';
@ -40,6 +41,10 @@ export const Modal = ({
overlay,
onClose,
}) => {
const shortcuts = {
escape: onClose,
};
return (
<div
data-testid="modal-container"
@ -64,6 +69,7 @@ export const Modal = ({
aria-label="Close"
onClick={onClose}
/>
<KeyboardShortcuts shortcuts={shortcuts} />
</div>
)}
<div className="crayons-modal__box__body">{children}</div>