mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-18 15:23:38 +01:00
Merge pull request #233 from acoard/feat/close-on-esc
Close the profile password modal via 'Esc' key
This commit is contained in:
commit
ce2ca57aba
@ -10,6 +10,7 @@ import TimezoneSetting from 'components/settings/TimezoneSetting';
|
||||
import Dots from 'assets/ellipsis-h.svg';
|
||||
import styles from './ProfileSettings.module.css';
|
||||
import DateRangeSetting from './DateRangeSetting';
|
||||
import useEscapeKey from 'hooks/useEscapeKey';
|
||||
|
||||
export default function ProfileSettings() {
|
||||
const user = useSelector(state => state.user);
|
||||
@ -22,6 +23,10 @@ export default function ProfileSettings() {
|
||||
setMessage(<FormattedMessage id="message.save-success" defaultMessage="Saved successfully." />);
|
||||
}
|
||||
|
||||
useEscapeKey(() => {
|
||||
setChangePassword(false);
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader>
|
||||
|
19
hooks/useEscapeKey.js
Normal file
19
hooks/useEscapeKey.js
Normal file
@ -0,0 +1,19 @@
|
||||
import { useEffect, useCallback } from 'react';
|
||||
|
||||
export default function useEscapeKey(handler) {
|
||||
const escFunction = useCallback(event => {
|
||||
if (event.keyCode === 27) {
|
||||
handler(event);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
document.addEventListener('keydown', escFunction, false);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('keydown', escFunction, false);
|
||||
};
|
||||
}, [escFunction]);
|
||||
|
||||
return null;
|
||||
}
|
Loading…
Reference in New Issue
Block a user