@vaadin/context-menu 24.3.0-beta1 → 24.3.0-rc1
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 +14 -12
- package/src/vaadin-context-menu-mixin.js +73 -11
- package/src/vaadin-context-menu.js +13 -11
- package/src/vaadin-contextmenu-items-mixin.js +13 -8
- package/src/vaadin-lit-context-menu-item.js +60 -0
- package/src/vaadin-lit-context-menu-list-box.js +87 -0
- package/src/vaadin-lit-context-menu-overlay.js +67 -0
- package/src/vaadin-lit-context-menu.js +79 -0
- package/src/vaadin-menu-overlay-mixin.js +9 -0
- package/theme/lumo/vaadin-lit-context-menu.js +4 -0
- package/theme/material/vaadin-lit-context-menu.js +4 -0
- 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": "24.3.0-
|
|
3
|
+
"version": "24.3.0-rc1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -27,7 +27,9 @@
|
|
|
27
27
|
"vaadin-*.d.ts",
|
|
28
28
|
"vaadin-*.js",
|
|
29
29
|
"web-types.json",
|
|
30
|
-
"web-types.lit.json"
|
|
30
|
+
"web-types.lit.json",
|
|
31
|
+
"!vaadin-lit-*.d.ts",
|
|
32
|
+
"!vaadin-lit-*.js"
|
|
31
33
|
],
|
|
32
34
|
"keywords": [
|
|
33
35
|
"Vaadin",
|
|
@@ -39,15 +41,15 @@
|
|
|
39
41
|
"dependencies": {
|
|
40
42
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
41
43
|
"@polymer/polymer": "^3.0.0",
|
|
42
|
-
"@vaadin/a11y-base": "24.3.0-
|
|
43
|
-
"@vaadin/component-base": "24.3.0-
|
|
44
|
-
"@vaadin/item": "24.3.0-
|
|
45
|
-
"@vaadin/list-box": "24.3.0-
|
|
46
|
-
"@vaadin/lit-renderer": "24.3.0-
|
|
47
|
-
"@vaadin/overlay": "24.3.0-
|
|
48
|
-
"@vaadin/vaadin-lumo-styles": "24.3.0-
|
|
49
|
-
"@vaadin/vaadin-material-styles": "24.3.0-
|
|
50
|
-
"@vaadin/vaadin-themable-mixin": "24.3.0-
|
|
44
|
+
"@vaadin/a11y-base": "24.3.0-rc1",
|
|
45
|
+
"@vaadin/component-base": "24.3.0-rc1",
|
|
46
|
+
"@vaadin/item": "24.3.0-rc1",
|
|
47
|
+
"@vaadin/list-box": "24.3.0-rc1",
|
|
48
|
+
"@vaadin/lit-renderer": "24.3.0-rc1",
|
|
49
|
+
"@vaadin/overlay": "24.3.0-rc1",
|
|
50
|
+
"@vaadin/vaadin-lumo-styles": "24.3.0-rc1",
|
|
51
|
+
"@vaadin/vaadin-material-styles": "24.3.0-rc1",
|
|
52
|
+
"@vaadin/vaadin-themable-mixin": "24.3.0-rc1"
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
|
53
55
|
"@esm-bundle/chai": "^4.3.4",
|
|
@@ -59,5 +61,5 @@
|
|
|
59
61
|
"web-types.json",
|
|
60
62
|
"web-types.lit.json"
|
|
61
63
|
],
|
|
62
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "54430cfc0f52bb6fc17b0fc325b0d62e0e49c700"
|
|
63
65
|
}
|
|
@@ -43,6 +43,7 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
43
43
|
openOn: {
|
|
44
44
|
type: String,
|
|
45
45
|
value: 'vaadin-contextmenu',
|
|
46
|
+
sync: true,
|
|
46
47
|
},
|
|
47
48
|
|
|
48
49
|
/**
|
|
@@ -54,6 +55,7 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
54
55
|
*/
|
|
55
56
|
listenOn: {
|
|
56
57
|
type: Object,
|
|
58
|
+
sync: true,
|
|
57
59
|
value() {
|
|
58
60
|
return this;
|
|
59
61
|
},
|
|
@@ -68,6 +70,7 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
68
70
|
type: String,
|
|
69
71
|
value: 'click',
|
|
70
72
|
observer: '_closeOnChanged',
|
|
73
|
+
sync: true,
|
|
71
74
|
},
|
|
72
75
|
|
|
73
76
|
/**
|
|
@@ -83,6 +86,7 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
83
86
|
*/
|
|
84
87
|
renderer: {
|
|
85
88
|
type: Function,
|
|
89
|
+
sync: true,
|
|
86
90
|
},
|
|
87
91
|
|
|
88
92
|
/**
|
|
@@ -91,10 +95,14 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
91
95
|
*/
|
|
92
96
|
_modeless: {
|
|
93
97
|
type: Boolean,
|
|
98
|
+
sync: true,
|
|
94
99
|
},
|
|
95
100
|
|
|
96
101
|
/** @private */
|
|
97
|
-
_context:
|
|
102
|
+
_context: {
|
|
103
|
+
type: Object,
|
|
104
|
+
sync: true,
|
|
105
|
+
},
|
|
98
106
|
|
|
99
107
|
/** @private */
|
|
100
108
|
_phone: {
|
|
@@ -126,11 +134,18 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
126
134
|
'_targetOrOpenOnChanged(listenOn, openOn)',
|
|
127
135
|
'_rendererChanged(renderer, items)',
|
|
128
136
|
'_touchOrWideChanged(_touch, _wide)',
|
|
137
|
+
'_overlayContextChanged(_overlayElement, _context)',
|
|
138
|
+
'_overlayModelessChanged(_overlayElement, _modeless)',
|
|
139
|
+
'_overlayPhoneChanged(_overlayElement, _phone)',
|
|
140
|
+
'_overlayThemeChanged(_overlayElement, _theme)',
|
|
129
141
|
];
|
|
130
142
|
}
|
|
131
143
|
|
|
132
144
|
constructor() {
|
|
133
145
|
super();
|
|
146
|
+
|
|
147
|
+
this._createOverlay();
|
|
148
|
+
|
|
134
149
|
this._boundOpen = this.open.bind(this);
|
|
135
150
|
this._boundClose = this.close.bind(this);
|
|
136
151
|
this._boundPreventDefault = this._preventDefault.bind(this);
|
|
@@ -165,9 +180,6 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
165
180
|
ready() {
|
|
166
181
|
super.ready();
|
|
167
182
|
|
|
168
|
-
this._overlayElement = this.$.overlay;
|
|
169
|
-
this._overlayElement.owner = this;
|
|
170
|
-
|
|
171
183
|
this.addController(
|
|
172
184
|
new MediaQueryController(this._wideMediaQuery, (matches) => {
|
|
173
185
|
this._wide = matches;
|
|
@@ -175,6 +187,23 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
175
187
|
);
|
|
176
188
|
}
|
|
177
189
|
|
|
190
|
+
/** @private */
|
|
191
|
+
_createOverlay() {
|
|
192
|
+
// Create an overlay in the constructor to use in observers before `ready()`
|
|
193
|
+
const overlay = document.createElement(`${this._tagNamePrefix}-overlay`);
|
|
194
|
+
overlay.owner = this;
|
|
195
|
+
|
|
196
|
+
overlay.addEventListener('opened-changed', (e) => {
|
|
197
|
+
this._onOverlayOpened(e);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
overlay.addEventListener('vaadin-overlay-open', (e) => {
|
|
201
|
+
this._onVaadinOverlayOpen(e);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
this._overlayElement = overlay;
|
|
205
|
+
}
|
|
206
|
+
|
|
178
207
|
/**
|
|
179
208
|
* Runs before overlay is fully rendered
|
|
180
209
|
* @private
|
|
@@ -190,10 +219,43 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
190
219
|
*/
|
|
191
220
|
_onVaadinOverlayOpen() {
|
|
192
221
|
this.__alignOverlayPosition();
|
|
193
|
-
this
|
|
222
|
+
this._overlayElement.style.opacity = '';
|
|
194
223
|
this.__forwardFocus();
|
|
195
224
|
}
|
|
196
225
|
|
|
226
|
+
/** @private */
|
|
227
|
+
_overlayContextChanged(overlay, context) {
|
|
228
|
+
if (overlay) {
|
|
229
|
+
overlay.model = context;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** @private */
|
|
234
|
+
_overlayModelessChanged(overlay, modeless) {
|
|
235
|
+
if (overlay) {
|
|
236
|
+
overlay.modeless = modeless;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** @private */
|
|
241
|
+
_overlayPhoneChanged(overlay, phone) {
|
|
242
|
+
if (overlay) {
|
|
243
|
+
overlay.toggleAttribute('phone', phone);
|
|
244
|
+
overlay.withBackdrop = phone;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** @private */
|
|
249
|
+
_overlayThemeChanged(overlay, theme) {
|
|
250
|
+
if (overlay) {
|
|
251
|
+
if (theme) {
|
|
252
|
+
overlay.setAttribute('theme', theme);
|
|
253
|
+
} else {
|
|
254
|
+
overlay.removeAttribute('theme');
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
197
259
|
/** @private */
|
|
198
260
|
_targetOrOpenOnChanged(listenOn, openOn) {
|
|
199
261
|
if (this._oldListenOn && this._oldOpenOn) {
|
|
@@ -238,7 +300,7 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
238
300
|
// Outside click event from overlay
|
|
239
301
|
const evtOverlay = 'vaadin-overlay-outside-click';
|
|
240
302
|
|
|
241
|
-
const overlay = this
|
|
303
|
+
const overlay = this._overlayElement;
|
|
242
304
|
|
|
243
305
|
if (oldCloseOn) {
|
|
244
306
|
this._unlisten(overlay, oldCloseOn, this._boundClose);
|
|
@@ -267,7 +329,7 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
267
329
|
}
|
|
268
330
|
|
|
269
331
|
// Has to be set after instance has been created
|
|
270
|
-
this
|
|
332
|
+
this._overlayElement.opened = opened;
|
|
271
333
|
}
|
|
272
334
|
|
|
273
335
|
/**
|
|
@@ -298,7 +360,7 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
298
360
|
renderer = this.__itemsRenderer;
|
|
299
361
|
}
|
|
300
362
|
|
|
301
|
-
this
|
|
363
|
+
this._overlayElement.renderer = renderer;
|
|
302
364
|
}
|
|
303
365
|
|
|
304
366
|
/**
|
|
@@ -342,7 +404,7 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
342
404
|
this.__y = this._getEventCoordinate(e, 'y');
|
|
343
405
|
this.__pageYOffset = window.pageYOffset;
|
|
344
406
|
|
|
345
|
-
this
|
|
407
|
+
this._overlayElement.style.opacity = '0';
|
|
346
408
|
this._setOpened(true);
|
|
347
409
|
}
|
|
348
410
|
}
|
|
@@ -369,7 +431,7 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
369
431
|
|
|
370
432
|
/** @private */
|
|
371
433
|
__adjustPosition(coord, diff) {
|
|
372
|
-
const overlay = this
|
|
434
|
+
const overlay = this._overlayElement;
|
|
373
435
|
const style = overlay.style;
|
|
374
436
|
|
|
375
437
|
style[coord] = `${(parseInt(style[coord]) || 0) + diff}px`;
|
|
@@ -377,7 +439,7 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
377
439
|
|
|
378
440
|
/** @private */
|
|
379
441
|
__alignOverlayPosition() {
|
|
380
|
-
const overlay = this
|
|
442
|
+
const overlay = this._overlayElement;
|
|
381
443
|
|
|
382
444
|
if (overlay.positionTarget) {
|
|
383
445
|
// The overlay is positioned relative to another node, for example, a
|
|
@@ -222,17 +222,6 @@ class ContextMenu extends ContextMenuMixin(
|
|
|
222
222
|
</style>
|
|
223
223
|
|
|
224
224
|
<slot id="slot"></slot>
|
|
225
|
-
|
|
226
|
-
<vaadin-context-menu-overlay
|
|
227
|
-
id="overlay"
|
|
228
|
-
on-opened-changed="_onOverlayOpened"
|
|
229
|
-
on-vaadin-overlay-open="_onVaadinOverlayOpen"
|
|
230
|
-
modeless="[[_modeless]]"
|
|
231
|
-
with-backdrop="[[_phone]]"
|
|
232
|
-
phone$="[[_phone]]"
|
|
233
|
-
model="[[_context]]"
|
|
234
|
-
theme$="[[_theme]]"
|
|
235
|
-
></vaadin-context-menu-overlay>
|
|
236
225
|
`;
|
|
237
226
|
}
|
|
238
227
|
|
|
@@ -247,6 +236,19 @@ class ContextMenu extends ContextMenuMixin(
|
|
|
247
236
|
processTemplates(this);
|
|
248
237
|
}
|
|
249
238
|
|
|
239
|
+
/**
|
|
240
|
+
* @param {DocumentFragment} dom
|
|
241
|
+
* @return {null}
|
|
242
|
+
* @protected
|
|
243
|
+
* @override
|
|
244
|
+
*/
|
|
245
|
+
_attachDom(dom) {
|
|
246
|
+
const root = this.attachShadow({ mode: 'open' });
|
|
247
|
+
root.appendChild(dom);
|
|
248
|
+
root.appendChild(this._overlayElement);
|
|
249
|
+
return root;
|
|
250
|
+
}
|
|
251
|
+
|
|
250
252
|
/**
|
|
251
253
|
* Fired when an item is selected when the context menu is populated using the `items` API.
|
|
252
254
|
*
|
|
@@ -66,7 +66,10 @@ export const ItemsMixin = (superClass) =>
|
|
|
66
66
|
* ----------------|----------------|----------------
|
|
67
67
|
* `:host` | expanded | Expanded parent item
|
|
68
68
|
*/
|
|
69
|
-
items:
|
|
69
|
+
items: {
|
|
70
|
+
type: Array,
|
|
71
|
+
sync: true,
|
|
72
|
+
},
|
|
70
73
|
};
|
|
71
74
|
}
|
|
72
75
|
|
|
@@ -110,7 +113,7 @@ export const ItemsMixin = (superClass) =>
|
|
|
110
113
|
|
|
111
114
|
/** @protected */
|
|
112
115
|
__forwardFocus() {
|
|
113
|
-
const overlay = this
|
|
116
|
+
const overlay = this._overlayElement;
|
|
114
117
|
const child = overlay.getFirstChild();
|
|
115
118
|
// If parent item is not focused, do not focus submenu
|
|
116
119
|
if (overlay.parentOverlay) {
|
|
@@ -131,9 +134,9 @@ export const ItemsMixin = (superClass) =>
|
|
|
131
134
|
subMenu.listenOn = itemElement;
|
|
132
135
|
subMenu.overlayClass = overlayClass;
|
|
133
136
|
|
|
134
|
-
const parent = this
|
|
137
|
+
const parent = this._overlayElement;
|
|
135
138
|
|
|
136
|
-
const subMenuOverlay = subMenu
|
|
139
|
+
const subMenuOverlay = subMenu._overlayElement;
|
|
137
140
|
subMenuOverlay.positionTarget = itemElement;
|
|
138
141
|
subMenuOverlay.noHorizontalOverlap = true;
|
|
139
142
|
// Store the reference parent overlay
|
|
@@ -146,7 +149,7 @@ export const ItemsMixin = (superClass) =>
|
|
|
146
149
|
subMenu.removeAttribute('theme');
|
|
147
150
|
}
|
|
148
151
|
|
|
149
|
-
const content =
|
|
152
|
+
const content = subMenuOverlay.$.content;
|
|
150
153
|
content.style.minWidth = '';
|
|
151
154
|
|
|
152
155
|
itemElement.dispatchEvent(
|
|
@@ -233,7 +236,7 @@ export const ItemsMixin = (superClass) =>
|
|
|
233
236
|
|
|
234
237
|
/** @private */
|
|
235
238
|
__initOverlay() {
|
|
236
|
-
const overlay = this
|
|
239
|
+
const overlay = this._overlayElement;
|
|
237
240
|
|
|
238
241
|
overlay.$.backdrop.addEventListener('click', () => {
|
|
239
242
|
this.close();
|
|
@@ -300,7 +303,9 @@ export const ItemsMixin = (superClass) =>
|
|
|
300
303
|
|
|
301
304
|
// Listen to the forwarded event from sub-menu.
|
|
302
305
|
this.addEventListener('close-all-menus', () => {
|
|
303
|
-
|
|
306
|
+
// Call `close()` on the overlay to close synchronously,
|
|
307
|
+
// as we can't have `sync: true` on `opened` property.
|
|
308
|
+
this._overlayElement.close();
|
|
304
309
|
});
|
|
305
310
|
|
|
306
311
|
// Listen to the forwarded event from sub-menu.
|
|
@@ -342,7 +347,7 @@ export const ItemsMixin = (superClass) =>
|
|
|
342
347
|
}
|
|
343
348
|
|
|
344
349
|
// Don't open sub-menus while the menu is still opening
|
|
345
|
-
if (this
|
|
350
|
+
if (this._overlayElement.hasAttribute('opening')) {
|
|
346
351
|
requestAnimationFrame(() => {
|
|
347
352
|
this.__showSubMenu(event, item);
|
|
348
353
|
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { css, html, LitElement } from 'lit';
|
|
7
|
+
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
8
|
+
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
9
|
+
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
|
|
10
|
+
import { ItemMixin } from '@vaadin/item/src/vaadin-item-mixin.js';
|
|
11
|
+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
15
|
+
*
|
|
16
|
+
* @customElement
|
|
17
|
+
* @extends HTMLElement
|
|
18
|
+
* @mixes DirMixin
|
|
19
|
+
* @mixes ItemMixin
|
|
20
|
+
* @mixes ThemableMixin
|
|
21
|
+
* @protected
|
|
22
|
+
*/
|
|
23
|
+
class ContextMenuItem extends ItemMixin(ThemableMixin(DirMixin(PolylitMixin(LitElement)))) {
|
|
24
|
+
static get is() {
|
|
25
|
+
return 'vaadin-context-menu-item';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static get styles() {
|
|
29
|
+
return css`
|
|
30
|
+
:host {
|
|
31
|
+
display: inline-block;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
:host([hidden]) {
|
|
35
|
+
display: none !important;
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** @protected */
|
|
41
|
+
render() {
|
|
42
|
+
return html`
|
|
43
|
+
<span part="checkmark" aria-hidden="true"></span>
|
|
44
|
+
<div part="content">
|
|
45
|
+
<slot></slot>
|
|
46
|
+
</div>
|
|
47
|
+
`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** @protected */
|
|
51
|
+
ready() {
|
|
52
|
+
super.ready();
|
|
53
|
+
|
|
54
|
+
this.setAttribute('role', 'menuitem');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
defineCustomElement(ContextMenuItem);
|
|
59
|
+
|
|
60
|
+
export { ContextMenuItem };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { css, html, LitElement } from 'lit';
|
|
7
|
+
import { ListMixin } from '@vaadin/a11y-base/src/list-mixin.js';
|
|
8
|
+
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
9
|
+
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
10
|
+
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
|
|
11
|
+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
15
|
+
*
|
|
16
|
+
* @customElement
|
|
17
|
+
* @extends HTMLElement
|
|
18
|
+
* @mixes DirMixin
|
|
19
|
+
* @mixes ListMixin
|
|
20
|
+
* @mixes ThemableMixin
|
|
21
|
+
* @protected
|
|
22
|
+
*/
|
|
23
|
+
class ContextMenuListBox extends ListMixin(ThemableMixin(DirMixin(PolylitMixin(LitElement)))) {
|
|
24
|
+
static get is() {
|
|
25
|
+
return 'vaadin-context-menu-list-box';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static get styles() {
|
|
29
|
+
return css`
|
|
30
|
+
:host {
|
|
31
|
+
display: flex;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
:host([hidden]) {
|
|
35
|
+
display: none !important;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
[part='items'] {
|
|
39
|
+
height: 100%;
|
|
40
|
+
width: 100%;
|
|
41
|
+
overflow-y: auto;
|
|
42
|
+
-webkit-overflow-scrolling: touch;
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static get properties() {
|
|
48
|
+
return {
|
|
49
|
+
// We don't need to define this property since super default is vertical,
|
|
50
|
+
// but we don't want it to be modified, or be shown in the API docs.
|
|
51
|
+
/** @private */
|
|
52
|
+
orientation: {
|
|
53
|
+
type: String,
|
|
54
|
+
readOnly: true,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @return {!HTMLElement}
|
|
61
|
+
* @protected
|
|
62
|
+
* @override
|
|
63
|
+
*/
|
|
64
|
+
get _scrollerElement() {
|
|
65
|
+
return this.shadowRoot.querySelector('[part="items"]');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** @protected */
|
|
69
|
+
render() {
|
|
70
|
+
return html`
|
|
71
|
+
<div part="items">
|
|
72
|
+
<slot></slot>
|
|
73
|
+
</div>
|
|
74
|
+
`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @protected */
|
|
78
|
+
ready() {
|
|
79
|
+
super.ready();
|
|
80
|
+
|
|
81
|
+
this.setAttribute('role', 'menu');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
defineCustomElement(ContextMenuListBox);
|
|
86
|
+
|
|
87
|
+
export { ContextMenuListBox };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { html, LitElement } from 'lit';
|
|
7
|
+
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
8
|
+
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
9
|
+
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
|
|
10
|
+
import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js';
|
|
11
|
+
import { overlayStyles } from '@vaadin/overlay/src/vaadin-overlay-styles.js';
|
|
12
|
+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
13
|
+
import { MenuOverlayMixin } from './vaadin-menu-overlay-mixin.js';
|
|
14
|
+
import { styles } from './vaadin-menu-overlay-styles.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
18
|
+
*
|
|
19
|
+
* @customElement
|
|
20
|
+
* @extends HTMLElement
|
|
21
|
+
* @mixes DirMixin
|
|
22
|
+
* @mixes MenuOverlayMixin
|
|
23
|
+
* @mixes OverlayMixin
|
|
24
|
+
* @mixes ThemableMixin
|
|
25
|
+
* @protected
|
|
26
|
+
*/
|
|
27
|
+
export class ContextMenuOverlay extends MenuOverlayMixin(
|
|
28
|
+
OverlayMixin(DirMixin(ThemableMixin(PolylitMixin(LitElement)))),
|
|
29
|
+
) {
|
|
30
|
+
static get is() {
|
|
31
|
+
return 'vaadin-context-menu-overlay';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static get properties() {
|
|
35
|
+
return {
|
|
36
|
+
/**
|
|
37
|
+
* When true, the overlay is visible and attached to body.
|
|
38
|
+
* This property config is overridden to set `sync: true`.
|
|
39
|
+
*/
|
|
40
|
+
opened: {
|
|
41
|
+
type: Boolean,
|
|
42
|
+
notify: true,
|
|
43
|
+
observer: '_openedChanged',
|
|
44
|
+
reflectToAttribute: true,
|
|
45
|
+
sync: true,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static get styles() {
|
|
51
|
+
return [overlayStyles, styles];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @protected */
|
|
55
|
+
render() {
|
|
56
|
+
return html`
|
|
57
|
+
<div id="backdrop" part="backdrop" ?hidden="${!this.withBackdrop}"></div>
|
|
58
|
+
<div part="overlay" id="overlay" tabindex="0">
|
|
59
|
+
<div part="content" id="content">
|
|
60
|
+
<slot></slot>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
defineCustomElement(ContextMenuOverlay);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import './vaadin-contextmenu-event.js';
|
|
7
|
+
import './vaadin-lit-context-menu-item.js';
|
|
8
|
+
import './vaadin-lit-context-menu-list-box.js';
|
|
9
|
+
import './vaadin-lit-context-menu-overlay.js';
|
|
10
|
+
import { css, html, LitElement } from 'lit';
|
|
11
|
+
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
12
|
+
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
13
|
+
import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
|
|
14
|
+
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
|
|
15
|
+
import { processTemplates } from '@vaadin/component-base/src/templates.js';
|
|
16
|
+
import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
|
|
17
|
+
import { ContextMenuMixin } from './vaadin-context-menu-mixin.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* LitElement based version of `<vaadin-context-menu>` web component.
|
|
21
|
+
*
|
|
22
|
+
* ## Disclaimer
|
|
23
|
+
*
|
|
24
|
+
* This component is an experiment not intended for publishing to npm.
|
|
25
|
+
* There is no ETA regarding specific Vaadin version where it'll land.
|
|
26
|
+
* Feel free to try this code in your apps as per Apache 2.0 license.
|
|
27
|
+
*/
|
|
28
|
+
class ContextMenu extends ContextMenuMixin(
|
|
29
|
+
OverlayClassMixin(ElementMixin(ThemePropertyMixin(PolylitMixin(LitElement)))),
|
|
30
|
+
) {
|
|
31
|
+
static get is() {
|
|
32
|
+
return 'vaadin-context-menu';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static get styles() {
|
|
36
|
+
return css`
|
|
37
|
+
:host {
|
|
38
|
+
display: block;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
:host([hidden]) {
|
|
42
|
+
display: none !important;
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @protected */
|
|
48
|
+
render() {
|
|
49
|
+
return html`<slot id="slot"></slot>`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @protected */
|
|
53
|
+
ready() {
|
|
54
|
+
super.ready();
|
|
55
|
+
|
|
56
|
+
processTemplates(this);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @protected
|
|
61
|
+
* @override
|
|
62
|
+
*/
|
|
63
|
+
createRenderRoot() {
|
|
64
|
+
const root = super.createRenderRoot();
|
|
65
|
+
root.appendChild(this._overlayElement);
|
|
66
|
+
return root;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Fired when an item is selected when the context menu is populated using the `items` API.
|
|
71
|
+
*
|
|
72
|
+
* @event item-selected
|
|
73
|
+
* @param {Object} detail
|
|
74
|
+
* @param {Object} detail.value the selected menu item
|
|
75
|
+
*/
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
defineCustomElement(ContextMenu);
|
|
79
|
+
export { ContextMenu };
|
package/web-types.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/web-types",
|
|
3
3
|
"name": "@vaadin/context-menu",
|
|
4
|
-
"version": "24.3.0-
|
|
4
|
+
"version": "24.3.0-rc1",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"contributions": {
|
|
7
7
|
"html": {
|
|
8
8
|
"elements": [
|
|
9
9
|
{
|
|
10
10
|
"name": "vaadin-context-menu",
|
|
11
|
-
"description": "`<vaadin-context-menu>` is a Web Component for creating context menus.\n\n### Items\n\nItems is a higher level convenience API for defining a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nWhen an item is selected, `<vaadin-context-menu>` dispatches an \"item-selected\" event\nwith the selected item as `event.detail.value` property.\nIf item does not have `keepOpen` property the menu will be closed.\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n\ncontextMenu.addEventListener('item-selected', e => {\n const item = e.detail.value;\n console.log(`${item.text} selected`);\n});\n```\n\n**NOTE:** when the `items` array is defined, the renderer cannot be used.\n\n### Rendering\n\nThe content of the menu can be populated by using the renderer callback function.\n\nThe renderer function provides `root`, `contextMenu`, `model` arguments when applicable.\nGenerate DOM content by using `model` object properties if needed, append it to the `root`\nelement and control the state of the host element by accessing `contextMenu`. Before generating\nnew content, the renderer function should check if there is already content in `root` for reusing it.\n\n```html\n<vaadin-context-menu id=\"contextMenu\">\n <p>This paragraph has a context menu.</p>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'Content of the selector: ' + context.target.textContent;\n};\n```\n\nYou can access the menu context inside the renderer using\n`context.target` and `context.detail`.\n\nRenderer is called on the opening of the context-menu and each time the related context is updated.\nDOM generated during the renderer call can be reused\nin the next renderer call and will be provided with the `root` argument.\nOn first call it will be empty.\n\n### `vaadin-contextmenu` Gesture Event\n\n`vaadin-contextmenu` is a gesture event (a custom event),\nwhich is dispatched after either `contextmenu` or long touch events.\nThis enables support for both mouse and touch environments in a uniform way.\n\n`<vaadin-context-menu>` opens the menu overlay on the `vaadin-contextmenu`\nevent by default.\n\n### Menu Listener\n\nBy default, the `<vaadin-context-menu>` element listens for the menu opening\nevent on itself. In case if you do not want to wrap the target, you can listen for\nevents on an element outside the `<vaadin-context-menu>` by setting the\n`listenOn` property:\n\n```html\n<vaadin-context-menu id=\"contextMenu\"></vaadin-context-menu>\n\n<div id=\"menuListener\">The element that listens for the contextmenu event.</div>\n```\n```javascript\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.listenOn = document.querySelector('#menuListener');\n```\n\n### Filtering Menu Targets\n\nBy default, the listener element and all its descendants open the context\nmenu. You can filter the menu targets to a smaller set of elements inside\nthe listener element by setting the `selector` property.\n\nIn the following example, only the elements matching `.has-menu` will open the context menu:\n\n```html\n<vaadin-context-menu selector=\".has-menu\">\n <p class=\"has-menu\">This paragraph opens the context menu</p>\n <p>This paragraph does not open the context menu</p>\n</vaadin-context-menu>\n```\n\n### Menu Context\n\nThe following properties are available in the `context` argument:\n\n- `target` is the menu opening event target, which is the element that\nthe user has called the context menu for\n- `detail` is the menu opening event detail\n\nIn the following example, the menu item text is composed with the contents\nof the element that opened the menu:\n\n```html\n<vaadin-context-menu selector=\"li\" id=\"contextMenu\">\n <ul>\n <li>Foo</li>\n <li>Bar</li>\n <li>Baz</li>\n </ul>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'The menu target: ' + context.target.textContent;\n};\n```\n\n### Styling\n\n`<vaadin-context-menu>` uses `<vaadin-context-menu-overlay>` internal\nthemable component as the actual visible context menu overlay.\n\nSee [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-
|
|
11
|
+
"description": "`<vaadin-context-menu>` is a Web Component for creating context menus.\n\n### Items\n\nItems is a higher level convenience API for defining a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nWhen an item is selected, `<vaadin-context-menu>` dispatches an \"item-selected\" event\nwith the selected item as `event.detail.value` property.\nIf item does not have `keepOpen` property the menu will be closed.\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n\ncontextMenu.addEventListener('item-selected', e => {\n const item = e.detail.value;\n console.log(`${item.text} selected`);\n});\n```\n\n**NOTE:** when the `items` array is defined, the renderer cannot be used.\n\n### Rendering\n\nThe content of the menu can be populated by using the renderer callback function.\n\nThe renderer function provides `root`, `contextMenu`, `model` arguments when applicable.\nGenerate DOM content by using `model` object properties if needed, append it to the `root`\nelement and control the state of the host element by accessing `contextMenu`. Before generating\nnew content, the renderer function should check if there is already content in `root` for reusing it.\n\n```html\n<vaadin-context-menu id=\"contextMenu\">\n <p>This paragraph has a context menu.</p>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'Content of the selector: ' + context.target.textContent;\n};\n```\n\nYou can access the menu context inside the renderer using\n`context.target` and `context.detail`.\n\nRenderer is called on the opening of the context-menu and each time the related context is updated.\nDOM generated during the renderer call can be reused\nin the next renderer call and will be provided with the `root` argument.\nOn first call it will be empty.\n\n### `vaadin-contextmenu` Gesture Event\n\n`vaadin-contextmenu` is a gesture event (a custom event),\nwhich is dispatched after either `contextmenu` or long touch events.\nThis enables support for both mouse and touch environments in a uniform way.\n\n`<vaadin-context-menu>` opens the menu overlay on the `vaadin-contextmenu`\nevent by default.\n\n### Menu Listener\n\nBy default, the `<vaadin-context-menu>` element listens for the menu opening\nevent on itself. In case if you do not want to wrap the target, you can listen for\nevents on an element outside the `<vaadin-context-menu>` by setting the\n`listenOn` property:\n\n```html\n<vaadin-context-menu id=\"contextMenu\"></vaadin-context-menu>\n\n<div id=\"menuListener\">The element that listens for the contextmenu event.</div>\n```\n```javascript\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.listenOn = document.querySelector('#menuListener');\n```\n\n### Filtering Menu Targets\n\nBy default, the listener element and all its descendants open the context\nmenu. You can filter the menu targets to a smaller set of elements inside\nthe listener element by setting the `selector` property.\n\nIn the following example, only the elements matching `.has-menu` will open the context menu:\n\n```html\n<vaadin-context-menu selector=\".has-menu\">\n <p class=\"has-menu\">This paragraph opens the context menu</p>\n <p>This paragraph does not open the context menu</p>\n</vaadin-context-menu>\n```\n\n### Menu Context\n\nThe following properties are available in the `context` argument:\n\n- `target` is the menu opening event target, which is the element that\nthe user has called the context menu for\n- `detail` is the menu opening event detail\n\nIn the following example, the menu item text is composed with the contents\nof the element that opened the menu:\n\n```html\n<vaadin-context-menu selector=\"li\" id=\"contextMenu\">\n <ul>\n <li>Foo</li>\n <li>Bar</li>\n <li>Baz</li>\n </ul>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'The menu target: ' + context.target.textContent;\n};\n```\n\n### Styling\n\n`<vaadin-context-menu>` uses `<vaadin-context-menu-overlay>` internal\nthemable component as the actual visible context menu overlay.\n\nSee [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-rc1/#/elements/vaadin-overlay)\ndocumentation for `<vaadin-context-menu-overlay>` stylable parts.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.\n\n### Internal components\n\nWhen using `items` API, in addition `<vaadin-context-menu-overlay>`, the following\ninternal components are themable:\n\n- `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-rc1/#/elements/vaadin-item).\n- `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-rc1/#/elements/vaadin-list-box).\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": "24.3.0-
|
|
4
|
+
"version": "24.3.0-rc1",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"framework": "lit",
|
|
7
7
|
"framework-config": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"elements": [
|
|
17
17
|
{
|
|
18
18
|
"name": "vaadin-context-menu",
|
|
19
|
-
"description": "`<vaadin-context-menu>` is a Web Component for creating context menus.\n\n### Items\n\nItems is a higher level convenience API for defining a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nWhen an item is selected, `<vaadin-context-menu>` dispatches an \"item-selected\" event\nwith the selected item as `event.detail.value` property.\nIf item does not have `keepOpen` property the menu will be closed.\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n\ncontextMenu.addEventListener('item-selected', e => {\n const item = e.detail.value;\n console.log(`${item.text} selected`);\n});\n```\n\n**NOTE:** when the `items` array is defined, the renderer cannot be used.\n\n### Rendering\n\nThe content of the menu can be populated by using the renderer callback function.\n\nThe renderer function provides `root`, `contextMenu`, `model` arguments when applicable.\nGenerate DOM content by using `model` object properties if needed, append it to the `root`\nelement and control the state of the host element by accessing `contextMenu`. Before generating\nnew content, the renderer function should check if there is already content in `root` for reusing it.\n\n```html\n<vaadin-context-menu id=\"contextMenu\">\n <p>This paragraph has a context menu.</p>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'Content of the selector: ' + context.target.textContent;\n};\n```\n\nYou can access the menu context inside the renderer using\n`context.target` and `context.detail`.\n\nRenderer is called on the opening of the context-menu and each time the related context is updated.\nDOM generated during the renderer call can be reused\nin the next renderer call and will be provided with the `root` argument.\nOn first call it will be empty.\n\n### `vaadin-contextmenu` Gesture Event\n\n`vaadin-contextmenu` is a gesture event (a custom event),\nwhich is dispatched after either `contextmenu` or long touch events.\nThis enables support for both mouse and touch environments in a uniform way.\n\n`<vaadin-context-menu>` opens the menu overlay on the `vaadin-contextmenu`\nevent by default.\n\n### Menu Listener\n\nBy default, the `<vaadin-context-menu>` element listens for the menu opening\nevent on itself. In case if you do not want to wrap the target, you can listen for\nevents on an element outside the `<vaadin-context-menu>` by setting the\n`listenOn` property:\n\n```html\n<vaadin-context-menu id=\"contextMenu\"></vaadin-context-menu>\n\n<div id=\"menuListener\">The element that listens for the contextmenu event.</div>\n```\n```javascript\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.listenOn = document.querySelector('#menuListener');\n```\n\n### Filtering Menu Targets\n\nBy default, the listener element and all its descendants open the context\nmenu. You can filter the menu targets to a smaller set of elements inside\nthe listener element by setting the `selector` property.\n\nIn the following example, only the elements matching `.has-menu` will open the context menu:\n\n```html\n<vaadin-context-menu selector=\".has-menu\">\n <p class=\"has-menu\">This paragraph opens the context menu</p>\n <p>This paragraph does not open the context menu</p>\n</vaadin-context-menu>\n```\n\n### Menu Context\n\nThe following properties are available in the `context` argument:\n\n- `target` is the menu opening event target, which is the element that\nthe user has called the context menu for\n- `detail` is the menu opening event detail\n\nIn the following example, the menu item text is composed with the contents\nof the element that opened the menu:\n\n```html\n<vaadin-context-menu selector=\"li\" id=\"contextMenu\">\n <ul>\n <li>Foo</li>\n <li>Bar</li>\n <li>Baz</li>\n </ul>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'The menu target: ' + context.target.textContent;\n};\n```\n\n### Styling\n\n`<vaadin-context-menu>` uses `<vaadin-context-menu-overlay>` internal\nthemable component as the actual visible context menu overlay.\n\nSee [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-
|
|
19
|
+
"description": "`<vaadin-context-menu>` is a Web Component for creating context menus.\n\n### Items\n\nItems is a higher level convenience API for defining a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nWhen an item is selected, `<vaadin-context-menu>` dispatches an \"item-selected\" event\nwith the selected item as `event.detail.value` property.\nIf item does not have `keepOpen` property the menu will be closed.\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n\ncontextMenu.addEventListener('item-selected', e => {\n const item = e.detail.value;\n console.log(`${item.text} selected`);\n});\n```\n\n**NOTE:** when the `items` array is defined, the renderer cannot be used.\n\n### Rendering\n\nThe content of the menu can be populated by using the renderer callback function.\n\nThe renderer function provides `root`, `contextMenu`, `model` arguments when applicable.\nGenerate DOM content by using `model` object properties if needed, append it to the `root`\nelement and control the state of the host element by accessing `contextMenu`. Before generating\nnew content, the renderer function should check if there is already content in `root` for reusing it.\n\n```html\n<vaadin-context-menu id=\"contextMenu\">\n <p>This paragraph has a context menu.</p>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'Content of the selector: ' + context.target.textContent;\n};\n```\n\nYou can access the menu context inside the renderer using\n`context.target` and `context.detail`.\n\nRenderer is called on the opening of the context-menu and each time the related context is updated.\nDOM generated during the renderer call can be reused\nin the next renderer call and will be provided with the `root` argument.\nOn first call it will be empty.\n\n### `vaadin-contextmenu` Gesture Event\n\n`vaadin-contextmenu` is a gesture event (a custom event),\nwhich is dispatched after either `contextmenu` or long touch events.\nThis enables support for both mouse and touch environments in a uniform way.\n\n`<vaadin-context-menu>` opens the menu overlay on the `vaadin-contextmenu`\nevent by default.\n\n### Menu Listener\n\nBy default, the `<vaadin-context-menu>` element listens for the menu opening\nevent on itself. In case if you do not want to wrap the target, you can listen for\nevents on an element outside the `<vaadin-context-menu>` by setting the\n`listenOn` property:\n\n```html\n<vaadin-context-menu id=\"contextMenu\"></vaadin-context-menu>\n\n<div id=\"menuListener\">The element that listens for the contextmenu event.</div>\n```\n```javascript\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.listenOn = document.querySelector('#menuListener');\n```\n\n### Filtering Menu Targets\n\nBy default, the listener element and all its descendants open the context\nmenu. You can filter the menu targets to a smaller set of elements inside\nthe listener element by setting the `selector` property.\n\nIn the following example, only the elements matching `.has-menu` will open the context menu:\n\n```html\n<vaadin-context-menu selector=\".has-menu\">\n <p class=\"has-menu\">This paragraph opens the context menu</p>\n <p>This paragraph does not open the context menu</p>\n</vaadin-context-menu>\n```\n\n### Menu Context\n\nThe following properties are available in the `context` argument:\n\n- `target` is the menu opening event target, which is the element that\nthe user has called the context menu for\n- `detail` is the menu opening event detail\n\nIn the following example, the menu item text is composed with the contents\nof the element that opened the menu:\n\n```html\n<vaadin-context-menu selector=\"li\" id=\"contextMenu\">\n <ul>\n <li>Foo</li>\n <li>Bar</li>\n <li>Baz</li>\n </ul>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'The menu target: ' + context.target.textContent;\n};\n```\n\n### Styling\n\n`<vaadin-context-menu>` uses `<vaadin-context-menu-overlay>` internal\nthemable component as the actual visible context menu overlay.\n\nSee [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-rc1/#/elements/vaadin-overlay)\ndocumentation for `<vaadin-context-menu-overlay>` stylable parts.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.\n\n### Internal components\n\nWhen using `items` API, in addition `<vaadin-context-menu-overlay>`, the following\ninternal components are themable:\n\n- `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-rc1/#/elements/vaadin-item).\n- `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/24.3.0-rc1/#/elements/vaadin-list-box).\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
|
{
|