[FEATURE] Extract input text from kmenu search textbox
Closed this issue ยท 2 comments
Is your feature request related to a problem? Please describe.
While implementing features like full-text search, where I had to match conditionally to show commands, a way to extract the current input from the command palette would be the only way possible. Currently, this could be done in a hack-y way, but having a hook for this would be awesome.
Describe the solution you'd like
I'd like to have a hook with a similar functionality:
import { useState, useMemo } from "react";
import { Palette, Command } from "kmenu";
import "kmenu/dist/index.css";
import { usePaletteCommands, usePaletteConfig } from "./config";
import { useTheme } from "next-themes";
const Cmd = () => {
const [open, setOpen] = useState(0);
const { theme } = useTheme();
// ๐ This is what I'd want to extract
const { inputText } = useKMenu()
const commands = [(myTextContent.includes(inputText) && {
text: myTextContent.title,
// Since kmenu doesn't support isAlwaysShown property or something,
// so the line below ensures this command is always visible
keywords: ` ${inputText} `
icon: <Search />,
category: 'Search Results'
})]
const config = usePaletteConfig();
const categories: string[] = ["Utility", "Links"];
return (
<Palette
open={open}
setOpen={setOpen}
index={1}
commands={commands}
config={config}
categories={categories}
main
/>
);
};
export default Cmd;
Describe alternatives you've considered
I've considered targeting the text-field element using selectors, but it is, obviously, a hack-y way to do it and may break in future
Additional context
None
Awesome, so basically a way to gather input text. I've added this to the v1.0.0 release milestone, thanks for sharing ๐ฏ
Closing as this has been fixed with the addition of the useKmenu
hook in the upcoming 1.0.0 update ๐พ