@vaadin/context-menu 25.0.0-alpha8 → 25.0.0-alpha9
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.
- package/package.json +12 -12
- package/src/vaadin-context-menu-mixin.js +31 -72
- package/src/vaadin-context-menu-overlay.js +1 -0
- package/src/vaadin-context-menu.d.ts +7 -6
- package/src/vaadin-context-menu.js +28 -17
- package/src/vaadin-contextmenu-items-mixin.js +19 -15
- package/src/vaadin-menu-overlay-mixin.d.ts +0 -5
- package/src/vaadin-menu-overlay-mixin.js +22 -27
- package/web-types.json +2 -2
- package/web-types.lit.json +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/context-menu",
|
|
3
|
-
"version": "25.0.0-
|
|
3
|
+
"version": "25.0.0-alpha9",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -39,19 +39,19 @@
|
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
42
|
-
"@vaadin/a11y-base": "25.0.0-
|
|
43
|
-
"@vaadin/component-base": "25.0.0-
|
|
44
|
-
"@vaadin/item": "25.0.0-
|
|
45
|
-
"@vaadin/list-box": "25.0.0-
|
|
46
|
-
"@vaadin/lit-renderer": "25.0.0-
|
|
47
|
-
"@vaadin/overlay": "25.0.0-
|
|
48
|
-
"@vaadin/vaadin-lumo-styles": "25.0.0-
|
|
49
|
-
"@vaadin/vaadin-themable-mixin": "25.0.0-
|
|
42
|
+
"@vaadin/a11y-base": "25.0.0-alpha9",
|
|
43
|
+
"@vaadin/component-base": "25.0.0-alpha9",
|
|
44
|
+
"@vaadin/item": "25.0.0-alpha9",
|
|
45
|
+
"@vaadin/list-box": "25.0.0-alpha9",
|
|
46
|
+
"@vaadin/lit-renderer": "25.0.0-alpha9",
|
|
47
|
+
"@vaadin/overlay": "25.0.0-alpha9",
|
|
48
|
+
"@vaadin/vaadin-lumo-styles": "25.0.0-alpha9",
|
|
49
|
+
"@vaadin/vaadin-themable-mixin": "25.0.0-alpha9",
|
|
50
50
|
"lit": "^3.0.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@vaadin/chai-plugins": "25.0.0-
|
|
54
|
-
"@vaadin/test-runner-commands": "25.0.0-
|
|
53
|
+
"@vaadin/chai-plugins": "25.0.0-alpha9",
|
|
54
|
+
"@vaadin/test-runner-commands": "25.0.0-alpha9",
|
|
55
55
|
"@vaadin/testing-helpers": "^2.0.0",
|
|
56
56
|
"sinon": "^18.0.0"
|
|
57
57
|
},
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"web-types.json",
|
|
60
60
|
"web-types.lit.json"
|
|
61
61
|
],
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "bbe4720721e0955ffc87a79b412bee38b1f0eb1e"
|
|
63
63
|
}
|
|
@@ -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
|
-
|
|
174
|
-
super.
|
|
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(
|
|
205
|
-
|
|
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,45 +198,17 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
213
198
|
* Runs after overlay is fully rendered
|
|
214
199
|
* @private
|
|
215
200
|
*/
|
|
216
|
-
_onVaadinOverlayOpen() {
|
|
201
|
+
_onVaadinOverlayOpen(event) {
|
|
202
|
+
// Ignore events from submenus
|
|
203
|
+
if (event.target !== this._overlayElement) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
217
207
|
this.__alignOverlayPosition();
|
|
218
208
|
this._overlayElement.style.visibility = '';
|
|
219
209
|
this.__forwardFocus();
|
|
220
210
|
}
|
|
221
211
|
|
|
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;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/** @private */
|
|
237
|
-
_overlayPhoneChanged(overlay, phone) {
|
|
238
|
-
if (overlay) {
|
|
239
|
-
overlay.toggleAttribute('phone', phone);
|
|
240
|
-
overlay.withBackdrop = phone;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
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
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
212
|
/** @private */
|
|
256
213
|
_targetOrOpenOnChanged(listenOn, openOn) {
|
|
257
214
|
if (this._oldListenOn && this._oldOpenOn) {
|
|
@@ -318,17 +275,14 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
318
275
|
}
|
|
319
276
|
|
|
320
277
|
/** @private */
|
|
321
|
-
_openedChanged(opened) {
|
|
278
|
+
_openedChanged(opened, oldOpened) {
|
|
322
279
|
if (opened) {
|
|
323
280
|
document.documentElement.addEventListener('contextmenu', this._boundOnGlobalContextMenu, true);
|
|
324
|
-
} else {
|
|
281
|
+
} else if (oldOpened) {
|
|
325
282
|
document.documentElement.removeEventListener('contextmenu', this._boundOnGlobalContextMenu, true);
|
|
326
283
|
}
|
|
327
284
|
|
|
328
285
|
this.__setListenOnUserSelect(opened);
|
|
329
|
-
|
|
330
|
-
// Has to be set after instance has been created
|
|
331
|
-
this._overlayElement.opened = opened;
|
|
332
286
|
}
|
|
333
287
|
|
|
334
288
|
/**
|
|
@@ -362,11 +316,7 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
362
316
|
if (this.closeOn === 'click') {
|
|
363
317
|
this.closeOn = '';
|
|
364
318
|
}
|
|
365
|
-
|
|
366
|
-
renderer = this.__itemsRenderer;
|
|
367
319
|
}
|
|
368
|
-
|
|
369
|
-
this._overlayElement.renderer = renderer;
|
|
370
320
|
}
|
|
371
321
|
|
|
372
322
|
/**
|
|
@@ -393,6 +343,11 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
393
343
|
* @param {!Event | undefined} e used as the context for the menu. Overlay coordinates are taken from this event.
|
|
394
344
|
*/
|
|
395
345
|
open(e) {
|
|
346
|
+
// Ignore events from the overlay
|
|
347
|
+
if (this._overlayElement && e.composedPath().includes(this._overlayElement)) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
|
|
396
351
|
if (e && !this.opened) {
|
|
397
352
|
this._context = {
|
|
398
353
|
detail: e.detail,
|
|
@@ -671,7 +626,11 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
671
626
|
// Dispatch another contextmenu at the same coordinates after the overlay is closed
|
|
672
627
|
this._overlayElement.addEventListener(
|
|
673
628
|
'vaadin-overlay-closed',
|
|
674
|
-
() =>
|
|
629
|
+
(closeEvent) => {
|
|
630
|
+
if (closeEvent.target === this._overlayElement) {
|
|
631
|
+
this.__contextMenuAt(e.clientX, e.clientY);
|
|
632
|
+
}
|
|
633
|
+
},
|
|
675
634
|
{
|
|
676
635
|
once: true,
|
|
677
636
|
},
|
|
@@ -208,18 +208,19 @@ export interface ContextMenuEventMap<TItem extends ContextMenuItem = ContextMenu
|
|
|
208
208
|
*
|
|
209
209
|
* ### Styling
|
|
210
210
|
*
|
|
211
|
-
*
|
|
212
|
-
* themable component as the actual visible context menu overlay.
|
|
211
|
+
* The following shadow DOM parts are available for styling:
|
|
213
212
|
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
213
|
+
* Part name | Description
|
|
214
|
+
* -----------------|-------------------------------------------
|
|
215
|
+
* `backdrop` | Backdrop of the overlay
|
|
216
|
+
* `overlay` | The overlay container
|
|
217
|
+
* `content` | The overlay content
|
|
216
218
|
*
|
|
217
219
|
* See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
|
|
218
220
|
*
|
|
219
221
|
* ### Internal components
|
|
220
222
|
*
|
|
221
|
-
* When using `items` API
|
|
222
|
-
* internal components are themable:
|
|
223
|
+
* When using `items` API the following internal components are themable:
|
|
223
224
|
*
|
|
224
225
|
* - `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](#/elements/vaadin-item).
|
|
225
226
|
* - `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](#/elements/vaadin-list-box).
|
|
@@ -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
|
-
*
|
|
179
|
-
* themable component as the actual visible context menu overlay.
|
|
179
|
+
* The following shadow DOM parts are available for styling:
|
|
180
180
|
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
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
|
|
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).
|
|
@@ -232,17 +234,26 @@ class ContextMenu extends ContextMenuMixin(
|
|
|
232
234
|
|
|
233
235
|
/** @protected */
|
|
234
236
|
render() {
|
|
235
|
-
return html
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
237
|
+
return html`
|
|
238
|
+
<slot id="slot"></slot>
|
|
239
|
+
<vaadin-context-menu-overlay
|
|
240
|
+
id="overlay"
|
|
241
|
+
.owner="${this}"
|
|
242
|
+
.opened="${this.opened}"
|
|
243
|
+
.model="${this._context}"
|
|
244
|
+
.modeless="${this._modeless}"
|
|
245
|
+
.renderer="${this.items ? this.__itemsRenderer : this.renderer}"
|
|
246
|
+
.withBackdrop="${this._phone}"
|
|
247
|
+
?phone="${this._phone}"
|
|
248
|
+
theme="${ifDefined(this._theme)}"
|
|
249
|
+
exportparts="backdrop, overlay, content"
|
|
250
|
+
@opened-changed="${this._onOverlayOpened}"
|
|
251
|
+
@vaadin-overlay-open="${this._onVaadinOverlayOpen}"
|
|
252
|
+
>
|
|
253
|
+
<slot name="overlay"></slot>
|
|
254
|
+
<slot name="submenu" slot="submenu"></slot>
|
|
255
|
+
</vaadin-context-menu-overlay>
|
|
256
|
+
`;
|
|
246
257
|
}
|
|
247
258
|
|
|
248
259
|
/**
|
|
@@ -116,10 +116,10 @@ export const ItemsMixin = (superClass) =>
|
|
|
116
116
|
/** @protected */
|
|
117
117
|
__forwardFocus() {
|
|
118
118
|
const overlay = this._overlayElement;
|
|
119
|
-
const child = overlay.
|
|
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.
|
|
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
|
-
|
|
410
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
|
153
|
-
*
|
|
154
|
-
*
|
|
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
|
-
|
|
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": "25.0.0-
|
|
4
|
+
"version": "25.0.0-alpha9",
|
|
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\
|
|
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-alpha9/#/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-alpha9/#/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",
|
package/web-types.lit.json
CHANGED
|
@@ -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-
|
|
4
|
+
"version": "25.0.0-alpha9",
|
|
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\
|
|
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-alpha9/#/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-alpha9/#/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
|
{
|