@vaadin/context-menu 24.8.4 → 25.0.0-alpha10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +0 -23
  2. package/package.json +16 -17
  3. package/src/styles/vaadin-context-menu-item-base-styles.d.ts +8 -0
  4. package/src/styles/vaadin-context-menu-item-base-styles.js +34 -0
  5. package/src/styles/vaadin-context-menu-item-core-styles.d.ts +8 -0
  6. package/src/styles/vaadin-context-menu-item-core-styles.js +8 -0
  7. package/src/styles/vaadin-context-menu-overlay-base-styles.d.ts +8 -0
  8. package/src/styles/vaadin-context-menu-overlay-base-styles.js +9 -0
  9. package/src/styles/vaadin-context-menu-overlay-core-styles.d.ts +8 -0
  10. package/src/styles/vaadin-context-menu-overlay-core-styles.js +9 -0
  11. package/src/{vaadin-menu-overlay-styles.d.ts → styles/vaadin-menu-overlay-base-styles.d.ts} +1 -1
  12. package/src/styles/vaadin-menu-overlay-base-styles.js +31 -0
  13. package/src/styles/vaadin-menu-overlay-core-styles.d.ts +8 -0
  14. package/src/{vaadin-menu-overlay-styles.js → styles/vaadin-menu-overlay-core-styles.js} +1 -1
  15. package/src/vaadin-context-menu-item.js +11 -12
  16. package/src/vaadin-context-menu-list-box.d.ts +1 -2
  17. package/src/vaadin-context-menu-list-box.js +17 -26
  18. package/src/vaadin-context-menu-mixin.js +43 -70
  19. package/src/vaadin-context-menu-overlay.js +16 -11
  20. package/src/vaadin-context-menu.d.ts +15 -6
  21. package/src/vaadin-context-menu.js +44 -42
  22. package/src/vaadin-contextmenu-items-mixin.js +19 -15
  23. package/src/vaadin-menu-overlay-mixin.d.ts +0 -5
  24. package/src/vaadin-menu-overlay-mixin.js +22 -27
  25. package/web-types.json +6 -2
  26. package/web-types.lit.json +9 -2
  27. package/src/vaadin-lit-context-menu-item.js +0 -60
  28. package/src/vaadin-lit-context-menu-list-box.js +0 -87
  29. package/src/vaadin-lit-context-menu-overlay.js +0 -51
  30. package/src/vaadin-lit-context-menu.js +0 -79
  31. package/theme/lumo/vaadin-lit-context-menu.d.ts +0 -4
  32. package/theme/lumo/vaadin-lit-context-menu.js +0 -4
  33. package/theme/material/vaadin-context-menu-item-styles.d.ts +0 -5
  34. package/theme/material/vaadin-context-menu-item-styles.js +0 -36
  35. package/theme/material/vaadin-context-menu-list-box-styles.d.ts +0 -4
  36. package/theme/material/vaadin-context-menu-list-box-styles.js +0 -38
  37. package/theme/material/vaadin-context-menu-overlay-styles.d.ts +0 -2
  38. package/theme/material/vaadin-context-menu-overlay-styles.js +0 -15
  39. package/theme/material/vaadin-context-menu.d.ts +0 -4
  40. package/theme/material/vaadin-context-menu.js +0 -4
  41. package/theme/material/vaadin-lit-context-menu.d.ts +0 -4
  42. package/theme/material/vaadin-lit-context-menu.js +0 -4
  43. package/vaadin-lit-context-menu.d.ts +0 -1
  44. package/vaadin-lit-context-menu.js +0 -2
@@ -34,6 +34,11 @@ export type ContextMenuItemSelectedEvent<TItem extends ContextMenuItem = Context
34
34
  value: TItem;
35
35
  }>;
36
36
 
37
+ /**
38
+ * Fired when the context menu is closed.
39
+ */
40
+ export type ContextMenuClosedEvent = CustomEvent;
41
+
37
42
  export interface ContextMenuCustomEventMap<TItem extends ContextMenuItem = ContextMenuItem> {
38
43
  'opened-changed': ContextMenuOpenedChangedEvent;
39
44
 
@@ -42,6 +47,8 @@ export interface ContextMenuCustomEventMap<TItem extends ContextMenuItem = Conte
42
47
  'close-all-menus': Event;
43
48
 
44
49
  'items-outside-click': Event;
50
+
51
+ closed: ContextMenuClosedEvent;
45
52
  }
46
53
 
47
54
  export interface ContextMenuEventMap<TItem extends ContextMenuItem = ContextMenuItem>
@@ -208,18 +215,19 @@ export interface ContextMenuEventMap<TItem extends ContextMenuItem = ContextMenu
208
215
  *
209
216
  * ### Styling
210
217
  *
211
- * `<vaadin-context-menu>` uses `<vaadin-context-menu-overlay>` internal
212
- * themable component as the actual visible context menu overlay.
218
+ * The following shadow DOM parts are available for styling:
213
219
  *
214
- * See [`<vaadin-overlay>`](#/elements/vaadin-overlay)
215
- * documentation for `<vaadin-context-menu-overlay>` stylable parts.
220
+ * Part name | Description
221
+ * -----------------|-------------------------------------------
222
+ * `backdrop` | Backdrop of the overlay
223
+ * `overlay` | The overlay container
224
+ * `content` | The overlay content
216
225
  *
217
226
  * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
218
227
  *
219
228
  * ### Internal components
220
229
  *
221
- * When using `items` API, in addition `<vaadin-context-menu-overlay>`, the following
222
- * internal components are themable:
230
+ * When using `items` API the following internal components are themable:
223
231
  *
224
232
  * - `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](#/elements/vaadin-item).
225
233
  * - `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](#/elements/vaadin-list-box).
@@ -236,6 +244,7 @@ export interface ContextMenuEventMap<TItem extends ContextMenuItem = ContextMenu
236
244
  *
237
245
  * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
238
246
  * @fires {CustomEvent} item-selected - Fired when an item is selected when the context menu is populated using the `items` API.
247
+ * @fires {CustomEvent} closed - Fired when the context menu is closed.
239
248
  */
240
249
  declare class ContextMenu<TItem extends ContextMenuItem = ContextMenuItem> extends HTMLElement {
241
250
  addEventListener<K extends keyof ContextMenuEventMap>(
@@ -7,12 +7,12 @@ import './vaadin-contextmenu-event.js';
7
7
  import './vaadin-context-menu-item.js';
8
8
  import './vaadin-context-menu-list-box.js';
9
9
  import './vaadin-context-menu-overlay.js';
10
- import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
11
- import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
10
+ import { css, html, LitElement } from 'lit';
11
+ import { ifDefined } from 'lit/directives/if-defined.js';
12
12
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
13
13
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
14
14
  import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
15
- import { processTemplates } from '@vaadin/component-base/src/templates.js';
15
+ import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
16
16
  import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
17
17
  import { ContextMenuMixin } from './vaadin-context-menu-mixin.js';
18
18
 
@@ -176,18 +176,19 @@ import { ContextMenuMixin } from './vaadin-context-menu-mixin.js';
176
176
  *
177
177
  * ### Styling
178
178
  *
179
- * `<vaadin-context-menu>` uses `<vaadin-context-menu-overlay>` internal
180
- * themable component as the actual visible context menu overlay.
179
+ * The following shadow DOM parts are available for styling:
181
180
  *
182
- * See [`<vaadin-overlay>`](#/elements/vaadin-overlay)
183
- * documentation for `<vaadin-context-menu-overlay>` stylable parts.
181
+ * Part name | Description
182
+ * -----------------|-------------------------------------------
183
+ * `backdrop` | Backdrop of the overlay
184
+ * `overlay` | The overlay container
185
+ * `content` | The overlay content
184
186
  *
185
187
  * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
186
188
  *
187
189
  * ### Internal components
188
190
  *
189
- * When using `items` API, in addition `<vaadin-context-menu-overlay>`, the following
190
- * internal components are themable:
191
+ * When using `items` API the following internal components are themable:
191
192
  *
192
193
  * - `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](#/elements/vaadin-item).
193
194
  * - `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](#/elements/vaadin-list-box).
@@ -204,56 +205,57 @@ import { ContextMenuMixin } from './vaadin-context-menu-mixin.js';
204
205
  *
205
206
  * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
206
207
  * @fires {CustomEvent} item-selected - Fired when an item is selected when the context menu is populated using the `items` API.
208
+ * @fires {CustomEvent} closed - Fired when the context menu is closed.
207
209
  *
208
210
  * @customElement
209
211
  * @extends HTMLElement
210
212
  * @mixes ElementMixin
211
213
  * @mixes ContextMenuMixin
212
- * @mixes ControllerMixin
213
214
  * @mixes OverlayClassMixin
214
215
  * @mixes ThemePropertyMixin
215
216
  */
216
217
  class ContextMenu extends ContextMenuMixin(
217
- OverlayClassMixin(ControllerMixin(ElementMixin(ThemePropertyMixin(PolymerElement)))),
218
+ OverlayClassMixin(ElementMixin(ThemePropertyMixin(PolylitMixin(LitElement)))),
218
219
  ) {
219
- static get template() {
220
- return html`
221
- <style>
222
- :host {
223
- display: block;
224
- }
225
-
226
- :host([hidden]) {
227
- display: none !important;
228
- }
229
- </style>
230
-
231
- <slot id="slot"></slot>
232
- `;
233
- }
234
-
235
220
  static get is() {
236
221
  return 'vaadin-context-menu';
237
222
  }
238
223
 
239
- /** @protected */
240
- ready() {
241
- super.ready();
224
+ static get styles() {
225
+ return css`
226
+ :host {
227
+ display: block;
228
+ }
242
229
 
243
- processTemplates(this);
230
+ :host([hidden]) {
231
+ display: none !important;
232
+ }
233
+ `;
244
234
  }
245
235
 
246
- /**
247
- * @param {DocumentFragment} dom
248
- * @return {null}
249
- * @protected
250
- * @override
251
- */
252
- _attachDom(dom) {
253
- const root = this.attachShadow({ mode: 'open' });
254
- root.appendChild(dom);
255
- root.appendChild(this._overlayElement);
256
- return root;
236
+ /** @protected */
237
+ render() {
238
+ return html`
239
+ <slot id="slot"></slot>
240
+ <vaadin-context-menu-overlay
241
+ id="overlay"
242
+ .owner="${this}"
243
+ .opened="${this.opened}"
244
+ .model="${this._context}"
245
+ .modeless="${this._modeless}"
246
+ .renderer="${this.items ? this.__itemsRenderer : this.renderer}"
247
+ .withBackdrop="${this._phone}"
248
+ ?phone="${this._phone}"
249
+ theme="${ifDefined(this._theme)}"
250
+ exportparts="backdrop, overlay, content"
251
+ @opened-changed="${this._onOverlayOpened}"
252
+ @vaadin-overlay-open="${this._onVaadinOverlayOpen}"
253
+ @vaadin-overlay-closed="${this._onVaadinOverlayClosed}"
254
+ >
255
+ <slot name="overlay"></slot>
256
+ <slot name="submenu" slot="submenu"></slot>
257
+ </vaadin-context-menu-overlay>
258
+ `;
257
259
  }
258
260
 
259
261
  /**
@@ -116,10 +116,10 @@ export const ItemsMixin = (superClass) =>
116
116
  /** @protected */
117
117
  __forwardFocus() {
118
118
  const overlay = this._overlayElement;
119
- const child = overlay.getFirstChild();
119
+ const child = overlay._contentRoot.firstElementChild;
120
120
  // If parent item is not focused, do not focus submenu
121
121
  if (overlay.parentOverlay) {
122
- const parent = overlay.parentOverlay.querySelector('[expanded]');
122
+ const parent = overlay.parentOverlay._contentRoot.querySelector('[expanded]');
123
123
  if (parent && parent.hasAttribute('focused') && child) {
124
124
  child.focus();
125
125
  } else {
@@ -253,10 +253,20 @@ export const ItemsMixin = (superClass) =>
253
253
  // Open a submenu on click event when a touch device is used.
254
254
  // On desktop, a submenu opens on hover.
255
255
  overlay.addEventListener(isTouch ? 'click' : 'mouseover', (event) => {
256
+ // Ignore events from the submenus
257
+ if (event.composedPath().includes(this._subMenu)) {
258
+ return;
259
+ }
260
+
256
261
  this.__showSubMenu(event);
257
262
  });
258
263
 
259
264
  overlay.addEventListener('keydown', (event) => {
265
+ // Ignore events from the submenus
266
+ if (event.composedPath().includes(this._subMenu)) {
267
+ return;
268
+ }
269
+
260
270
  const { key } = event;
261
271
  const isRTL = this.__isRTL;
262
272
 
@@ -288,10 +298,6 @@ export const ItemsMixin = (superClass) =>
288
298
  subMenu._modeless = true;
289
299
  subMenu.openOn = 'opensubmenu';
290
300
 
291
- // Sub-menu doesn't have a target to wrap,
292
- // so there is no need to keep it visible.
293
- subMenu.setAttribute('hidden', '');
294
-
295
301
  // Close sub-menu when the parent menu closes.
296
302
  this.addEventListener('opened-changed', (event) => {
297
303
  if (!event.detail.value) {
@@ -366,7 +372,7 @@ export const ItemsMixin = (superClass) =>
366
372
  const { children } = item._item;
367
373
 
368
374
  // Check if the sub-menu was focused before closing it.
369
- const child = subMenu._overlayElement.getFirstChild();
375
+ const child = subMenu._overlayElement._contentRoot.firstElementChild;
370
376
  const isSubmenuFocused = child && child.focused;
371
377
 
372
378
  if (subMenu.items !== children) {
@@ -394,7 +400,7 @@ export const ItemsMixin = (superClass) =>
394
400
 
395
401
  /** @protected */
396
402
  __getListBox() {
397
- return this._overlayElement.querySelector(`${this._tagNamePrefix}-list-box`);
403
+ return this._overlayElement._contentRoot.querySelector(`${this._tagNamePrefix}-list-box`);
398
404
  }
399
405
 
400
406
  /**
@@ -406,15 +412,12 @@ export const ItemsMixin = (superClass) =>
406
412
  __itemsRenderer(root, menu) {
407
413
  this.__initMenu(root, menu);
408
414
 
409
- const subMenu = root.querySelector(this.constructor.is);
410
- subMenu.closeOn = menu.closeOn;
411
-
412
- const listBox = this.__getListBox();
413
- listBox.innerHTML = '';
415
+ this._subMenu.closeOn = menu.closeOn;
416
+ this._listBox.innerHTML = '';
414
417
 
415
418
  menu.items.forEach((item) => {
416
419
  const component = this.__createComponent(item);
417
- listBox.appendChild(component);
420
+ this._listBox.appendChild(component);
418
421
  });
419
422
  }
420
423
 
@@ -455,8 +458,9 @@ export const ItemsMixin = (superClass) =>
455
458
  root.appendChild(listBox);
456
459
 
457
460
  const subMenu = this.__initSubMenu();
461
+ subMenu.slot = 'submenu';
458
462
  this._subMenu = subMenu;
459
- root.appendChild(subMenu);
463
+ this.appendChild(subMenu);
460
464
 
461
465
  requestAnimationFrame(() => {
462
466
  this.__openListenerActive = true;
@@ -18,9 +18,4 @@ export declare class MenuOverlayMixinClass {
18
18
  * Returns the adjusted boundaries of the overlay.
19
19
  */
20
20
  getBoundaries(): { xMax: number; xMin: number; yMax: number };
21
-
22
- /**
23
- * Returns the first element in the overlay content.
24
- */
25
- getFirstChild(): HTMLElement;
26
21
  }
@@ -3,7 +3,6 @@
3
3
  * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { getClosestElement } from '@vaadin/component-base/src/dom-utils.js';
7
6
  import { OverlayFocusMixin } from '@vaadin/overlay/src/vaadin-overlay-focus-mixin.js';
8
7
  import { PositionMixin } from '@vaadin/overlay/src/vaadin-overlay-position-mixin.js';
9
8
 
@@ -37,6 +36,23 @@ export const MenuOverlayMixin = (superClass) =>
37
36
  return ['_themeChanged(_theme)'];
38
37
  }
39
38
 
39
+ /**
40
+ * Override method from OverlayFocusMixin to use slotted div as the content root.
41
+ * @protected
42
+ * @override
43
+ */
44
+ get _contentRoot() {
45
+ if (!this.__savedRoot) {
46
+ const root = document.createElement('div');
47
+ root.setAttribute('slot', 'overlay');
48
+ root.style.display = 'contents';
49
+ this.owner.appendChild(root);
50
+ this.__savedRoot = root;
51
+ }
52
+
53
+ return this.__savedRoot;
54
+ }
55
+
40
56
  /** @protected */
41
57
  ready() {
42
58
  super.ready();
@@ -45,7 +61,7 @@ export const MenuOverlayMixin = (superClass) =>
45
61
 
46
62
  this.addEventListener('keydown', (e) => {
47
63
  if (!e.defaultPrevented && e.composedPath()[0] === this.$.overlay && [38, 40].indexOf(e.keyCode) > -1) {
48
- const child = this.getFirstChild();
64
+ const child = this._contentRoot.firstElementChild;
49
65
  if (child && Array.isArray(child.items) && child.items.length) {
50
66
  e.preventDefault();
51
67
  if (e.keyCode === 38) {
@@ -58,15 +74,6 @@ export const MenuOverlayMixin = (superClass) =>
58
74
  });
59
75
  }
60
76
 
61
- /**
62
- * Returns the first element in the overlay content.
63
- *
64
- * @returns {HTMLElement}
65
- */
66
- getFirstChild() {
67
- return this.querySelector(':not(style):not(slot)');
68
- }
69
-
70
77
  /** @private */
71
78
  _themeChanged() {
72
79
  this.close();
@@ -149,9 +156,9 @@ export const MenuOverlayMixin = (superClass) =>
149
156
  }
150
157
 
151
158
  /**
152
- * Override method inherited from `OverlayFocusMixin` to return
153
- * true if the overlay contains the given node, including
154
- * those within descendant menu overlays.
159
+ * Override method inherited from `OverlayFocusMixin` to check if the
160
+ * node is contained within the overlay's owner element (the menu),
161
+ * where all content (overlay content, sub-menus, etc.) is slotted.
155
162
  *
156
163
  * @protected
157
164
  * @override
@@ -159,18 +166,6 @@ export const MenuOverlayMixin = (superClass) =>
159
166
  * @return {boolean}
160
167
  */
161
168
  _deepContains(node) {
162
- // Find the closest menu overlay for the given node.
163
- let overlay = getClosestElement(this.localName, node);
164
- while (overlay) {
165
- if (overlay === this) {
166
- // The node is inside a descendant menu overlay.
167
- return true;
168
- }
169
-
170
- // Traverse the overlay hierarchy to check parent overlays.
171
- overlay = overlay.parentOverlay;
172
- }
173
-
174
- return false;
169
+ return this.owner.contains(node);
175
170
  }
176
171
  };
package/web-types.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/context-menu",
4
- "version": "24.8.4",
4
+ "version": "25.0.0-alpha10",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
8
8
  "elements": [
9
9
  {
10
10
  "name": "vaadin-context-menu",
11
- "description": "`<vaadin-context-menu>` is a Web Component for creating context menus.\n\n### Items\n\nItems is a higher level convenience API for defining a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nWhen an item is selected, `<vaadin-context-menu>` dispatches an \"item-selected\" event\nwith the selected item as `event.detail.value` property.\nIf item does not have `keepOpen` property the menu will be closed.\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n\ncontextMenu.addEventListener('item-selected', e => {\n const item = e.detail.value;\n console.log(`${item.text} selected`);\n});\n```\n\n**NOTE:** when the `items` array is defined, the renderer cannot be used.\n\n### Rendering\n\nThe content of the menu can be populated by using the renderer callback function.\n\nThe renderer function provides `root`, `contextMenu`, `model` arguments when applicable.\nGenerate DOM content by using `model` object properties if needed, append it to the `root`\nelement and control the state of the host element by accessing `contextMenu`. Before generating\nnew content, the renderer function should check if there is already content in `root` for reusing it.\n\n```html\n<vaadin-context-menu id=\"contextMenu\">\n <p>This paragraph has a context menu.</p>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'Content of the selector: ' + context.target.textContent;\n};\n```\n\nYou can access the menu context inside the renderer using\n`context.target` and `context.detail`.\n\nRenderer is called on the opening of the context-menu and each time the related context is updated.\nDOM generated during the renderer call can be reused\nin the next renderer call and will be provided with the `root` argument.\nOn first call it will be empty.\n\n### `vaadin-contextmenu` Gesture Event\n\n`vaadin-contextmenu` is a gesture event (a custom event),\nwhich is dispatched after either `contextmenu` or long touch events.\nThis enables support for both mouse and touch environments in a uniform way.\n\n`<vaadin-context-menu>` opens the menu overlay on the `vaadin-contextmenu`\nevent by default.\n\n### Menu Listener\n\nBy default, the `<vaadin-context-menu>` element listens for the menu opening\nevent on itself. In case if you do not want to wrap the target, you can listen for\nevents on an element outside the `<vaadin-context-menu>` by setting the\n`listenOn` property:\n\n```html\n<vaadin-context-menu id=\"contextMenu\"></vaadin-context-menu>\n\n<div id=\"menuListener\">The element that listens for the contextmenu event.</div>\n```\n```javascript\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.listenOn = document.querySelector('#menuListener');\n```\n\n### Filtering Menu Targets\n\nBy default, the listener element and all its descendants open the context\nmenu. You can filter the menu targets to a smaller set of elements inside\nthe listener element by setting the `selector` property.\n\nIn the following example, only the elements matching `.has-menu` will open the context menu:\n\n```html\n<vaadin-context-menu selector=\".has-menu\">\n <p class=\"has-menu\">This paragraph opens the context menu</p>\n <p>This paragraph does not open the context menu</p>\n</vaadin-context-menu>\n```\n\n### Menu Context\n\nThe following properties are available in the `context` argument:\n\n- `target` is the menu opening event target, which is the element that\nthe user has called the context menu for\n- `detail` is the menu opening event detail\n\nIn the following example, the menu item text is composed with the contents\nof the element that opened the menu:\n\n```html\n<vaadin-context-menu selector=\"li\" id=\"contextMenu\">\n <ul>\n <li>Foo</li>\n <li>Bar</li>\n <li>Baz</li>\n </ul>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'The menu target: ' + context.target.textContent;\n};\n```\n\n### Styling\n\n`<vaadin-context-menu>` uses `<vaadin-context-menu-overlay>` internal\nthemable component as the actual visible context menu overlay.\n\nSee [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.8.4/#/elements/vaadin-overlay)\ndocumentation for `<vaadin-context-menu-overlay>` stylable parts.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.\n\n### Internal components\n\nWhen using `items` API, in addition `<vaadin-context-menu-overlay>`, the following\ninternal components are themable:\n\n- `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.8.4/#/elements/vaadin-item).\n- `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/24.8.4/#/elements/vaadin-list-box).\n\nThe `<vaadin-context-menu-item>` sub-menu elements have the following additional state attributes\non top of the built-in `<vaadin-item>` state attributes:\n\nAttribute | Description\n---------- |-------------\n`expanded` | Expanded parent item.\n\nNote: the `theme` attribute value set on `<vaadin-context-menu>` is\npropagated to the internal components listed above.",
11
+ "description": "`<vaadin-context-menu>` is a Web Component for creating context menus.\n\n### Items\n\nItems is a higher level convenience API for defining a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nWhen an item is selected, `<vaadin-context-menu>` dispatches an \"item-selected\" event\nwith the selected item as `event.detail.value` property.\nIf item does not have `keepOpen` property the menu will be closed.\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n\ncontextMenu.addEventListener('item-selected', e => {\n const item = e.detail.value;\n console.log(`${item.text} selected`);\n});\n```\n\n**NOTE:** when the `items` array is defined, the renderer cannot be used.\n\n### Rendering\n\nThe content of the menu can be populated by using the renderer callback function.\n\nThe renderer function provides `root`, `contextMenu`, `model` arguments when applicable.\nGenerate DOM content by using `model` object properties if needed, append it to the `root`\nelement and control the state of the host element by accessing `contextMenu`. Before generating\nnew content, the renderer function should check if there is already content in `root` for reusing it.\n\n```html\n<vaadin-context-menu id=\"contextMenu\">\n <p>This paragraph has a context menu.</p>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'Content of the selector: ' + context.target.textContent;\n};\n```\n\nYou can access the menu context inside the renderer using\n`context.target` and `context.detail`.\n\nRenderer is called on the opening of the context-menu and each time the related context is updated.\nDOM generated during the renderer call can be reused\nin the next renderer call and will be provided with the `root` argument.\nOn first call it will be empty.\n\n### `vaadin-contextmenu` Gesture Event\n\n`vaadin-contextmenu` is a gesture event (a custom event),\nwhich is dispatched after either `contextmenu` or long touch events.\nThis enables support for both mouse and touch environments in a uniform way.\n\n`<vaadin-context-menu>` opens the menu overlay on the `vaadin-contextmenu`\nevent by default.\n\n### Menu Listener\n\nBy default, the `<vaadin-context-menu>` element listens for the menu opening\nevent on itself. In case if you do not want to wrap the target, you can listen for\nevents on an element outside the `<vaadin-context-menu>` by setting the\n`listenOn` property:\n\n```html\n<vaadin-context-menu id=\"contextMenu\"></vaadin-context-menu>\n\n<div id=\"menuListener\">The element that listens for the contextmenu event.</div>\n```\n```javascript\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.listenOn = document.querySelector('#menuListener');\n```\n\n### Filtering Menu Targets\n\nBy default, the listener element and all its descendants open the context\nmenu. You can filter the menu targets to a smaller set of elements inside\nthe listener element by setting the `selector` property.\n\nIn the following example, only the elements matching `.has-menu` will open the context menu:\n\n```html\n<vaadin-context-menu selector=\".has-menu\">\n <p class=\"has-menu\">This paragraph opens the context menu</p>\n <p>This paragraph does not open the context menu</p>\n</vaadin-context-menu>\n```\n\n### Menu Context\n\nThe following properties are available in the `context` argument:\n\n- `target` is the menu opening event target, which is the element that\nthe user has called the context menu for\n- `detail` is the menu opening event detail\n\nIn the following example, the menu item text is composed with the contents\nof the element that opened the menu:\n\n```html\n<vaadin-context-menu selector=\"li\" id=\"contextMenu\">\n <ul>\n <li>Foo</li>\n <li>Bar</li>\n <li>Baz</li>\n </ul>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'The menu target: ' + context.target.textContent;\n};\n```\n\n### Styling\n\nThe following shadow DOM parts are available for styling:\n\nPart name | Description\n-----------------|-------------------------------------------\n`backdrop` | Backdrop of the overlay\n`overlay` | The overlay container\n`content` | The overlay content\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.\n\n### Internal components\n\nWhen using `items` API the following internal components are themable:\n\n- `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/25.0.0-alpha10/#/elements/vaadin-item).\n- `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/25.0.0-alpha10/#/elements/vaadin-list-box).\n\nThe `<vaadin-context-menu-item>` sub-menu elements have the following additional state attributes\non top of the built-in `<vaadin-item>` state attributes:\n\nAttribute | Description\n---------- |-------------\n`expanded` | Expanded parent item.\n\nNote: the `theme` attribute value set on `<vaadin-context-menu>` is\npropagated to the internal components listed above.",
12
12
  "attributes": [
13
13
  {
14
14
  "name": "selector",
@@ -135,6 +135,10 @@
135
135
  }
136
136
  ],
137
137
  "events": [
138
+ {
139
+ "name": "closed",
140
+ "description": "Fired when the context menu is closed."
141
+ },
138
142
  {
139
143
  "name": "item-selected",
140
144
  "description": "Fired when an item is selected when the context menu is populated using the `items` API."
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/context-menu",
4
- "version": "24.8.4",
4
+ "version": "25.0.0-alpha10",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {
@@ -16,7 +16,7 @@
16
16
  "elements": [
17
17
  {
18
18
  "name": "vaadin-context-menu",
19
- "description": "`<vaadin-context-menu>` is a Web Component for creating context menus.\n\n### Items\n\nItems is a higher level convenience API for defining a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nWhen an item is selected, `<vaadin-context-menu>` dispatches an \"item-selected\" event\nwith the selected item as `event.detail.value` property.\nIf item does not have `keepOpen` property the menu will be closed.\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n\ncontextMenu.addEventListener('item-selected', e => {\n const item = e.detail.value;\n console.log(`${item.text} selected`);\n});\n```\n\n**NOTE:** when the `items` array is defined, the renderer cannot be used.\n\n### Rendering\n\nThe content of the menu can be populated by using the renderer callback function.\n\nThe renderer function provides `root`, `contextMenu`, `model` arguments when applicable.\nGenerate DOM content by using `model` object properties if needed, append it to the `root`\nelement and control the state of the host element by accessing `contextMenu`. Before generating\nnew content, the renderer function should check if there is already content in `root` for reusing it.\n\n```html\n<vaadin-context-menu id=\"contextMenu\">\n <p>This paragraph has a context menu.</p>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'Content of the selector: ' + context.target.textContent;\n};\n```\n\nYou can access the menu context inside the renderer using\n`context.target` and `context.detail`.\n\nRenderer is called on the opening of the context-menu and each time the related context is updated.\nDOM generated during the renderer call can be reused\nin the next renderer call and will be provided with the `root` argument.\nOn first call it will be empty.\n\n### `vaadin-contextmenu` Gesture Event\n\n`vaadin-contextmenu` is a gesture event (a custom event),\nwhich is dispatched after either `contextmenu` or long touch events.\nThis enables support for both mouse and touch environments in a uniform way.\n\n`<vaadin-context-menu>` opens the menu overlay on the `vaadin-contextmenu`\nevent by default.\n\n### Menu Listener\n\nBy default, the `<vaadin-context-menu>` element listens for the menu opening\nevent on itself. In case if you do not want to wrap the target, you can listen for\nevents on an element outside the `<vaadin-context-menu>` by setting the\n`listenOn` property:\n\n```html\n<vaadin-context-menu id=\"contextMenu\"></vaadin-context-menu>\n\n<div id=\"menuListener\">The element that listens for the contextmenu event.</div>\n```\n```javascript\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.listenOn = document.querySelector('#menuListener');\n```\n\n### Filtering Menu Targets\n\nBy default, the listener element and all its descendants open the context\nmenu. You can filter the menu targets to a smaller set of elements inside\nthe listener element by setting the `selector` property.\n\nIn the following example, only the elements matching `.has-menu` will open the context menu:\n\n```html\n<vaadin-context-menu selector=\".has-menu\">\n <p class=\"has-menu\">This paragraph opens the context menu</p>\n <p>This paragraph does not open the context menu</p>\n</vaadin-context-menu>\n```\n\n### Menu Context\n\nThe following properties are available in the `context` argument:\n\n- `target` is the menu opening event target, which is the element that\nthe user has called the context menu for\n- `detail` is the menu opening event detail\n\nIn the following example, the menu item text is composed with the contents\nof the element that opened the menu:\n\n```html\n<vaadin-context-menu selector=\"li\" id=\"contextMenu\">\n <ul>\n <li>Foo</li>\n <li>Bar</li>\n <li>Baz</li>\n </ul>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'The menu target: ' + context.target.textContent;\n};\n```\n\n### Styling\n\n`<vaadin-context-menu>` uses `<vaadin-context-menu-overlay>` internal\nthemable component as the actual visible context menu overlay.\n\nSee [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.8.4/#/elements/vaadin-overlay)\ndocumentation for `<vaadin-context-menu-overlay>` stylable parts.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.\n\n### Internal components\n\nWhen using `items` API, in addition `<vaadin-context-menu-overlay>`, the following\ninternal components are themable:\n\n- `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.8.4/#/elements/vaadin-item).\n- `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/24.8.4/#/elements/vaadin-list-box).\n\nThe `<vaadin-context-menu-item>` sub-menu elements have the following additional state attributes\non top of the built-in `<vaadin-item>` state attributes:\n\nAttribute | Description\n---------- |-------------\n`expanded` | Expanded parent item.\n\nNote: the `theme` attribute value set on `<vaadin-context-menu>` is\npropagated to the internal components listed above.",
19
+ "description": "`<vaadin-context-menu>` is a Web Component for creating context menus.\n\n### Items\n\nItems is a higher level convenience API for defining a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nWhen an item is selected, `<vaadin-context-menu>` dispatches an \"item-selected\" event\nwith the selected item as `event.detail.value` property.\nIf item does not have `keepOpen` property the menu will be closed.\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n\ncontextMenu.addEventListener('item-selected', e => {\n const item = e.detail.value;\n console.log(`${item.text} selected`);\n});\n```\n\n**NOTE:** when the `items` array is defined, the renderer cannot be used.\n\n### Rendering\n\nThe content of the menu can be populated by using the renderer callback function.\n\nThe renderer function provides `root`, `contextMenu`, `model` arguments when applicable.\nGenerate DOM content by using `model` object properties if needed, append it to the `root`\nelement and control the state of the host element by accessing `contextMenu`. Before generating\nnew content, the renderer function should check if there is already content in `root` for reusing it.\n\n```html\n<vaadin-context-menu id=\"contextMenu\">\n <p>This paragraph has a context menu.</p>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'Content of the selector: ' + context.target.textContent;\n};\n```\n\nYou can access the menu context inside the renderer using\n`context.target` and `context.detail`.\n\nRenderer is called on the opening of the context-menu and each time the related context is updated.\nDOM generated during the renderer call can be reused\nin the next renderer call and will be provided with the `root` argument.\nOn first call it will be empty.\n\n### `vaadin-contextmenu` Gesture Event\n\n`vaadin-contextmenu` is a gesture event (a custom event),\nwhich is dispatched after either `contextmenu` or long touch events.\nThis enables support for both mouse and touch environments in a uniform way.\n\n`<vaadin-context-menu>` opens the menu overlay on the `vaadin-contextmenu`\nevent by default.\n\n### Menu Listener\n\nBy default, the `<vaadin-context-menu>` element listens for the menu opening\nevent on itself. In case if you do not want to wrap the target, you can listen for\nevents on an element outside the `<vaadin-context-menu>` by setting the\n`listenOn` property:\n\n```html\n<vaadin-context-menu id=\"contextMenu\"></vaadin-context-menu>\n\n<div id=\"menuListener\">The element that listens for the contextmenu event.</div>\n```\n```javascript\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.listenOn = document.querySelector('#menuListener');\n```\n\n### Filtering Menu Targets\n\nBy default, the listener element and all its descendants open the context\nmenu. You can filter the menu targets to a smaller set of elements inside\nthe listener element by setting the `selector` property.\n\nIn the following example, only the elements matching `.has-menu` will open the context menu:\n\n```html\n<vaadin-context-menu selector=\".has-menu\">\n <p class=\"has-menu\">This paragraph opens the context menu</p>\n <p>This paragraph does not open the context menu</p>\n</vaadin-context-menu>\n```\n\n### Menu Context\n\nThe following properties are available in the `context` argument:\n\n- `target` is the menu opening event target, which is the element that\nthe user has called the context menu for\n- `detail` is the menu opening event detail\n\nIn the following example, the menu item text is composed with the contents\nof the element that opened the menu:\n\n```html\n<vaadin-context-menu selector=\"li\" id=\"contextMenu\">\n <ul>\n <li>Foo</li>\n <li>Bar</li>\n <li>Baz</li>\n </ul>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'The menu target: ' + context.target.textContent;\n};\n```\n\n### Styling\n\nThe following shadow DOM parts are available for styling:\n\nPart name | Description\n-----------------|-------------------------------------------\n`backdrop` | Backdrop of the overlay\n`overlay` | The overlay container\n`content` | The overlay content\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.\n\n### Internal components\n\nWhen using `items` API the following internal components are themable:\n\n- `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/25.0.0-alpha10/#/elements/vaadin-item).\n- `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/25.0.0-alpha10/#/elements/vaadin-list-box).\n\nThe `<vaadin-context-menu-item>` sub-menu elements have the following additional state attributes\non top of the built-in `<vaadin-item>` state attributes:\n\nAttribute | Description\n---------- |-------------\n`expanded` | Expanded parent item.\n\nNote: the `theme` attribute value set on `<vaadin-context-menu>` is\npropagated to the internal components listed above.",
20
20
  "extension": true,
21
21
  "attributes": [
22
22
  {
@@ -68,6 +68,13 @@
68
68
  "kind": "expression"
69
69
  }
70
70
  },
71
+ {
72
+ "name": "@closed",
73
+ "description": "Fired when the context menu is closed.",
74
+ "value": {
75
+ "kind": "expression"
76
+ }
77
+ },
71
78
  {
72
79
  "name": "@item-selected",
73
80
  "description": "Fired when an item is selected when the context menu is populated using the `items` API.",
@@ -1,60 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { css, html, LitElement } from 'lit';
7
- import { defineCustomElement } from '@vaadin/component-base/src/define.js';
8
- import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
9
- import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
10
- import { ItemMixin } from '@vaadin/item/src/vaadin-item-mixin.js';
11
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
12
-
13
- /**
14
- * An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
15
- *
16
- * @customElement
17
- * @extends HTMLElement
18
- * @mixes DirMixin
19
- * @mixes ItemMixin
20
- * @mixes ThemableMixin
21
- * @protected
22
- */
23
- class ContextMenuItem extends ItemMixin(ThemableMixin(DirMixin(PolylitMixin(LitElement)))) {
24
- static get is() {
25
- return 'vaadin-context-menu-item';
26
- }
27
-
28
- static get styles() {
29
- return css`
30
- :host {
31
- display: inline-block;
32
- }
33
-
34
- :host([hidden]) {
35
- display: none !important;
36
- }
37
- `;
38
- }
39
-
40
- /** @protected */
41
- render() {
42
- return html`
43
- <span part="checkmark" aria-hidden="true"></span>
44
- <div part="content">
45
- <slot></slot>
46
- </div>
47
- `;
48
- }
49
-
50
- /** @protected */
51
- ready() {
52
- super.ready();
53
-
54
- this.setAttribute('role', 'menuitem');
55
- }
56
- }
57
-
58
- defineCustomElement(ContextMenuItem);
59
-
60
- export { ContextMenuItem };
@@ -1,87 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2016 - 2025 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { css, html, LitElement } from 'lit';
7
- import { ListMixin } from '@vaadin/a11y-base/src/list-mixin.js';
8
- import { defineCustomElement } from '@vaadin/component-base/src/define.js';
9
- import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
10
- import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
11
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
12
-
13
- /**
14
- * An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
15
- *
16
- * @customElement
17
- * @extends HTMLElement
18
- * @mixes DirMixin
19
- * @mixes ListMixin
20
- * @mixes ThemableMixin
21
- * @protected
22
- */
23
- class ContextMenuListBox extends ListMixin(ThemableMixin(DirMixin(PolylitMixin(LitElement)))) {
24
- static get is() {
25
- return 'vaadin-context-menu-list-box';
26
- }
27
-
28
- static get styles() {
29
- return css`
30
- :host {
31
- display: flex;
32
- }
33
-
34
- :host([hidden]) {
35
- display: none !important;
36
- }
37
-
38
- [part='items'] {
39
- height: 100%;
40
- width: 100%;
41
- overflow-y: auto;
42
- -webkit-overflow-scrolling: touch;
43
- }
44
- `;
45
- }
46
-
47
- static get properties() {
48
- return {
49
- // We don't need to define this property since super default is vertical,
50
- // but we don't want it to be modified, or be shown in the API docs.
51
- /** @private */
52
- orientation: {
53
- type: String,
54
- readOnly: true,
55
- },
56
- };
57
- }
58
-
59
- /**
60
- * @return {!HTMLElement}
61
- * @protected
62
- * @override
63
- */
64
- get _scrollerElement() {
65
- return this.shadowRoot.querySelector('[part="items"]');
66
- }
67
-
68
- /** @protected */
69
- render() {
70
- return html`
71
- <div part="items">
72
- <slot></slot>
73
- </div>
74
- `;
75
- }
76
-
77
- /** @protected */
78
- ready() {
79
- super.ready();
80
-
81
- this.setAttribute('role', 'menu');
82
- }
83
- }
84
-
85
- defineCustomElement(ContextMenuListBox);
86
-
87
- export { ContextMenuListBox };