@vaadin/context-menu 25.0.0-alpha1 → 25.0.0-alpha11

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 (27) hide show
  1. package/package.json +13 -14
  2. package/src/styles/vaadin-context-menu-item-base-styles.d.ts +8 -0
  3. package/src/styles/vaadin-context-menu-item-base-styles.js +34 -0
  4. package/src/styles/vaadin-context-menu-overlay-base-styles.d.ts +8 -0
  5. package/src/styles/vaadin-context-menu-overlay-base-styles.js +9 -0
  6. package/src/{vaadin-menu-overlay-styles.d.ts → styles/vaadin-menu-overlay-base-styles.d.ts} +1 -1
  7. package/src/{vaadin-menu-overlay-styles.js → styles/vaadin-menu-overlay-base-styles.js} +7 -8
  8. package/src/vaadin-context-menu-item.js +5 -11
  9. package/src/vaadin-context-menu-list-box.js +5 -18
  10. package/src/vaadin-context-menu-mixin.js +118 -74
  11. package/src/vaadin-context-menu-overlay.js +5 -4
  12. package/src/vaadin-context-menu.d.ts +15 -9
  13. package/src/vaadin-context-menu.js +30 -20
  14. package/src/vaadin-contextmenu-items-mixin.js +37 -27
  15. package/src/vaadin-menu-overlay-mixin.d.ts +0 -5
  16. package/src/vaadin-menu-overlay-mixin.js +22 -27
  17. package/vaadin-context-menu.js +1 -1
  18. package/web-types.json +6 -2
  19. package/web-types.lit.json +9 -2
  20. package/theme/lumo/vaadin-context-menu-item-styles.d.ts +0 -6
  21. package/theme/lumo/vaadin-context-menu-item-styles.js +0 -45
  22. package/theme/lumo/vaadin-context-menu-list-box-styles.d.ts +0 -5
  23. package/theme/lumo/vaadin-context-menu-list-box-styles.js +0 -47
  24. package/theme/lumo/vaadin-context-menu-overlay-styles.d.ts +0 -4
  25. package/theme/lumo/vaadin-context-menu-overlay-styles.js +0 -35
  26. package/theme/lumo/vaadin-context-menu.d.ts +0 -4
  27. package/theme/lumo/vaadin-context-menu.js +0 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/context-menu",
3
- "version": "25.0.0-alpha1",
3
+ "version": "25.0.0-alpha11",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -23,7 +23,6 @@
23
23
  "lit.d.ts",
24
24
  "lit.js",
25
25
  "src",
26
- "theme",
27
26
  "vaadin-*.d.ts",
28
27
  "vaadin-*.js",
29
28
  "web-types.json",
@@ -37,25 +36,25 @@
37
36
  ],
38
37
  "dependencies": {
39
38
  "@open-wc/dedupe-mixin": "^1.3.0",
40
- "@vaadin/a11y-base": "25.0.0-alpha1",
41
- "@vaadin/component-base": "25.0.0-alpha1",
42
- "@vaadin/item": "25.0.0-alpha1",
43
- "@vaadin/list-box": "25.0.0-alpha1",
44
- "@vaadin/lit-renderer": "25.0.0-alpha1",
45
- "@vaadin/overlay": "25.0.0-alpha1",
46
- "@vaadin/vaadin-lumo-styles": "25.0.0-alpha1",
47
- "@vaadin/vaadin-themable-mixin": "25.0.0-alpha1",
39
+ "@vaadin/a11y-base": "25.0.0-alpha11",
40
+ "@vaadin/component-base": "25.0.0-alpha11",
41
+ "@vaadin/item": "25.0.0-alpha11",
42
+ "@vaadin/list-box": "25.0.0-alpha11",
43
+ "@vaadin/lit-renderer": "25.0.0-alpha11",
44
+ "@vaadin/overlay": "25.0.0-alpha11",
45
+ "@vaadin/vaadin-themable-mixin": "25.0.0-alpha11",
48
46
  "lit": "^3.0.0"
49
47
  },
50
48
  "devDependencies": {
51
- "@vaadin/chai-plugins": "25.0.0-alpha1",
52
- "@vaadin/test-runner-commands": "25.0.0-alpha1",
53
- "@vaadin/testing-helpers": "^1.1.0",
49
+ "@vaadin/chai-plugins": "25.0.0-alpha11",
50
+ "@vaadin/test-runner-commands": "25.0.0-alpha11",
51
+ "@vaadin/testing-helpers": "^2.0.0",
52
+ "@vaadin/vaadin-lumo-styles": "25.0.0-alpha11",
54
53
  "sinon": "^18.0.0"
55
54
  },
56
55
  "web-types": [
57
56
  "web-types.json",
58
57
  "web-types.lit.json"
59
58
  ],
60
- "gitHead": "b8c22a4a0c64156210d0daac96b43ae4e5526d49"
59
+ "gitHead": "abfd315ba5a7484a613e0768635a4e8fe945a44b"
61
60
  }
@@ -0,0 +1,8 @@
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 type { CSSResult } from 'lit';
7
+
8
+ export const contextMenuItemStyles: CSSResult;
@@ -0,0 +1,34 @@
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 '@vaadin/component-base/src/styles/style-props.js';
7
+ import { css } from 'lit';
8
+ import { itemStyles } from '@vaadin/item/src/styles/vaadin-item-base-styles.js';
9
+
10
+ const menuItemStyles = css`
11
+ :host::after {
12
+ background: var(--vaadin-color-subtle);
13
+ content: '';
14
+ display: block;
15
+ height: var(--vaadin-icon-size, 1lh);
16
+ mask-image: var(--_vaadin-icon-chevron-down);
17
+ rotate: -90deg;
18
+ visibility: hidden;
19
+ width: var(--vaadin-icon-size, 1lh);
20
+ }
21
+
22
+ :host([dir='rtl'])::after {
23
+ rotate: 90deg;
24
+ }
25
+
26
+ /* TODO would be nice to only reserve the space for these if
27
+ one or mote items in the list is checkable or has child items */
28
+ :host([aria-haspopup='true'])::after,
29
+ :host([menu-item-checked]) [part='checkmark'] {
30
+ visibility: visible;
31
+ }
32
+ `;
33
+
34
+ export const contextMenuItemStyles = [itemStyles, menuItemStyles];
@@ -0,0 +1,8 @@
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 type { CSSResult } from 'lit';
7
+
8
+ export const contextMenuOverlayStyles: CSSResult;
@@ -0,0 +1,9 @@
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 { overlayStyles } from '@vaadin/overlay/src/styles/vaadin-overlay-base-styles.js';
7
+ import { menuOverlayStyles } from './vaadin-menu-overlay-base-styles.js';
8
+
9
+ export const contextMenuOverlayStyles = [overlayStyles, menuOverlayStyles];
@@ -5,4 +5,4 @@
5
5
  */
6
6
  import type { CSSResult } from 'lit';
7
7
 
8
- export const styles: CSSResult;
8
+ export const menuOverlayStyles: CSSResult;
@@ -3,9 +3,9 @@
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 { css } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
6
+ import { css } from 'lit';
7
7
 
8
- export const styles = css`
8
+ export const menuOverlayStyles = css`
9
9
  :host {
10
10
  align-items: flex-start;
11
11
  justify-content: flex-start;
@@ -20,13 +20,12 @@ export const styles = css`
20
20
  justify-content: flex-end;
21
21
  }
22
22
 
23
- [part='overlay'] {
24
- background-color: #fff;
23
+ [part='content'] {
24
+ padding: var(--vaadin-item-overlay-padding, 4px);
25
25
  }
26
26
 
27
- @media (forced-colors: active) {
28
- [part='overlay'] {
29
- outline: 3px solid !important;
30
- }
27
+ /* TODO keyboard focus becomes visible even when navigating the menu with the mouse */
28
+ [part='overlay']:focus-visible {
29
+ outline: none;
31
30
  }
32
31
  `;
@@ -3,12 +3,14 @@
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 { css, html, LitElement } from 'lit';
6
+ import { html, LitElement } from 'lit';
7
7
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
8
8
  import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
9
9
  import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
10
10
  import { ItemMixin } from '@vaadin/item/src/vaadin-item-mixin.js';
11
+ import { LumoInjectionMixin } from '@vaadin/vaadin-themable-mixin/lumo-injection-mixin.js';
11
12
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
13
+ import { contextMenuItemStyles } from './styles/vaadin-context-menu-item-base-styles.js';
12
14
 
13
15
  /**
14
16
  * An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
@@ -20,21 +22,13 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
20
22
  * @mixes ThemableMixin
21
23
  * @protected
22
24
  */
23
- class ContextMenuItem extends ItemMixin(ThemableMixin(DirMixin(PolylitMixin(LitElement)))) {
25
+ class ContextMenuItem extends ItemMixin(ThemableMixin(DirMixin(PolylitMixin(LumoInjectionMixin(LitElement))))) {
24
26
  static get is() {
25
27
  return 'vaadin-context-menu-item';
26
28
  }
27
29
 
28
30
  static get styles() {
29
- return css`
30
- :host {
31
- display: inline-block;
32
- }
33
-
34
- :host([hidden]) {
35
- display: none !important;
36
- }
37
- `;
31
+ return contextMenuItemStyles;
38
32
  }
39
33
 
40
34
  /** @protected */
@@ -3,11 +3,13 @@
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 { css, html, LitElement } from 'lit';
6
+ import { html, LitElement } from 'lit';
7
7
  import { ListMixin } from '@vaadin/a11y-base/src/list-mixin.js';
8
8
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
9
9
  import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
10
10
  import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
11
+ import { listBoxStyles } from '@vaadin/list-box/src/styles/vaadin-list-box-base-styles.js';
12
+ import { LumoInjectionMixin } from '@vaadin/vaadin-themable-mixin/lumo-injection-mixin.js';
11
13
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
12
14
 
13
15
  /**
@@ -20,28 +22,13 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
20
22
  * @mixes ThemableMixin
21
23
  * @protected
22
24
  */
23
- class ContextMenuListBox extends ListMixin(ThemableMixin(DirMixin(PolylitMixin(LitElement)))) {
25
+ class ContextMenuListBox extends ListMixin(ThemableMixin(DirMixin(PolylitMixin(LumoInjectionMixin(LitElement))))) {
24
26
  static get is() {
25
27
  return 'vaadin-context-menu-list-box';
26
28
  }
27
29
 
28
30
  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
- `;
31
+ return listBoxStyles;
45
32
  }
46
33
 
47
34
  static get properties() {
@@ -3,7 +3,7 @@
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 { isElementFocusable } from '@vaadin/a11y-base/src/focus-utils.js';
6
+ import { isElementFocusable, isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
7
7
  import { isAndroid, isIOS } from '@vaadin/component-base/src/browser-utils.js';
8
8
  import { addListener, deepTargetFind, gestures, removeListener } from '@vaadin/component-base/src/gestures.js';
9
9
  import { MediaQueryController } from '@vaadin/component-base/src/media-query-controller.js';
@@ -31,6 +31,8 @@ export const ContextMenuMixin = (superClass) =>
31
31
  */
32
32
  opened: {
33
33
  type: Boolean,
34
+ reflectToAttribute: true,
35
+ observer: '_openedChanged',
34
36
  value: false,
35
37
  notify: true,
36
38
  readOnly: true,
@@ -123,22 +125,15 @@ export const ContextMenuMixin = (superClass) =>
123
125
 
124
126
  static get observers() {
125
127
  return [
126
- '_openedChanged(opened)',
127
128
  '_targetOrOpenOnChanged(listenOn, openOn)',
128
129
  '_rendererChanged(renderer, items)',
129
130
  '_fullscreenChanged(_fullscreen)',
130
- '_overlayContextChanged(_overlayElement, _context)',
131
- '_overlayModelessChanged(_overlayElement, _modeless)',
132
- '_overlayPhoneChanged(_overlayElement, _phone)',
133
- '_overlayThemeChanged(_overlayElement, _theme)',
134
131
  ];
135
132
  }
136
133
 
137
134
  constructor() {
138
135
  super();
139
136
 
140
- this._createOverlay();
141
-
142
137
  this._boundOpen = this.open.bind(this);
143
138
  this._boundClose = this.close.bind(this);
144
139
  this._boundPreventDefault = this._preventDefault.bind(this);
@@ -170,8 +165,10 @@ export const ContextMenuMixin = (superClass) =>
170
165
  }
171
166
 
172
167
  /** @protected */
173
- ready() {
174
- super.ready();
168
+ firstUpdated() {
169
+ super.firstUpdated();
170
+
171
+ this._overlayElement = this.$.overlay;
175
172
 
176
173
  this.addController(
177
174
  new MediaQueryController(this._fullscreenMediaQuery, (matches) => {
@@ -180,29 +177,17 @@ export const ContextMenuMixin = (superClass) =>
180
177
  );
181
178
  }
182
179
 
183
- /** @private */
184
- _createOverlay() {
185
- // Create an overlay in the constructor to use in observers before `ready()`
186
- const overlay = document.createElement(`${this._tagNamePrefix}-overlay`);
187
- overlay.owner = this;
188
-
189
- overlay.addEventListener('opened-changed', (e) => {
190
- this._onOverlayOpened(e);
191
- });
192
-
193
- overlay.addEventListener('vaadin-overlay-open', (e) => {
194
- this._onVaadinOverlayOpen(e);
195
- });
196
-
197
- this._overlayElement = overlay;
198
- }
199
-
200
180
  /**
201
181
  * Runs before overlay is fully rendered
202
182
  * @private
203
183
  */
204
- _onOverlayOpened(e) {
205
- const opened = e.detail.value;
184
+ _onOverlayOpened(event) {
185
+ // Ignore events from submenus
186
+ if (event.target !== this._overlayElement) {
187
+ return;
188
+ }
189
+
190
+ const opened = event.detail.value;
206
191
  this._setOpened(opened);
207
192
  if (opened) {
208
193
  this.__alignOverlayPosition();
@@ -213,43 +198,23 @@ export const ContextMenuMixin = (superClass) =>
213
198
  * Runs after overlay is fully rendered
214
199
  * @private
215
200
  */
216
- _onVaadinOverlayOpen() {
217
- this.__alignOverlayPosition();
218
- this._overlayElement.style.opacity = '';
219
- this.__forwardFocus();
220
- }
221
-
222
- /** @private */
223
- _overlayContextChanged(overlay, context) {
224
- if (overlay) {
225
- overlay.model = context;
226
- }
227
- }
228
-
229
- /** @private */
230
- _overlayModelessChanged(overlay, modeless) {
231
- if (overlay) {
232
- overlay.modeless = modeless;
201
+ _onVaadinOverlayOpen(event) {
202
+ // Ignore events from submenus
203
+ if (event.target !== this._overlayElement) {
204
+ return;
233
205
  }
234
- }
235
206
 
236
- /** @private */
237
- _overlayPhoneChanged(overlay, phone) {
238
- if (overlay) {
239
- overlay.toggleAttribute('phone', phone);
240
- overlay.withBackdrop = phone;
241
- }
207
+ this.__alignOverlayPosition();
208
+ this._overlayElement.style.visibility = '';
209
+ this.__forwardFocus();
242
210
  }
243
211
 
244
- /** @private */
245
- _overlayThemeChanged(overlay, theme) {
246
- if (overlay) {
247
- if (theme) {
248
- overlay.setAttribute('theme', theme);
249
- } else {
250
- overlay.removeAttribute('theme');
251
- }
252
- }
212
+ /**
213
+ * Runs after overlay's closing animation is finished
214
+ * @private
215
+ */
216
+ _onVaadinOverlayClosed() {
217
+ this.dispatchEvent(new CustomEvent('closed'));
253
218
  }
254
219
 
255
220
  /** @private */
@@ -318,17 +283,14 @@ export const ContextMenuMixin = (superClass) =>
318
283
  }
319
284
 
320
285
  /** @private */
321
- _openedChanged(opened) {
286
+ _openedChanged(opened, oldOpened) {
322
287
  if (opened) {
323
288
  document.documentElement.addEventListener('contextmenu', this._boundOnGlobalContextMenu, true);
324
- } else {
289
+ } else if (oldOpened) {
325
290
  document.documentElement.removeEventListener('contextmenu', this._boundOnGlobalContextMenu, true);
326
291
  }
327
292
 
328
293
  this.__setListenOnUserSelect(opened);
329
-
330
- // Has to be set after instance has been created
331
- this._overlayElement.opened = opened;
332
294
  }
333
295
 
334
296
  /**
@@ -338,11 +300,18 @@ export const ContextMenuMixin = (superClass) =>
338
300
  * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
339
301
  */
340
302
  requestContentUpdate() {
341
- if (!this._overlayElement || !this.renderer) {
303
+ if (!this._overlayElement) {
342
304
  return;
343
305
  }
344
306
 
307
+ // Store state to be restored after re-rendering
308
+ this.__preserveMenuState();
309
+
310
+ // Run overlay renderer to re-create DOM elements
345
311
  this._overlayElement.requestContentUpdate();
312
+
313
+ // Restore focused item, update sub-menu if needed
314
+ this.__restoreMenuState();
346
315
  }
347
316
 
348
317
  /** @private */
@@ -355,11 +324,7 @@ export const ContextMenuMixin = (superClass) =>
355
324
  if (this.closeOn === 'click') {
356
325
  this.closeOn = '';
357
326
  }
358
-
359
- renderer = this.__itemsRenderer;
360
327
  }
361
-
362
- this._overlayElement.renderer = renderer;
363
328
  }
364
329
 
365
330
  /**
@@ -386,6 +351,11 @@ export const ContextMenuMixin = (superClass) =>
386
351
  * @param {!Event | undefined} e used as the context for the menu. Overlay coordinates are taken from this event.
387
352
  */
388
353
  open(e) {
354
+ // Ignore events from the overlay
355
+ if (this._overlayElement && e.composedPath().includes(this._overlayElement)) {
356
+ return;
357
+ }
358
+
389
359
  if (e && !this.opened) {
390
360
  this._context = {
391
361
  detail: e.detail,
@@ -403,12 +373,76 @@ export const ContextMenuMixin = (superClass) =>
403
373
  this.__y = this._getEventCoordinate(e, 'y');
404
374
  this.__pageYOffset = window.pageYOffset;
405
375
 
406
- this._overlayElement.style.opacity = '0';
376
+ // Hide overlay until it is fully rendered and positioned
377
+ this._overlayElement.style.visibility = 'hidden';
407
378
  this._setOpened(true);
408
379
  }
409
380
  }
410
381
  }
411
382
 
383
+ /** @private */
384
+ __preserveMenuState() {
385
+ const listBox = this.__getListBox();
386
+ if (listBox) {
387
+ this.__focusedIndex = listBox.items.indexOf(listBox.focused);
388
+
389
+ if (this._subMenu && this._subMenu.opened) {
390
+ this.__subMenuIndex = listBox.items.indexOf(this._subMenu.listenOn);
391
+ }
392
+ }
393
+ }
394
+
395
+ /** @private */
396
+ __restoreMenuState() {
397
+ const focusedIndex = this.__focusedIndex;
398
+ const subMenuIndex = this.__subMenuIndex;
399
+ const selectedIndex = this.__selectedIndex;
400
+
401
+ const listBox = this.__getListBox();
402
+
403
+ if (listBox) {
404
+ // Initialize menu items synchronously
405
+ listBox._observer.flush();
406
+
407
+ if (subMenuIndex > -1) {
408
+ const itemToOpen = listBox.items[subMenuIndex];
409
+ if (itemToOpen) {
410
+ if (Array.isArray(itemToOpen._item.children) && itemToOpen._item.children.length) {
411
+ // Keep nested sub-menu opened and update it
412
+ this.__updateSubMenuForItem(this._subMenu, itemToOpen);
413
+ this._subMenu.requestContentUpdate();
414
+ } else {
415
+ // Item no longer has children, close sub-menu
416
+ this._subMenu.close();
417
+ this.__focusItem(itemToOpen);
418
+ }
419
+ } else {
420
+ // Item no longer exists, focus the list-box
421
+ listBox.focus();
422
+ }
423
+ }
424
+
425
+ // Focus previously selected item, in case it was clicked with
426
+ // `keepOpen` option, or the previously focused item, if any
427
+ this.__focusItem(selectedIndex > -1 ? listBox.children[selectedIndex] : listBox.items[focusedIndex]);
428
+ }
429
+
430
+ this.__focusedIndex = undefined;
431
+ this.__subMenuIndex = undefined;
432
+ this.__selectedIndex = undefined;
433
+ }
434
+
435
+ /** @private */
436
+ __focusItem(item) {
437
+ if (item) {
438
+ item.focus();
439
+
440
+ if (isKeyboardActive()) {
441
+ item.setAttribute('focus-ring', '');
442
+ }
443
+ }
444
+ }
445
+
412
446
  /** @private */
413
447
  __onScroll() {
414
448
  if (!this.opened) {
@@ -600,7 +634,11 @@ export const ContextMenuMixin = (superClass) =>
600
634
  // Dispatch another contextmenu at the same coordinates after the overlay is closed
601
635
  this._overlayElement.addEventListener(
602
636
  'vaadin-overlay-closed',
603
- () => this.__contextMenuAt(e.clientX, e.clientY),
637
+ (closeEvent) => {
638
+ if (closeEvent.target === this._overlayElement) {
639
+ this.__contextMenuAt(e.clientX, e.clientY);
640
+ }
641
+ },
604
642
  {
605
643
  once: true,
606
644
  },
@@ -611,4 +649,10 @@ export const ContextMenuMixin = (superClass) =>
611
649
  this.close();
612
650
  }
613
651
  }
652
+
653
+ /**
654
+ * Fired when the context menu is closed.
655
+ *
656
+ * @event closed
657
+ */
614
658
  };
@@ -8,10 +8,10 @@ import { defineCustomElement } from '@vaadin/component-base/src/define.js';
8
8
  import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
9
9
  import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
10
10
  import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js';
11
- import { overlayStyles } from '@vaadin/overlay/src/vaadin-overlay-styles.js';
11
+ import { LumoInjectionMixin } from '@vaadin/vaadin-themable-mixin/lumo-injection-mixin.js';
12
12
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
13
+ import { contextMenuOverlayStyles } from './styles/vaadin-context-menu-overlay-base-styles.js';
13
14
  import { MenuOverlayMixin } from './vaadin-menu-overlay-mixin.js';
14
- import { styles } from './vaadin-menu-overlay-styles.js';
15
15
 
16
16
  /**
17
17
  * An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
@@ -25,14 +25,14 @@ import { styles } from './vaadin-menu-overlay-styles.js';
25
25
  * @protected
26
26
  */
27
27
  export class ContextMenuOverlay extends MenuOverlayMixin(
28
- OverlayMixin(DirMixin(ThemableMixin(PolylitMixin(LitElement)))),
28
+ OverlayMixin(DirMixin(ThemableMixin(PolylitMixin(LumoInjectionMixin(LitElement))))),
29
29
  ) {
30
30
  static get is() {
31
31
  return 'vaadin-context-menu-overlay';
32
32
  }
33
33
 
34
34
  static get styles() {
35
- return [overlayStyles, styles];
35
+ return contextMenuOverlayStyles;
36
36
  }
37
37
 
38
38
  /** @protected */
@@ -42,6 +42,7 @@ export class ContextMenuOverlay extends MenuOverlayMixin(
42
42
  <div part="overlay" id="overlay" tabindex="0">
43
43
  <div part="content" id="content">
44
44
  <slot></slot>
45
+ <slot name="submenu"></slot>
45
46
  </div>
46
47
  </div>
47
48
  `;
@@ -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).
@@ -231,11 +239,9 @@ export interface ContextMenuEventMap<TItem extends ContextMenuItem = ContextMenu
231
239
  * ---------- |-------------
232
240
  * `expanded` | Expanded parent item.
233
241
  *
234
- * Note: the `theme` attribute value set on `<vaadin-context-menu>` is
235
- * propagated to the internal components listed above.
236
- *
237
242
  * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
238
243
  * @fires {CustomEvent} item-selected - Fired when an item is selected when the context menu is populated using the `items` API.
244
+ * @fires {CustomEvent} closed - Fired when the context menu is closed.
239
245
  */
240
246
  declare class ContextMenu<TItem extends ContextMenuItem = ContextMenuItem> extends HTMLElement {
241
247
  addEventListener<K extends keyof ContextMenuEventMap>(
@@ -8,6 +8,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
10
  import { css, html, LitElement } from 'lit';
11
+ import { ifDefined } from 'lit/directives/if-defined.js';
11
12
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
12
13
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
13
14
  import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
@@ -175,18 +176,19 @@ import { ContextMenuMixin } from './vaadin-context-menu-mixin.js';
175
176
  *
176
177
  * ### Styling
177
178
  *
178
- * `<vaadin-context-menu>` uses `<vaadin-context-menu-overlay>` internal
179
- * themable component as the actual visible context menu overlay.
179
+ * The following shadow DOM parts are available for styling:
180
180
  *
181
- * See [`<vaadin-overlay>`](#/elements/vaadin-overlay)
182
- * 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
183
186
  *
184
187
  * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
185
188
  *
186
189
  * ### Internal components
187
190
  *
188
- * When using `items` API, in addition `<vaadin-context-menu-overlay>`, the following
189
- * internal components are themable:
191
+ * When using `items` API the following internal components are themable:
190
192
  *
191
193
  * - `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](#/elements/vaadin-item).
192
194
  * - `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](#/elements/vaadin-list-box).
@@ -198,11 +200,9 @@ import { ContextMenuMixin } from './vaadin-context-menu-mixin.js';
198
200
  * ---------- |-------------
199
201
  * `expanded` | Expanded parent item.
200
202
  *
201
- * Note: the `theme` attribute value set on `<vaadin-context-menu>` is
202
- * propagated to the internal components listed above.
203
- *
204
203
  * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
205
204
  * @fires {CustomEvent} item-selected - Fired when an item is selected when the context menu is populated using the `items` API.
205
+ * @fires {CustomEvent} closed - Fired when the context menu is closed.
206
206
  *
207
207
  * @customElement
208
208
  * @extends HTMLElement
@@ -232,17 +232,27 @@ class ContextMenu extends ContextMenuMixin(
232
232
 
233
233
  /** @protected */
234
234
  render() {
235
- return html`<slot id="slot"></slot>`;
236
- }
237
-
238
- /**
239
- * @protected
240
- * @override
241
- */
242
- createRenderRoot() {
243
- const root = super.createRenderRoot();
244
- root.appendChild(this._overlayElement);
245
- return root;
235
+ return html`
236
+ <slot id="slot"></slot>
237
+ <vaadin-context-menu-overlay
238
+ id="overlay"
239
+ .owner="${this}"
240
+ .opened="${this.opened}"
241
+ .model="${this._context}"
242
+ .modeless="${this._modeless}"
243
+ .renderer="${this.items ? this.__itemsRenderer : this.renderer}"
244
+ .withBackdrop="${this._phone}"
245
+ ?phone="${this._phone}"
246
+ theme="${ifDefined(this._theme)}"
247
+ exportparts="backdrop, overlay, content"
248
+ @opened-changed="${this._onOverlayOpened}"
249
+ @vaadin-overlay-open="${this._onVaadinOverlayOpen}"
250
+ @vaadin-overlay-closed="${this._onVaadinOverlayClosed}"
251
+ >
252
+ <slot name="overlay"></slot>
253
+ <slot name="submenu" slot="submenu"></slot>
254
+ </vaadin-context-menu-overlay>
255
+ `;
246
256
  }
247
257
 
248
258
  /**
@@ -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 {
@@ -132,14 +132,12 @@ export const ItemsMixin = (superClass) =>
132
132
 
133
133
  /** @private */
134
134
  __openSubMenu(subMenu, itemElement, overlayClass) {
135
- subMenu.items = itemElement._item.children;
136
- subMenu.listenOn = itemElement;
135
+ this.__updateSubMenuForItem(subMenu, itemElement);
137
136
  subMenu.overlayClass = overlayClass;
138
137
 
139
138
  const parent = this._overlayElement;
140
139
 
141
140
  const subMenuOverlay = subMenu._overlayElement;
142
- subMenuOverlay.positionTarget = itemElement;
143
141
  subMenuOverlay.noHorizontalOverlap = true;
144
142
  // Store the reference parent overlay
145
143
  subMenuOverlay._setParentOverlay(parent);
@@ -163,6 +161,13 @@ export const ItemsMixin = (superClass) =>
163
161
  );
164
162
  }
165
163
 
164
+ /** @private */
165
+ __updateSubMenuForItem(subMenu, itemElement) {
166
+ subMenu.items = itemElement._item.children;
167
+ subMenu.listenOn = itemElement;
168
+ subMenu._overlayElement.positionTarget = itemElement;
169
+ }
170
+
166
171
  /**
167
172
  * @param {!ContextMenuItem} item
168
173
  * @return {HTMLElement}
@@ -248,10 +253,20 @@ export const ItemsMixin = (superClass) =>
248
253
  // Open a submenu on click event when a touch device is used.
249
254
  // On desktop, a submenu opens on hover.
250
255
  overlay.addEventListener(isTouch ? 'click' : 'mouseover', (event) => {
256
+ // Ignore events from the submenus
257
+ if (event.composedPath().includes(this._subMenu)) {
258
+ return;
259
+ }
260
+
251
261
  this.__showSubMenu(event);
252
262
  });
253
263
 
254
264
  overlay.addEventListener('keydown', (event) => {
265
+ // Ignore events from the submenus
266
+ if (event.composedPath().includes(this._subMenu)) {
267
+ return;
268
+ }
269
+
255
270
  const { key } = event;
256
271
  const isRTL = this.__isRTL;
257
272
 
@@ -283,10 +298,6 @@ export const ItemsMixin = (superClass) =>
283
298
  subMenu._modeless = true;
284
299
  subMenu.openOn = 'opensubmenu';
285
300
 
286
- // Sub-menu doesn't have a target to wrap,
287
- // so there is no need to keep it visible.
288
- subMenu.setAttribute('hidden', '');
289
-
290
301
  // Close sub-menu when the parent menu closes.
291
302
  this.addEventListener('opened-changed', (event) => {
292
303
  if (!event.detail.value) {
@@ -317,14 +328,10 @@ export const ItemsMixin = (superClass) =>
317
328
  const menu = e.target;
318
329
  const selectedItem = e.detail.value;
319
330
  const index = menu.items.indexOf(selectedItem);
320
- if (!!selectedItem.keepOpen && index > -1) {
321
- menu._overlayElement.requestContentUpdate();
322
-
323
- // Initialize items synchronously
324
- menu._listBox._observer.flush();
325
-
326
- const newItem = menu._listBox.children[index];
327
- newItem.focus();
331
+ // Menu can be no longer opened if parent menu items changed
332
+ if (!!selectedItem.keepOpen && index > -1 && menu.opened) {
333
+ menu.__selectedIndex = index;
334
+ menu.requestContentUpdate();
328
335
  } else if (!selectedItem.keepOpen) {
329
336
  this.close();
330
337
  }
@@ -365,7 +372,7 @@ export const ItemsMixin = (superClass) =>
365
372
  const { children } = item._item;
366
373
 
367
374
  // Check if the sub-menu was focused before closing it.
368
- const child = subMenu._overlayElement.getFirstChild();
375
+ const child = subMenu._overlayElement._contentRoot.firstElementChild;
369
376
  const isSubmenuFocused = child && child.focused;
370
377
 
371
378
  if (subMenu.items !== children) {
@@ -391,24 +398,26 @@ export const ItemsMixin = (superClass) =>
391
398
  }
392
399
  }
393
400
 
401
+ /** @protected */
402
+ __getListBox() {
403
+ return this._overlayElement._contentRoot.querySelector(`${this._tagNamePrefix}-list-box`);
404
+ }
405
+
394
406
  /**
395
407
  * @param {!HTMLElement} root
396
408
  * @param {!ContextMenu} menu
397
409
  * @param {!ContextMenuRendererContext} context
398
410
  * @protected
399
411
  */
400
- __itemsRenderer(root, menu, { detail }) {
412
+ __itemsRenderer(root, menu) {
401
413
  this.__initMenu(root, menu);
402
414
 
403
- const subMenu = root.querySelector(this.constructor.is);
404
- subMenu.closeOn = menu.closeOn;
405
-
406
- const listBox = root.querySelector(`${this._tagNamePrefix}-list-box`);
407
- listBox.innerHTML = '';
415
+ this._subMenu.closeOn = menu.closeOn;
416
+ this._listBox.innerHTML = '';
408
417
 
409
- [...(detail.children || menu.items)].forEach((item) => {
418
+ menu.items.forEach((item) => {
410
419
  const component = this.__createComponent(item);
411
- listBox.appendChild(component);
420
+ this._listBox.appendChild(component);
412
421
  });
413
422
  }
414
423
 
@@ -449,8 +458,9 @@ export const ItemsMixin = (superClass) =>
449
458
  root.appendChild(listBox);
450
459
 
451
460
  const subMenu = this.__initSubMenu();
461
+ subMenu.slot = 'submenu';
452
462
  this._subMenu = subMenu;
453
- root.appendChild(subMenu);
463
+ this.appendChild(subMenu);
454
464
 
455
465
  requestAnimationFrame(() => {
456
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
  };
@@ -1,2 +1,2 @@
1
- import './theme/lumo/vaadin-context-menu.js';
1
+ import './src/vaadin-context-menu.js';
2
2
  export * from './src/vaadin-context-menu.js';
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": "25.0.0-alpha1",
4
+ "version": "25.0.0-alpha11",
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/25.0.0-alpha1/#/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/25.0.0-alpha1/#/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-alpha1/#/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-alpha11/#/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-alpha11/#/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.",
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": "25.0.0-alpha1",
4
+ "version": "25.0.0-alpha11",
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/25.0.0-alpha1/#/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/25.0.0-alpha1/#/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-alpha1/#/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-alpha11/#/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-alpha11/#/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.",
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,6 +0,0 @@
1
- import '@vaadin/vaadin-lumo-styles/color.js';
2
- import '@vaadin/vaadin-lumo-styles/font-icons.js';
3
- import '@vaadin/vaadin-lumo-styles/sizing.js';
4
- import '@vaadin/vaadin-lumo-styles/spacing.js';
5
- declare const contextMenuItem: import("lit").CSSResult;
6
- export { contextMenuItem };
@@ -1,45 +0,0 @@
1
- import '@vaadin/vaadin-lumo-styles/color.js';
2
- import '@vaadin/vaadin-lumo-styles/font-icons.js';
3
- import '@vaadin/vaadin-lumo-styles/sizing.js';
4
- import '@vaadin/vaadin-lumo-styles/spacing.js';
5
- import { item } from '@vaadin/item/theme/lumo/vaadin-item-styles.js';
6
- import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
7
-
8
- const contextMenuItem = css`
9
- /* :hover needed to workaround https://github.com/vaadin/web-components/issues/3133 */
10
- :host(:hover) {
11
- user-select: none;
12
- -webkit-user-select: none;
13
- }
14
-
15
- :host([role='menuitem'][menu-item-checked]) [part='checkmark']::before {
16
- opacity: 1;
17
- }
18
-
19
- :host([aria-haspopup='true'])::after {
20
- font-family: lumo-icons;
21
- font-size: var(--lumo-icon-size-xs);
22
- content: var(--lumo-icons-angle-right);
23
- color: var(--lumo-tertiary-text-color);
24
- }
25
-
26
- :host(:not([dir='rtl'])[aria-haspopup='true'])::after {
27
- margin-right: calc(var(--lumo-space-m) * -1);
28
- padding-left: var(--lumo-space-m);
29
- }
30
-
31
- :host([expanded]) {
32
- background-color: var(--lumo-primary-color-10pct);
33
- }
34
-
35
- /* RTL styles */
36
- :host([dir='rtl'][aria-haspopup='true'])::after {
37
- content: var(--lumo-icons-angle-left);
38
- margin-left: calc(var(--lumo-space-m) * -1);
39
- padding-right: var(--lumo-space-m);
40
- }
41
- `;
42
-
43
- registerStyles('vaadin-context-menu-item', [item, contextMenuItem], { moduleId: 'lumo-context-menu-item' });
44
-
45
- export { contextMenuItem };
@@ -1,5 +0,0 @@
1
- import '@vaadin/vaadin-lumo-styles/color.js';
2
- import '@vaadin/vaadin-lumo-styles/spacing.js';
3
- import '@vaadin/vaadin-lumo-styles/style.js';
4
- declare const contextMenuListBox: import("lit").CSSResult;
5
- export { contextMenuListBox };
@@ -1,47 +0,0 @@
1
- import '@vaadin/vaadin-lumo-styles/color.js';
2
- import '@vaadin/vaadin-lumo-styles/spacing.js';
3
- import '@vaadin/vaadin-lumo-styles/style.js';
4
- import { listBox } from '@vaadin/list-box/theme/lumo/vaadin-list-box-styles.js';
5
- import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
6
-
7
- const contextMenuListBox = css`
8
- :host {
9
- --_lumo-list-box-item-selected-icon-display: block;
10
- }
11
-
12
- /* Normal item */
13
- [part='items'] ::slotted([role='menuitem']) {
14
- -webkit-tap-highlight-color: var(--lumo-primary-color-10pct);
15
- cursor: default;
16
- outline: none;
17
- border-radius: var(--lumo-border-radius-m);
18
- padding-left: calc(var(--lumo-border-radius-m) / 4);
19
- padding-right: calc(var(--lumo-space-l) + var(--lumo-border-radius-m) / 4);
20
- }
21
-
22
- /* Hovered item */
23
- /* TODO a workaround until we have "focus-follows-mouse". After that, use the hover style for focus-ring as well */
24
- [part='items'] ::slotted([role='menuitem']:hover:not([disabled])),
25
- [part='items'] ::slotted([role='menuitem'][expanded]:not([disabled])) {
26
- background-color: var(--lumo-primary-color-10pct);
27
- }
28
-
29
- /* RTL styles */
30
- :host([dir='rtl']) [part='items'] ::slotted([role='menuitem']) {
31
- padding-left: calc(var(--lumo-space-l) + var(--lumo-border-radius-m) / 4);
32
- padding-right: calc(var(--lumo-border-radius-m) / 4);
33
- }
34
-
35
- /* Focused item */
36
- @media (pointer: coarse) {
37
- [part='items'] ::slotted([role='menuitem']:hover:not([expanded]):not([disabled])) {
38
- background-color: transparent;
39
- }
40
- }
41
- `;
42
-
43
- registerStyles('vaadin-context-menu-list-box', [listBox, contextMenuListBox], {
44
- moduleId: 'lumo-context-menu-list-box',
45
- });
46
-
47
- export { contextMenuListBox };
@@ -1,4 +0,0 @@
1
- import '@vaadin/vaadin-lumo-styles/spacing.js';
2
- import '@vaadin/vaadin-lumo-styles/style.js';
3
- declare const contextMenuOverlay: import("lit").CSSResult;
4
- export { contextMenuOverlay };
@@ -1,35 +0,0 @@
1
- import '@vaadin/vaadin-lumo-styles/spacing.js';
2
- import '@vaadin/vaadin-lumo-styles/style.js';
3
- import { menuOverlay } from '@vaadin/vaadin-lumo-styles/mixins/menu-overlay.js';
4
- import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
5
-
6
- const contextMenuOverlay = css`
7
- :host([phone]) {
8
- /* stylelint-disable declaration-block-no-redundant-longhand-properties */
9
- top: 0 !important;
10
- right: 0 !important;
11
- bottom: var(--vaadin-overlay-viewport-bottom) !important;
12
- left: 0 !important;
13
- /* stylelint-enable declaration-block-no-redundant-longhand-properties */
14
- align-items: stretch;
15
- justify-content: flex-end;
16
- }
17
-
18
- /* TODO These style overrides should not be needed.
19
- We should instead offer a way to have non-selectable items inside the context menu. */
20
-
21
- :host {
22
- --_lumo-list-box-item-selected-icon-display: none;
23
- --_lumo-list-box-item-padding-left: calc(var(--lumo-space-m) + var(--lumo-border-radius-m) / 4);
24
- }
25
-
26
- [part='overlay'] {
27
- outline: none;
28
- }
29
- `;
30
-
31
- registerStyles('vaadin-context-menu-overlay', [menuOverlay, contextMenuOverlay], {
32
- moduleId: 'lumo-context-menu-overlay',
33
- });
34
-
35
- export { contextMenuOverlay };
@@ -1,4 +0,0 @@
1
- import './vaadin-context-menu-item-styles.js';
2
- import './vaadin-context-menu-list-box-styles.js';
3
- import './vaadin-context-menu-overlay-styles.js';
4
- import '../../src/vaadin-context-menu.js';
@@ -1,4 +0,0 @@
1
- import './vaadin-context-menu-item-styles.js';
2
- import './vaadin-context-menu-list-box-styles.js';
3
- import './vaadin-context-menu-overlay-styles.js';
4
- import '../../src/vaadin-context-menu.js';