Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
feat: keyboard shortcut for seachbox (#1971)
Browse files Browse the repository at this point in the history
* keyboard shortcut added for seachbox

* reverted changes in package-lock.json
  • Loading branch information
Manmohan11 authored Oct 21, 2022
1 parent 6d96c37 commit 2eda13a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Components/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -13,7 +22,7 @@ function Home() {
<header>
<Navbar
start={
<Link to="/search" aria-label="Search">
<Link id="search-button" to="/search" aria-label="Search">
<GetIcons
iconName="search"
className={`${darkTheme ? 'text-white' : 'text-gray-900'}`}
Expand Down
9 changes: 9 additions & 0 deletions src/Components/Search/Searchbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import GetIcons from '../Icons/GetIcons'
import './Search.css'
import { useTheme } from '../../ThemeContext'

document.addEventListener('keydown', (e) => {
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()

Expand Down

0 comments on commit 2eda13a

Please sign in to comment.