@vaadin/context-menu 24.2.0-dev.f254716fe → 24.2.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 +12 -12
- package/src/vaadin-context-menu-item.js +3 -1
- package/src/vaadin-context-menu-list-box.js +3 -1
- package/src/vaadin-context-menu-overlay.js +3 -1
- package/src/vaadin-context-menu.d.ts +2 -1
- package/src/vaadin-context-menu.js +5 -2
- package/src/vaadin-contextmenu-items-mixin.d.ts +2 -1
- package/src/vaadin-contextmenu-items-mixin.js +20 -4
- package/web-types.json +152 -0
- package/web-types.lit.json +90 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/context-menu",
|
|
3
|
-
"version": "24.2.0-
|
|
3
|
+
"version": "24.2.0-rc1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -39,19 +39,19 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
41
41
|
"@polymer/polymer": "^3.0.0",
|
|
42
|
-
"@vaadin/a11y-base": "24.2.0-
|
|
43
|
-
"@vaadin/component-base": "24.2.0-
|
|
44
|
-
"@vaadin/item": "24.2.0-
|
|
45
|
-
"@vaadin/list-box": "24.2.0-
|
|
46
|
-
"@vaadin/lit-renderer": "24.2.0-
|
|
47
|
-
"@vaadin/overlay": "24.2.0-
|
|
48
|
-
"@vaadin/vaadin-lumo-styles": "24.2.0-
|
|
49
|
-
"@vaadin/vaadin-material-styles": "24.2.0-
|
|
50
|
-
"@vaadin/vaadin-themable-mixin": "24.2.0-
|
|
42
|
+
"@vaadin/a11y-base": "24.2.0-rc1",
|
|
43
|
+
"@vaadin/component-base": "24.2.0-rc1",
|
|
44
|
+
"@vaadin/item": "24.2.0-rc1",
|
|
45
|
+
"@vaadin/list-box": "24.2.0-rc1",
|
|
46
|
+
"@vaadin/lit-renderer": "24.2.0-rc1",
|
|
47
|
+
"@vaadin/overlay": "24.2.0-rc1",
|
|
48
|
+
"@vaadin/vaadin-lumo-styles": "24.2.0-rc1",
|
|
49
|
+
"@vaadin/vaadin-material-styles": "24.2.0-rc1",
|
|
50
|
+
"@vaadin/vaadin-themable-mixin": "24.2.0-rc1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@esm-bundle/chai": "^4.3.4",
|
|
54
|
-
"@vaadin/testing-helpers": "^0.
|
|
54
|
+
"@vaadin/testing-helpers": "^0.5.0",
|
|
55
55
|
"lit": "^2.0.0",
|
|
56
56
|
"sinon": "^13.0.2"
|
|
57
57
|
},
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"web-types.json",
|
|
60
60
|
"web-types.lit.json"
|
|
61
61
|
],
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "012bef350bbf29865748f4c78338dd17c6f61a74"
|
|
63
63
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
7
|
+
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
7
8
|
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
8
9
|
import { ItemMixin } from '@vaadin/item/src/vaadin-item-mixin.js';
|
|
9
10
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
@@ -11,6 +12,7 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
|
|
|
11
12
|
/**
|
|
12
13
|
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
13
14
|
*
|
|
15
|
+
* @customElement
|
|
14
16
|
* @extends HTMLElement
|
|
15
17
|
* @mixes DirMixin
|
|
16
18
|
* @mixes ItemMixin
|
|
@@ -48,6 +50,6 @@ class ContextMenuItem extends ItemMixin(ThemableMixin(DirMixin(PolymerElement)))
|
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
defineCustomElement(ContextMenuItem);
|
|
52
54
|
|
|
53
55
|
export { ContextMenuItem };
|
|
@@ -6,12 +6,14 @@
|
|
|
6
6
|
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
7
7
|
import { ListMixin } from '@vaadin/a11y-base/src/list-mixin.js';
|
|
8
8
|
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
|
|
9
|
+
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
9
10
|
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
10
11
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
14
15
|
*
|
|
16
|
+
* @customElement
|
|
15
17
|
* @extends HTMLElement
|
|
16
18
|
* @mixes ControllerMixin
|
|
17
19
|
* @mixes DirMixin
|
|
@@ -76,6 +78,6 @@ class ContextMenuListBox extends ListMixin(ThemableMixin(DirMixin(ControllerMixi
|
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
|
|
81
|
+
defineCustomElement(ContextMenuListBox);
|
|
80
82
|
|
|
81
83
|
export { ContextMenuListBox };
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
7
|
+
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
7
8
|
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
8
9
|
import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js';
|
|
9
10
|
import { overlayStyles } from '@vaadin/overlay/src/vaadin-overlay-styles.js';
|
|
@@ -18,6 +19,7 @@ registerStyles('vaadin-context-menu-overlay', [overlayStyles, styles], {
|
|
|
18
19
|
/**
|
|
19
20
|
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
20
21
|
*
|
|
22
|
+
* @customElement
|
|
21
23
|
* @extends HTMLElement
|
|
22
24
|
* @mixes DirMixin
|
|
23
25
|
* @mixes MenuOverlayMixin
|
|
@@ -42,4 +44,4 @@ export class ContextMenuOverlay extends MenuOverlayMixin(OverlayMixin(DirMixin(T
|
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
defineCustomElement(ContextMenuOverlay);
|
|
@@ -54,12 +54,13 @@ export interface ContextMenuEventMap extends HTMLElementEventMap, ContextMenuCus
|
|
|
54
54
|
*
|
|
55
55
|
* When an item is selected, `<vaadin-context-menu>` dispatches an "item-selected" event
|
|
56
56
|
* with the selected item as `event.detail.value` property.
|
|
57
|
+
* If item does not have `keepOpen` property the menu will be closed.
|
|
57
58
|
*
|
|
58
59
|
* ```javascript
|
|
59
60
|
* contextMenu.items = [
|
|
60
61
|
* { text: 'Menu Item 1', theme: 'primary', children:
|
|
61
62
|
* [
|
|
62
|
-
* { text: 'Menu Item 1-1', checked: true },
|
|
63
|
+
* { text: 'Menu Item 1-1', checked: true, keepOpen: true },
|
|
63
64
|
* { text: 'Menu Item 1-2' }
|
|
64
65
|
* ]
|
|
65
66
|
* },
|
|
@@ -8,6 +8,7 @@ import './vaadin-context-menu-overlay.js';
|
|
|
8
8
|
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
9
9
|
import { isTouch } from '@vaadin/component-base/src/browser-utils.js';
|
|
10
10
|
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
|
|
11
|
+
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
11
12
|
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
12
13
|
import { addListener, gestures, removeListener } from '@vaadin/component-base/src/gestures.js';
|
|
13
14
|
import { MediaQueryController } from '@vaadin/component-base/src/media-query-controller.js';
|
|
@@ -27,12 +28,13 @@ import { ItemsMixin } from './vaadin-contextmenu-items-mixin.js';
|
|
|
27
28
|
*
|
|
28
29
|
* When an item is selected, `<vaadin-context-menu>` dispatches an "item-selected" event
|
|
29
30
|
* with the selected item as `event.detail.value` property.
|
|
31
|
+
* If item does not have `keepOpen` property the menu will be closed.
|
|
30
32
|
*
|
|
31
33
|
* ```javascript
|
|
32
34
|
* contextMenu.items = [
|
|
33
35
|
* { text: 'Menu Item 1', theme: 'primary', children:
|
|
34
36
|
* [
|
|
35
|
-
* { text: 'Menu Item 1-1', checked: true },
|
|
37
|
+
* { text: 'Menu Item 1-1', checked: true, keepOpen: true },
|
|
36
38
|
* { text: 'Menu Item 1-2' }
|
|
37
39
|
* ]
|
|
38
40
|
* },
|
|
@@ -197,6 +199,7 @@ import { ItemsMixin } from './vaadin-contextmenu-items-mixin.js';
|
|
|
197
199
|
* @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
|
|
198
200
|
* @fires {CustomEvent} item-selected - Fired when an item is selected when the context menu is populated using the `items` API.
|
|
199
201
|
*
|
|
202
|
+
* @customElement
|
|
200
203
|
* @extends HTMLElement
|
|
201
204
|
* @mixes ElementMixin
|
|
202
205
|
* @mixes ControllerMixin
|
|
@@ -726,5 +729,5 @@ class ContextMenu extends OverlayClassMixin(
|
|
|
726
729
|
*/
|
|
727
730
|
}
|
|
728
731
|
|
|
729
|
-
|
|
732
|
+
defineCustomElement(ContextMenu);
|
|
730
733
|
export { ContextMenu };
|
|
@@ -12,6 +12,7 @@ export interface ContextMenuItem {
|
|
|
12
12
|
component?: HTMLElement | string;
|
|
13
13
|
disabled?: boolean;
|
|
14
14
|
checked?: boolean;
|
|
15
|
+
keepOpen?: boolean;
|
|
15
16
|
theme?: string[] | string;
|
|
16
17
|
children?: ContextMenuItem[];
|
|
17
18
|
}
|
|
@@ -32,7 +33,7 @@ export declare class ItemsMixinClass {
|
|
|
32
33
|
* contextMenu.items = [
|
|
33
34
|
* { text: 'Menu Item 1', theme: 'primary', children:
|
|
34
35
|
* [
|
|
35
|
-
* { text: 'Menu Item 1-1', checked: true },
|
|
36
|
+
* { text: 'Menu Item 1-1', checked: true, keepOpen: true },
|
|
36
37
|
* { text: 'Menu Item 1-2' }
|
|
37
38
|
* ]
|
|
38
39
|
* },
|
|
@@ -22,6 +22,7 @@ export const ItemsMixin = (superClass) =>
|
|
|
22
22
|
* Either a tagName or an element instance. Defaults to "vaadin-context-menu-item".
|
|
23
23
|
* @property {boolean} disabled - If true, the item is disabled and cannot be selected
|
|
24
24
|
* @property {boolean} checked - If true, the item shows a checkmark next to it
|
|
25
|
+
* @property {boolean} keepOpen - If true, the menu will not be closed on item selection
|
|
25
26
|
* @property {union: string | string[]} theme - If set, sets the given theme(s) as an attribute to the menu item component, overriding any theme set on the context menu.
|
|
26
27
|
* @property {MenuItem[]} children - Array of child menu items
|
|
27
28
|
*/
|
|
@@ -39,7 +40,7 @@ export const ItemsMixin = (superClass) =>
|
|
|
39
40
|
* contextMenu.items = [
|
|
40
41
|
* { text: 'Menu Item 1', theme: 'primary', children:
|
|
41
42
|
* [
|
|
42
|
-
* { text: 'Menu Item 1-1', checked: true },
|
|
43
|
+
* { text: 'Menu Item 1-1', checked: true, keepOpen: true },
|
|
43
44
|
* { text: 'Menu Item 1-2' }
|
|
44
45
|
* ]
|
|
45
46
|
* },
|
|
@@ -214,10 +215,12 @@ export const ItemsMixin = (superClass) =>
|
|
|
214
215
|
const { value } = event.detail;
|
|
215
216
|
if (typeof value === 'number') {
|
|
216
217
|
const item = listBox.items[value]._item;
|
|
218
|
+
// Reset selected before dispatching the event to prevent
|
|
219
|
+
// checkmark icon flashing when `keepOpen` is set to true.
|
|
220
|
+
listBox.selected = null;
|
|
217
221
|
if (!item.children) {
|
|
218
222
|
this.dispatchEvent(new CustomEvent('item-selected', { detail: { value: item } }));
|
|
219
223
|
}
|
|
220
|
-
listBox.selected = null;
|
|
221
224
|
}
|
|
222
225
|
});
|
|
223
226
|
|
|
@@ -297,8 +300,21 @@ export const ItemsMixin = (superClass) =>
|
|
|
297
300
|
});
|
|
298
301
|
|
|
299
302
|
// Listen to the forwarded event from sub-menu.
|
|
300
|
-
this.addEventListener('item-selected', () => {
|
|
301
|
-
|
|
303
|
+
this.addEventListener('item-selected', (e) => {
|
|
304
|
+
const menu = e.target;
|
|
305
|
+
const selectedItem = e.detail.value;
|
|
306
|
+
const index = menu.items.indexOf(selectedItem);
|
|
307
|
+
if (!!selectedItem.keepOpen && index > -1) {
|
|
308
|
+
menu._overlayElement.requestContentUpdate();
|
|
309
|
+
|
|
310
|
+
// Initialize items synchronously
|
|
311
|
+
menu._listBox._observer.flush();
|
|
312
|
+
|
|
313
|
+
const newItem = menu._listBox.items[index];
|
|
314
|
+
newItem.focus();
|
|
315
|
+
} else if (!selectedItem.keepOpen) {
|
|
316
|
+
this.close();
|
|
317
|
+
}
|
|
302
318
|
});
|
|
303
319
|
|
|
304
320
|
// Mark parent item as collapsed when closing.
|
package/web-types.json
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/web-types",
|
|
3
|
+
"name": "@vaadin/context-menu",
|
|
4
|
+
"version": "24.2.0-rc1",
|
|
5
|
+
"description-markup": "markdown",
|
|
6
|
+
"contributions": {
|
|
7
|
+
"html": {
|
|
8
|
+
"elements": [
|
|
9
|
+
{
|
|
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', 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 }\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.2.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.2.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.2.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
|
+
"attributes": [
|
|
13
|
+
{
|
|
14
|
+
"name": "overlay-class",
|
|
15
|
+
"description": "A space-delimited list of CSS class names to set on the overlay element.\nThis property does not affect other CSS class names set manually via JS.\n\nNote, if the CSS class name was set with this property, clearing it will\nremove it from the overlay, even if the same class name was also added\nmanually, e.g. by using `classList.add()` in the `renderer` function.",
|
|
16
|
+
"value": {
|
|
17
|
+
"type": [
|
|
18
|
+
"string",
|
|
19
|
+
"null",
|
|
20
|
+
"undefined"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "selector",
|
|
26
|
+
"description": "CSS selector that can be used to target any child element\nof the context menu to listen for `openOn` events.",
|
|
27
|
+
"value": {
|
|
28
|
+
"type": [
|
|
29
|
+
"string",
|
|
30
|
+
"null",
|
|
31
|
+
"undefined"
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "open-on",
|
|
37
|
+
"description": "Event name to listen for opening the context menu.",
|
|
38
|
+
"value": {
|
|
39
|
+
"type": [
|
|
40
|
+
"string"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "close-on",
|
|
46
|
+
"description": "Event name to listen for closing the context menu.",
|
|
47
|
+
"value": {
|
|
48
|
+
"type": [
|
|
49
|
+
"string"
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"name": "theme",
|
|
55
|
+
"description": "The theme variants to apply to the component.",
|
|
56
|
+
"value": {
|
|
57
|
+
"type": [
|
|
58
|
+
"string",
|
|
59
|
+
"null",
|
|
60
|
+
"undefined"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"js": {
|
|
66
|
+
"properties": [
|
|
67
|
+
{
|
|
68
|
+
"name": "overlayClass",
|
|
69
|
+
"description": "A space-delimited list of CSS class names to set on the overlay element.\nThis property does not affect other CSS class names set manually via JS.\n\nNote, if the CSS class name was set with this property, clearing it will\nremove it from the overlay, even if the same class name was also added\nmanually, e.g. by using `classList.add()` in the `renderer` function.",
|
|
70
|
+
"value": {
|
|
71
|
+
"type": [
|
|
72
|
+
"string",
|
|
73
|
+
"null",
|
|
74
|
+
"undefined"
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"name": "items",
|
|
80
|
+
"description": "Defines 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\nThe items API can't be used together with a renderer!\n\n#### Example\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', 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 }\n];\n```",
|
|
81
|
+
"value": {
|
|
82
|
+
"type": [
|
|
83
|
+
"Array.<ContextMenuItem>",
|
|
84
|
+
"undefined"
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"name": "selector",
|
|
90
|
+
"description": "CSS selector that can be used to target any child element\nof the context menu to listen for `openOn` events.",
|
|
91
|
+
"value": {
|
|
92
|
+
"type": [
|
|
93
|
+
"string",
|
|
94
|
+
"null",
|
|
95
|
+
"undefined"
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"name": "openOn",
|
|
101
|
+
"description": "Event name to listen for opening the context menu.",
|
|
102
|
+
"value": {
|
|
103
|
+
"type": [
|
|
104
|
+
"string"
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"name": "listenOn",
|
|
110
|
+
"description": "The target element that's listened to for context menu opening events.\nBy default the vaadin-context-menu listens to the target's `vaadin-contextmenu`\nevents.",
|
|
111
|
+
"value": {
|
|
112
|
+
"type": [
|
|
113
|
+
"HTMLElement"
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"name": "closeOn",
|
|
119
|
+
"description": "Event name to listen for closing the context menu.",
|
|
120
|
+
"value": {
|
|
121
|
+
"type": [
|
|
122
|
+
"string"
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"name": "renderer",
|
|
128
|
+
"description": "Custom function for rendering the content of the menu overlay.\nReceives three arguments:\n\n- `root` The root container DOM element. Append your content to it.\n- `contextMenu` The reference to the `<vaadin-context-menu>` element.\n- `context` The object with the menu context, contains:\n - `context.target` the target of the menu opening event,\n - `context.detail` the menu opening event detail.",
|
|
129
|
+
"value": {
|
|
130
|
+
"type": [
|
|
131
|
+
"ContextMenuRenderer",
|
|
132
|
+
"undefined"
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
"events": [
|
|
138
|
+
{
|
|
139
|
+
"name": "item-selected",
|
|
140
|
+
"description": "Fired when an item is selected when the context menu is populated using the `items` API."
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"name": "opened-changed",
|
|
144
|
+
"description": "Fired when the `opened` property changes."
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/web-types",
|
|
3
|
+
"name": "@vaadin/context-menu",
|
|
4
|
+
"version": "24.2.0-rc1",
|
|
5
|
+
"description-markup": "markdown",
|
|
6
|
+
"framework": "lit",
|
|
7
|
+
"framework-config": {
|
|
8
|
+
"enable-when": {
|
|
9
|
+
"node-packages": [
|
|
10
|
+
"lit"
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"contributions": {
|
|
15
|
+
"html": {
|
|
16
|
+
"elements": [
|
|
17
|
+
{
|
|
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', 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 }\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.2.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.2.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.2.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
|
+
"extension": true,
|
|
21
|
+
"attributes": [
|
|
22
|
+
{
|
|
23
|
+
"name": ".overlayClass",
|
|
24
|
+
"description": "A space-delimited list of CSS class names to set on the overlay element.\nThis property does not affect other CSS class names set manually via JS.\n\nNote, if the CSS class name was set with this property, clearing it will\nremove it from the overlay, even if the same class name was also added\nmanually, e.g. by using `classList.add()` in the `renderer` function.",
|
|
25
|
+
"value": {
|
|
26
|
+
"kind": "expression"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name": ".items",
|
|
31
|
+
"description": "Defines 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\nThe items API can't be used together with a renderer!\n\n#### Example\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', 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 }\n];\n```",
|
|
32
|
+
"value": {
|
|
33
|
+
"kind": "expression"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"name": ".selector",
|
|
38
|
+
"description": "CSS selector that can be used to target any child element\nof the context menu to listen for `openOn` events.",
|
|
39
|
+
"value": {
|
|
40
|
+
"kind": "expression"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": ".openOn",
|
|
45
|
+
"description": "Event name to listen for opening the context menu.",
|
|
46
|
+
"value": {
|
|
47
|
+
"kind": "expression"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": ".listenOn",
|
|
52
|
+
"description": "The target element that's listened to for context menu opening events.\nBy default the vaadin-context-menu listens to the target's `vaadin-contextmenu`\nevents.",
|
|
53
|
+
"value": {
|
|
54
|
+
"kind": "expression"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"name": ".closeOn",
|
|
59
|
+
"description": "Event name to listen for closing the context menu.",
|
|
60
|
+
"value": {
|
|
61
|
+
"kind": "expression"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": ".renderer",
|
|
66
|
+
"description": "Custom function for rendering the content of the menu overlay.\nReceives three arguments:\n\n- `root` The root container DOM element. Append your content to it.\n- `contextMenu` The reference to the `<vaadin-context-menu>` element.\n- `context` The object with the menu context, contains:\n - `context.target` the target of the menu opening event,\n - `context.detail` the menu opening event detail.",
|
|
67
|
+
"value": {
|
|
68
|
+
"kind": "expression"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"name": "@item-selected",
|
|
73
|
+
"description": "Fired when an item is selected when the context menu is populated using the `items` API.",
|
|
74
|
+
"value": {
|
|
75
|
+
"kind": "expression"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"name": "@opened-changed",
|
|
80
|
+
"description": "Fired when the `opened` property changes.",
|
|
81
|
+
"value": {
|
|
82
|
+
"kind": "expression"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|