Dynamic Context Menu for List Items
In modern web applications, context menus provide a quick and intuitive way for users to perform actions on specific elements without navigating away. For instance, in a file management system or a data table, right-clicking an item reveals a set of relevant operations. This problem challenges you to build a dynamic context menu for a list of items, replicating a common UI pattern found across many applications.
Your task is to implement a React component that displays a list of items. Each item should be interactable via a custom context menu.
App.tsx.contextmenu event) on any list item, a custom context menu should appear.Escape key is pressed.alert should be triggered displaying the action name and the ID of the item on which the context menu was opened (e.g., "Action: Edit on Item ID: 1").ul/li or divs).div with a background color and border) containing the action buttons/links.alert.alert with the action name and the ID of the associated item.Escape key closes the context menu.Constraints
App.tsx.aria attributes for screen readers, tab navigation within the menu).contextmenu, click, and keydown events for display, positioning, and dismissal.useState and useEffect hooks to manage menu visibility, position, and the currently active item.Loading editor...