Pressing CTRL + F now focuses the search bar
This commit is contained in:
parent
25c9d62cf2
commit
afa721f7f7
@ -4,18 +4,31 @@ import "./styles.sass";
|
|||||||
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
||||||
import {faSearch} from "@fortawesome/free-solid-svg-icons";
|
import {faSearch} from "@fortawesome/free-solid-svg-icons";
|
||||||
import {routes} from "@/common/routes";
|
import {routes} from "@/common/routes";
|
||||||
|
import {useEffect, useRef} from "react";
|
||||||
|
|
||||||
export const SidebarContent = () => {
|
export const SidebarContent = () => {
|
||||||
|
const searchRef = useRef();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const listener = (e) => {
|
||||||
|
if (e.keyCode === 114 || (e.ctrlKey && e.keyCode === 70)) {
|
||||||
|
e.preventDefault();
|
||||||
|
searchRef.current.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("keydown", listener);
|
||||||
|
return () => document.removeEventListener("keydown", listener);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="sidebar-content">
|
<div className="sidebar-content">
|
||||||
<div className="search-item">
|
<div className="search-item">
|
||||||
<FontAwesomeIcon icon={faSearch}/>
|
<FontAwesomeIcon icon={faSearch}/>
|
||||||
<input type="text" placeholder="Tool suchen..."/>
|
<input type="text" placeholder="Tool suchen..." ref={searchRef}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div className="power-item-area">
|
<div className="power-item-area">
|
||||||
|
|
||||||
{Object.keys(routes).map((route) => (
|
{Object.keys(routes).map((route) => (
|
||||||
<PowerItemGroup name={route} key={route}>
|
<PowerItemGroup name={route} key={route}>
|
||||||
{routes[route].map((route) => (
|
{routes[route].map((route) => (
|
||||||
|
Reference in New Issue
Block a user