You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Find an exhaustive collection of icons currently used in DevTools [here](https://drive.google.com/corp/drive/folders/1EpmxLRjvdHn5Ia8iT3aicgIEPEvhXY_D?resourcekey=0-QseNsNRsF4w8F5EKz7ncnA)
274
274
@@ -299,3 +299,188 @@ Usage with the imperative API:

306
+
307
+
Context Menu allows us to display contextual actions to the user, typically triggered by a right-click or via a dedicated menu button.
308
+
309
+
### General information
310
+
311
+
#### ContextMenu Class
312
+
313
+
The primary class for creating and managing context menus.
314
+
It can render as a "soft" menu (custom HTML-based implementation, offering extra functionality like keeping the menu open) or a native menu. The preferred and default way is the native menu, soft menu should ONLY be used in exceptional cases where native menu lacks features.
315
+
Typically instantiated in response to a user event (e.g. contextmenu mouse event).
316
+
317
+
#### Item Class
318
+
319
+
Represents an individual entry within a context menu.
320
+
Types:
321
+
* 'item': A standard clickable menu item.
322
+
* 'checkbox': An item that can be toggled on or off.
323
+
* 'separator': A visual line to group related items.
324
+
Items can have labels, handlers, be enabled/disabled. Optionally can also display shortcuts or tooltips (both are exceptions and not recommended).
325
+
326
+
#### Section Class
327
+
328
+
Groups related Items within a ContextMenu or SubMenu.
329
+
Helps organize the menu structure and often introduces visual separation.
330
+
Predefined section names (e.g. 'header', 'clipboard', 'default', 'footer') are available on ContextMenu and SubMenu instances.
331
+
332
+
#### SubMenu Class
333
+
334
+
A special type of Item that, when clicked or hovered, opens another nested menu.
335
+
SubMenus contain their own Sections and Items, allowing for hierarchical menu structures.
336
+
337
+
#### MenuButton Component
338
+
339
+
A custom HTML element (`<devtools-menu-button>`) that renders as a button (currently an icon button only, though we plan to extend it to text buttons too).
340
+
When clicked, it instantiates and displays a ContextMenu.
341
+
Configured via HTML attributes (e.g. `icon-name`, `title`) and a `populateMenuCall` property to define the menu's content.
342
+
343
+
344
+
#### Providers
345
+
346
+
A mechanism to dynamically add context-specific menu items.
347
+
Providers are registered with `ContextMenu.registerProvider()` and are associated with specific object types.
348
+
When a context menu is shown for a particular target object, relevant providers are invoked to append their items.
349
+
350
+
351
+
#### Registered Items
352
+
353
+
A way to add menu items (linked to actions from the `ActionRegistry`) to predefined locations within the DevTools UI (e.g. the main menu, navigator context menus).
354
+
Items are registered using `ContextMenu.registerItem()` with a specific `ItemLocation`.
355
+
356
+
### Usage
357
+
358
+
#### Design Guidelines
359
+
360
+
Generally, we do not recommend using shortcuts in context menus since this goes against Mac platform guidelines and we do not want to have them on some platforms, but not the others. Try to find an alternative solution, however if none is possible and showing shortcuts is critical for a smooth user flow, reach out to kimanh@ or kprokopenko@.
361
+
362
+
#### Developer guidelines
363
+
364
+
##### Dos and Don'ts
365
+
366
+
###### Do
367
+
368
+
* Use `new ContextMenu(event, options?)` to create and show menus in response to user interactions (e.g. contextmenu event on an element).
369
+
* Use `<devtools-menu-button>` to create buttons that should trigger a context menu.
370
+
371
+
###### Don't
372
+
373
+
* Forget to call `contextMenu.show()` after populating the menu; otherwise, it won't open.
374
+
375
+
##### Developer examples
376
+
377
+
Usage with lit-html (left-click on a `<devtools-menu-button>` opens a menu):
0 commit comments