Context Menu
A long press on an element lifts it and opens a menu of actions beside it, while the rest of the screen dims, as on iOS 26.
Installation
Usage
- The items are the menu, and everything else inside
<ui-context-menu>is the element it opens from: here, the card. - A long press opens it. A tap still reaches the element: Lynx tells a tap from a long press.
- The phone taps as it opens from a long press, with
LynxHaptics. Opening it from code doesn't. - Choosing an item emits its
pressed, then closes the menu. A tap outside the menu, or Android's back button, closes it without choosing. - The menu opens below the element, or above it near the bottom of the screen. When it fits on neither side, the element moves up to make room, as on iOS.
[(open)]opens and closes it from code.disabledturns the long press off.
The items, sections, separators and submenus are the Menu's: icons, check marks, destructive and disabled items, titled sections and submenus all work here too.
On iOS, the finger that long-pressed can slide on onto an item and lift to choose it, as in UIKit. Android's menus wait for a tap.
What each platform draws
The lifted element
The element that lifts is the element itself, not a copy or a picture of it. The context menu moves it into the menu's overlay, at the same spot on screen, above the dimming layer, and scales it up a little. When the menu closes, it goes back. Meanwhile the space it left keeps its size, so the page doesn't move.
So the element looks exactly as it did and stays live: a tap on it still runs its own handler, and closes the menu.
Match swipe actions
Apple asks for a context menu's first actions to match the swipe actions of the row it's on, if the row has any, so the two ways to reach an action agree. A mail row that swipes to Archive and Delete offers Archive and Delete first in its context menu.
API
UiContextMenu
The items' API is on the Menu page.
Accessibility
- VoiceOver and TalkBack open it with a double-tap and hold, their long press.
- When the menu opens, a screen reader moves into it and stays inside until it closes. Each item is a button named by its label, and a destructive one reads as "Delete, destructive".
- Reduce Motion: the element doesn't scale, and the menu doesn't grow. They appear in place, and the dimming and the items fade in.
- Reduce Transparency and Increase Contrast apply as on all glass.
Related
- Menu: the same menu, opened by a tap on a button
- Glass: the material the menu is drawn with
- Action Sheet: a list of actions from the bottom of the screen
- Events:
bindtapandbindlongpress
