The New Way to Build with AI! Introducing ReUI — the developer platform for agentic UI with shadcn/ui
Browse ReUI Pro

Keyboard shortcut for search


How to implement a keyboard shortcut for the search dropdown in the support forum theme react version?


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (2)

 
Deleted comment
 
Deleted comment
 
Deleted comment

Hi,

Sorry for the late reply.

If you're using our MenuComponent, you can display and hide the menu using the component's show and hide functions.

Here is an example:

useEffect(() => {
setTimeout(()=>{
if(!searchEl.current){
return;
}

const menuInst = MenuComponent.getInstance(searchEl.current);

const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === "/") {
menuInst?.show(searchEl.current!);
event.preventDefault();
}
};

document.addEventListener("keydown", handleKeyDown);
})
}, []);


Regards,
Lauris Stepanovs,
Keenthemes Support Team



I build similar and here is a basic example (you have to customize this to your needs

import React, { useState, useEffect } from "react";

const Search = () => {
const [isDropdownVisible, setDropdownVisible] = useState(false);

useEffect(() => {

document.addEventListener("keydown", handleKeyDown);


return () => {
document.removeEventListener("keydown", handleKeyDown);
};
}, []);

const handleKeyDown = (event) => {
// Check if the "/" key is pressed
if (event.key === "/") {
event.preventDefault();
toggleDropdown();
}
};

const toggleDropdown = () => {
setDropdownVisible(!isDropdownVisible);
};

return (
<div>
<input
type="text"
placeholder="Search..."
onFocus={() => setDropdownVisible(true)}
onBlur={() => setDropdownVisible(false)}
/>
{isDropdownVisible && (
<div className="search-dropdown">
{/* Dropdown content goes here */}
<p>Dropdown Content</p>
</div>
)}
</div>
);
};

export default Search;


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
buy metronic keenthemes mega bundle

ReUI

Open-source React components, blocks and templates built on shadcn/ui and Tailwind CSS by Keenthemes.