Only bind shortcut for pending changes confirmation when it's shown
This commit is contained in:
parent
e1c6722aad
commit
ded7c3c6e2
|
@ -15,12 +15,17 @@ function PendingChangesModal(props) {
|
||||||
isOpen,
|
isOpen,
|
||||||
onConfirm,
|
onConfirm,
|
||||||
onCancel,
|
onCancel,
|
||||||
bindShortcut
|
bindShortcut,
|
||||||
|
unbindShortcut
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
bindShortcut('enter', onConfirm);
|
if (isOpen) {
|
||||||
}, [bindShortcut, onConfirm]);
|
bindShortcut('enter', onConfirm);
|
||||||
|
|
||||||
|
return () => unbindShortcut('enter', onConfirm);
|
||||||
|
}
|
||||||
|
}, [bindShortcut, unbindShortcut, isOpen, onConfirm]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
|
@ -61,7 +66,8 @@ PendingChangesModal.propTypes = {
|
||||||
kind: PropTypes.oneOf(kinds.all),
|
kind: PropTypes.oneOf(kinds.all),
|
||||||
onConfirm: PropTypes.func.isRequired,
|
onConfirm: PropTypes.func.isRequired,
|
||||||
onCancel: PropTypes.func.isRequired,
|
onCancel: PropTypes.func.isRequired,
|
||||||
bindShortcut: PropTypes.func.isRequired
|
bindShortcut: PropTypes.func.isRequired,
|
||||||
|
unbindShortcut: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
PendingChangesModal.defaultProps = {
|
PendingChangesModal.defaultProps = {
|
||||||
|
|
Loading…
Reference in New Issue