Skip to content

Commit bfbc917

Browse files
committed
Add ESC shortcut for closing SidePanel
Signed-off-by: EnyMan <[email protected]>
1 parent 8a402c1 commit bfbc917

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

frontend/src/components/SidePanel.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ interface SidePanelProps {
5757
}
5858

5959
class SidePanel extends React.Component<SidePanelProps> {
60+
public componentDidMount(): void {
61+
document.addEventListener('keydown', this.handleKeyDown);
62+
}
63+
64+
public componentWillUnmount(): void {
65+
document.removeEventListener('keydown', this.handleKeyDown);
66+
}
67+
68+
private handleKeyDown = (event: KeyboardEvent): void => {
69+
if (event.key === 'Escape' && this.props.isOpen) {
70+
this.props.onClose();
71+
}
72+
};
73+
6074
public render(): JSX.Element {
6175
const { isBusy, isOpen, onClose, title, defaultWidth } = this.props;
6276
return (

0 commit comments

Comments
 (0)