Browse Source

Forum: Back on Escape

Joystream Stats 4 years ago
parent
commit
a5f664ae33
1 changed files with 12 additions and 0 deletions
  1. 12 0
      src/components/Forum/index.tsx

+ 12 - 0
src/components/Forum/index.tsx

@@ -23,6 +23,18 @@ class Forum extends React.Component<IProps, IState> {
     this.state = { categoryId: 0, threadId: 0, postId: 0 };
     this.selectCategory = this.selectCategory.bind(this);
     this.selectThread = this.selectThread.bind(this);
+    this.handleKeyDown = this.handleKeyDown.bind(this);
+  }
+
+  componentDidMount() {
+    document.addEventListener("keydown", this.handleKeyDown);
+  }
+
+  handleKeyDown(event: { key: string }) {
+    const { key } = event;
+    if (key !== "Escape") return;
+    if (this.state.threadId) return this.selectThread(0);
+    if (this.state.categoryId) return this.selectCategory(0);
   }
 
   selectCategory(categoryId: number) {