Dynamic and Accessible Context Menu
In Livspace's intuitive design platform, users frequently interact with various elements—be it furniture pieces, wall sections, or design components. Providing quick, context-sensitive actions for these elements is paramount for an efficient workflow. A robust and accessible context menu significantly enhances user productivity by offering relevant operations directly at the point of interaction. This problem challenges you to build a reusable and accessible ContextMenu component that mirrors this critical platform functionality.
Your primary task is to develop a functional and accessible ContextMenu component in React/TypeScript. Specifically, you must:
ContextMenu component: This component should be a standalone, reusable UI element.div) is right-clicked.ContextMenu component must accept an array of menu item objects, each specifying a label and an action to be performed.(x, y) coordinates of the mouse click that triggered it.Escape key is pressed.ArrowUp and ArrowDown keys.Enter when an item is focused should trigger its associated action and close the menu.divs with a border/shadow).role="menu", role="menuitem") to be perceivable and operable by assistive technologies.target-area successfully opens the context menu.action and closes the menu.Escape key closes the context menu when it is open.ArrowUp and ArrowDown keys allow navigation between menu items, visually indicating the focused item.Enter on a focused menu item triggers its action and closes the menu.ContextMenu component is modular and reusable, accepting items, x, y, onClose, and onItemClick as props.Constraints
ContextMenu component is structured and its reusability across different parts of an application.contextmenu, click, keydown).Loading editor...