From 2eda13afdaf61aad5e1884b193a8f73bb5c57465 Mon Sep 17 00:00:00 2001 From: Manmohan Dwivedi <76547210+Manmohan11@users.noreply.github.com> Date: Fri, 21 Oct 2022 21:57:06 +0530 Subject: [PATCH] feat: keyboard shortcut for seachbox (#1971) * keyboard shortcut added for seachbox * reverted changes in package-lock.json --- src/Components/Home.js | 11 ++++++++++- src/Components/Search/Searchbar.js | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Components/Home.js b/src/Components/Home.js index c3aa9d856b9..6ff7e58d80d 100644 --- a/src/Components/Home.js +++ b/src/Components/Home.js @@ -5,6 +5,15 @@ import Navbar from './Navbar' import GetIcons from './Icons/GetIcons' import { useTheme } from '../ThemeContext' +document.addEventListener('keydown', (e) => { + e = e || window.event + const searchbox = document.getElementById('search-button') + if (e.key === 'k' && e.ctrlKey) { + searchbox.click() + e.preventDefault() + } +}) + function Home() { const darkTheme = useTheme() @@ -13,7 +22,7 @@ function Home() {
+ { + e = e || window.event + const searchbox = document.getElementById('search-input') + if (e.key === 'k' && e.ctrlKey) { + searchbox.focus() + e.preventDefault() + } +}) + const Searchbar = ({ searchHandler, searchTerm }) => { const darkTheme = useTheme()