Interactive Command Palette
Modern web applications often provide a "command palette" — a powerful modal interface that allows users to quickly search for and execute actions using just their keyboard. This enhances productivity by reducing reliance on mouse navigation. In this problem, you will build a simplified command palette component for a hypothetical dashboard application.
This exercise assesses your ability to manage component state, handle keyboard events, and implement interactive UI elements in React.
Your goal is to implement a CommandPalette component that fulfills the following requirements:
Ctrl+K (or Cmd+K on macOS) anywhere on the page.App.tsx).Up and Down arrow keys. The currently highlighted item should have a distinct visual style.Enter, the associated action for that command should be executed (for this problem, a simple console.log is sufficient). After execution, the palette should close.Escape key.Ctrl+K / Cmd+K.Up and Down arrow keys correctly change the highlighted command item.Enter on a highlighted command executes its action and closes the palette.Escape closes the palette without executing any command.Constraints
MOCK_COMMANDS) should be used.Loading editor...