@vaadin/context-menu 24.8.0-alpha9 → 24.8.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 +13 -13
- package/src/vaadin-context-menu-mixin.js +75 -4
- package/src/vaadin-contextmenu-items-mixin.js +23 -16
- 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.8.0-
|
|
3
|
+
"version": "24.8.0-rc1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -39,20 +39,20 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
41
41
|
"@polymer/polymer": "^3.0.0",
|
|
42
|
-
"@vaadin/a11y-base": "24.8.0-
|
|
43
|
-
"@vaadin/component-base": "24.8.0-
|
|
44
|
-
"@vaadin/item": "24.8.0-
|
|
45
|
-
"@vaadin/list-box": "24.8.0-
|
|
46
|
-
"@vaadin/lit-renderer": "24.8.0-
|
|
47
|
-
"@vaadin/overlay": "24.8.0-
|
|
48
|
-
"@vaadin/vaadin-lumo-styles": "24.8.0-
|
|
49
|
-
"@vaadin/vaadin-material-styles": "24.8.0-
|
|
50
|
-
"@vaadin/vaadin-themable-mixin": "24.8.0-
|
|
42
|
+
"@vaadin/a11y-base": "24.8.0-rc1",
|
|
43
|
+
"@vaadin/component-base": "24.8.0-rc1",
|
|
44
|
+
"@vaadin/item": "24.8.0-rc1",
|
|
45
|
+
"@vaadin/list-box": "24.8.0-rc1",
|
|
46
|
+
"@vaadin/lit-renderer": "24.8.0-rc1",
|
|
47
|
+
"@vaadin/overlay": "24.8.0-rc1",
|
|
48
|
+
"@vaadin/vaadin-lumo-styles": "24.8.0-rc1",
|
|
49
|
+
"@vaadin/vaadin-material-styles": "24.8.0-rc1",
|
|
50
|
+
"@vaadin/vaadin-themable-mixin": "24.8.0-rc1",
|
|
51
51
|
"lit": "^3.0.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@vaadin/chai-plugins": "24.8.0-
|
|
55
|
-
"@vaadin/test-runner-commands": "24.8.0-
|
|
54
|
+
"@vaadin/chai-plugins": "24.8.0-rc1",
|
|
55
|
+
"@vaadin/test-runner-commands": "24.8.0-rc1",
|
|
56
56
|
"@vaadin/testing-helpers": "^1.1.0",
|
|
57
57
|
"sinon": "^18.0.0"
|
|
58
58
|
},
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"web-types.json",
|
|
61
61
|
"web-types.lit.json"
|
|
62
62
|
],
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "901d3eb9224983fd81e222e2fa5c7c207f9a6e46"
|
|
64
64
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright (c) 2016 - 2025 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import { isElementFocusable } from '@vaadin/a11y-base/src/focus-utils.js';
|
|
6
|
+
import { isElementFocusable, isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
|
|
7
7
|
import { isAndroid, isIOS } from '@vaadin/component-base/src/browser-utils.js';
|
|
8
8
|
import { addListener, deepTargetFind, gestures, removeListener } from '@vaadin/component-base/src/gestures.js';
|
|
9
9
|
import { MediaQueryController } from '@vaadin/component-base/src/media-query-controller.js';
|
|
@@ -215,7 +215,7 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
215
215
|
*/
|
|
216
216
|
_onVaadinOverlayOpen() {
|
|
217
217
|
this.__alignOverlayPosition();
|
|
218
|
-
this._overlayElement.style.
|
|
218
|
+
this._overlayElement.style.visibility = '';
|
|
219
219
|
this.__forwardFocus();
|
|
220
220
|
}
|
|
221
221
|
|
|
@@ -338,11 +338,18 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
338
338
|
* It is not guaranteed that the update happens immediately (synchronously) after it is requested.
|
|
339
339
|
*/
|
|
340
340
|
requestContentUpdate() {
|
|
341
|
-
if (!this._overlayElement
|
|
341
|
+
if (!this._overlayElement) {
|
|
342
342
|
return;
|
|
343
343
|
}
|
|
344
344
|
|
|
345
|
+
// Store state to be restored after re-rendering
|
|
346
|
+
this.__preserveMenuState();
|
|
347
|
+
|
|
348
|
+
// Run overlay renderer to re-create DOM elements
|
|
345
349
|
this._overlayElement.requestContentUpdate();
|
|
350
|
+
|
|
351
|
+
// Restore focused item, update sub-menu if needed
|
|
352
|
+
this.__restoreMenuState();
|
|
346
353
|
}
|
|
347
354
|
|
|
348
355
|
/** @private */
|
|
@@ -403,12 +410,76 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
403
410
|
this.__y = this._getEventCoordinate(e, 'y');
|
|
404
411
|
this.__pageYOffset = window.pageYOffset;
|
|
405
412
|
|
|
406
|
-
|
|
413
|
+
// Hide overlay until it is fully rendered and positioned
|
|
414
|
+
this._overlayElement.style.visibility = 'hidden';
|
|
407
415
|
this._setOpened(true);
|
|
408
416
|
}
|
|
409
417
|
}
|
|
410
418
|
}
|
|
411
419
|
|
|
420
|
+
/** @private */
|
|
421
|
+
__preserveMenuState() {
|
|
422
|
+
const listBox = this.__getListBox();
|
|
423
|
+
if (listBox) {
|
|
424
|
+
this.__focusedIndex = listBox.items.indexOf(listBox.focused);
|
|
425
|
+
|
|
426
|
+
if (this._subMenu && this._subMenu.opened) {
|
|
427
|
+
this.__subMenuIndex = listBox.items.indexOf(this._subMenu.listenOn);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/** @private */
|
|
433
|
+
__restoreMenuState() {
|
|
434
|
+
const focusedIndex = this.__focusedIndex;
|
|
435
|
+
const subMenuIndex = this.__subMenuIndex;
|
|
436
|
+
const selectedIndex = this.__selectedIndex;
|
|
437
|
+
|
|
438
|
+
const listBox = this.__getListBox();
|
|
439
|
+
|
|
440
|
+
if (listBox) {
|
|
441
|
+
// Initialize menu items synchronously
|
|
442
|
+
listBox._observer.flush();
|
|
443
|
+
|
|
444
|
+
if (subMenuIndex > -1) {
|
|
445
|
+
const itemToOpen = listBox.items[subMenuIndex];
|
|
446
|
+
if (itemToOpen) {
|
|
447
|
+
if (Array.isArray(itemToOpen._item.children) && itemToOpen._item.children.length) {
|
|
448
|
+
// Keep nested sub-menu opened and update it
|
|
449
|
+
this.__updateSubMenuForItem(this._subMenu, itemToOpen);
|
|
450
|
+
this._subMenu.requestContentUpdate();
|
|
451
|
+
} else {
|
|
452
|
+
// Item no longer has children, close sub-menu
|
|
453
|
+
this._subMenu.close();
|
|
454
|
+
this.__focusItem(itemToOpen);
|
|
455
|
+
}
|
|
456
|
+
} else {
|
|
457
|
+
// Item no longer exists, focus the list-box
|
|
458
|
+
listBox.focus();
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// Focus previously selected item, in case it was clicked with
|
|
463
|
+
// `keepOpen` option, or the previously focused item, if any
|
|
464
|
+
this.__focusItem(selectedIndex > -1 ? listBox.children[selectedIndex] : listBox.items[focusedIndex]);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
this.__focusedIndex = undefined;
|
|
468
|
+
this.__subMenuIndex = undefined;
|
|
469
|
+
this.__selectedIndex = undefined;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** @private */
|
|
473
|
+
__focusItem(item) {
|
|
474
|
+
if (item) {
|
|
475
|
+
item.focus();
|
|
476
|
+
|
|
477
|
+
if (isKeyboardActive()) {
|
|
478
|
+
item.setAttribute('focus-ring', '');
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
412
483
|
/** @private */
|
|
413
484
|
__onScroll() {
|
|
414
485
|
if (!this.opened) {
|
|
@@ -132,14 +132,12 @@ export const ItemsMixin = (superClass) =>
|
|
|
132
132
|
|
|
133
133
|
/** @private */
|
|
134
134
|
__openSubMenu(subMenu, itemElement, overlayClass) {
|
|
135
|
-
subMenu
|
|
136
|
-
subMenu.listenOn = itemElement;
|
|
135
|
+
this.__updateSubMenuForItem(subMenu, itemElement);
|
|
137
136
|
subMenu.overlayClass = overlayClass;
|
|
138
137
|
|
|
139
138
|
const parent = this._overlayElement;
|
|
140
139
|
|
|
141
140
|
const subMenuOverlay = subMenu._overlayElement;
|
|
142
|
-
subMenuOverlay.positionTarget = itemElement;
|
|
143
141
|
subMenuOverlay.noHorizontalOverlap = true;
|
|
144
142
|
// Store the reference parent overlay
|
|
145
143
|
subMenuOverlay._setParentOverlay(parent);
|
|
@@ -163,6 +161,13 @@ export const ItemsMixin = (superClass) =>
|
|
|
163
161
|
);
|
|
164
162
|
}
|
|
165
163
|
|
|
164
|
+
/** @private */
|
|
165
|
+
__updateSubMenuForItem(subMenu, itemElement) {
|
|
166
|
+
subMenu.items = itemElement._item.children;
|
|
167
|
+
subMenu.listenOn = itemElement;
|
|
168
|
+
subMenu._overlayElement.positionTarget = itemElement;
|
|
169
|
+
}
|
|
170
|
+
|
|
166
171
|
/**
|
|
167
172
|
* @param {!ContextMenuItem} item
|
|
168
173
|
* @return {HTMLElement}
|
|
@@ -268,8 +273,9 @@ export const ItemsMixin = (superClass) =>
|
|
|
268
273
|
// Close the menu
|
|
269
274
|
this.close();
|
|
270
275
|
this.listenOn.focus();
|
|
271
|
-
} else if (key === 'Tab') {
|
|
272
|
-
// Close all menus
|
|
276
|
+
} else if (key === 'Tab' && !event.defaultPrevented) {
|
|
277
|
+
// Close all menus unless the Tab key was handled separately
|
|
278
|
+
// which is the case e.g. in menu-bar with Tab navigation.
|
|
273
279
|
this.dispatchEvent(new CustomEvent('close-all-menus'));
|
|
274
280
|
}
|
|
275
281
|
});
|
|
@@ -316,14 +322,10 @@ export const ItemsMixin = (superClass) =>
|
|
|
316
322
|
const menu = e.target;
|
|
317
323
|
const selectedItem = e.detail.value;
|
|
318
324
|
const index = menu.items.indexOf(selectedItem);
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
menu._listBox._observer.flush();
|
|
324
|
-
|
|
325
|
-
const newItem = menu._listBox.children[index];
|
|
326
|
-
newItem.focus();
|
|
325
|
+
// Menu can be no longer opened if parent menu items changed
|
|
326
|
+
if (!!selectedItem.keepOpen && index > -1 && menu.opened) {
|
|
327
|
+
menu.__selectedIndex = index;
|
|
328
|
+
menu.requestContentUpdate();
|
|
327
329
|
} else if (!selectedItem.keepOpen) {
|
|
328
330
|
this.close();
|
|
329
331
|
}
|
|
@@ -390,22 +392,27 @@ export const ItemsMixin = (superClass) =>
|
|
|
390
392
|
}
|
|
391
393
|
}
|
|
392
394
|
|
|
395
|
+
/** @protected */
|
|
396
|
+
__getListBox() {
|
|
397
|
+
return this._overlayElement.querySelector(`${this._tagNamePrefix}-list-box`);
|
|
398
|
+
}
|
|
399
|
+
|
|
393
400
|
/**
|
|
394
401
|
* @param {!HTMLElement} root
|
|
395
402
|
* @param {!ContextMenu} menu
|
|
396
403
|
* @param {!ContextMenuRendererContext} context
|
|
397
404
|
* @protected
|
|
398
405
|
*/
|
|
399
|
-
__itemsRenderer(root, menu
|
|
406
|
+
__itemsRenderer(root, menu) {
|
|
400
407
|
this.__initMenu(root, menu);
|
|
401
408
|
|
|
402
409
|
const subMenu = root.querySelector(this.constructor.is);
|
|
403
410
|
subMenu.closeOn = menu.closeOn;
|
|
404
411
|
|
|
405
|
-
const listBox =
|
|
412
|
+
const listBox = this.__getListBox();
|
|
406
413
|
listBox.innerHTML = '';
|
|
407
414
|
|
|
408
|
-
|
|
415
|
+
menu.items.forEach((item) => {
|
|
409
416
|
const component = this.__createComponent(item);
|
|
410
417
|
listBox.appendChild(component);
|
|
411
418
|
});
|
package/web-types.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/web-types",
|
|
3
3
|
"name": "@vaadin/context-menu",
|
|
4
|
-
"version": "24.8.0-
|
|
4
|
+
"version": "24.8.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.8.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.8.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.8.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.8.0-rc1/#/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": "24.8.0-
|
|
4
|
+
"version": "24.8.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.8.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.8.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.8.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.8.0-rc1/#/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
|
{
|