Build an accessible dropdown menu as a single React component: a trigger button that reveals a list of actions and hides it again. The interesting part isn't the open/close toggle — it's everything that should dismiss the menu (a click outside, the Escape key, choosing an item) and moving a keyboard highlight through the options. It's the same pattern behind every account menu, kebab menu, and select in real apps.
The starter App.tsx renders the trigger with the menu closed. Make it interactive:
open with useState. Clicking the trigger flips it; the <ul role="menu"> renders only when open is true, and aria-expanded mirrors it.useEffect and clean them up.activeIndex highlight through the four items (wrapping at the ends); Enter or Space activates the active item and closes the menu.onClick can't see clicks elsewhere; you listen on document and check whether the target is inside the wrapper.useEffect keyed on open adds the listeners when the menu opens and removes them when it closes or unmounts — no leaks.aria-haspopup="menu" and aria-expanded; the list is role="menu" and each item role="menuitem".styles.css; focus on the state and the listeners.