Implement a Command Palette with Keyboard Navigation
Modern applications often feature a command palette, a powerful interface that allows users to quickly search for and execute actions without navigating through complex menus. This significantly boosts productivity and enhances the user experience, making applications more accessible and efficient. For instance, tools like VS Code or Notion heavily rely on command palettes for quick feature access.
This problem challenges you to build a foundational command palette component, focusing on core keyboard navigation and filtering capabilities, simulating a feature that would be essential in a rich client-side application like a document editor.
Your goal is to implement a CommandPalette component that meets the following requirements:
Cmd/Ctrl + K) to open the command palette.ArrowUp and ArrowDown keys.ArrowUp from the first item moves to the last, and ArrowDown from the last item moves to the first).Enter key while a command is selected should "execute" it. For this problem, "execution" means logging the command's id and name to the console.Escape key is pressed or when the user clicks outside the palette modal.Cmd/Ctrl + K is pressed anywhere on the page.Escape is pressed or when a click occurs outside the palette modal.ArrowUp and ArrowDown keys correctly navigate through the filtered commands, with visual selection feedback.Enter on a selected command logs its id and name to the browser console.Constraints
Loading editor...