Skip to content

Commit

Permalink
feat(preferences): close preferences with Esc button (#647)
Browse files Browse the repository at this point in the history
* feat(preferences): close preferences with Esc button

* feat: use ioService for escape key handling
  • Loading branch information
gorjan5sk authored Sep 27, 2021
1 parent f12bb7b commit 150f7a7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/assets/javascripts/preferences/PreferencesView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PreferencesMenuView } from './PreferencesMenuView';
import { WebApplication } from '@/ui_models/application';
import { MfaProps } from './panes/two-factor-auth/MfaProps';
import { AppState } from '@/ui_models/app_state';
import { useCallback, useEffect } from 'preact/hooks';

interface PreferencesProps extends MfaProps {
application: WebApplication;
Expand Down Expand Up @@ -63,6 +64,19 @@ const PreferencesCanvas: FunctionComponent<

export const PreferencesView: FunctionComponent<PreferencesProps> = observer(
(props) => {

useEffect(() => {
const removeEscKeyObserver = props.application.io.addKeyObserver({
key: 'Escape',
onKeyDown: (event) => {
event.preventDefault();
props.closePreferences();
}
});
return () => {
removeEscKeyObserver();
};
}, [props]);
const menu = new PreferencesMenu();
return (
<div className="h-full w-full absolute top-left-0 flex flex-col bg-contrast z-index-preferences">
Expand Down

0 comments on commit 150f7a7

Please sign in to comment.