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

keyboard shortcut added for seachbox #1971

Merged
merged 3 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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