@vaadin/context-menu 23.2.0-dev.8a7678b70 → 23.3.0-alpha1

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A web component that can be attached to any component to display a context menu.
4
4
 
5
- [Documentation + Live Demo ↗](https://vaadin.com/docs/latest/ds/components/context-menu)
5
+ [Documentation + Live Demo ↗](https://vaadin.com/docs/latest/components/context-menu)
6
6
 
7
7
  [![npm version](https://badgen.net/npm/v/@vaadin/context-menu)](https://www.npmjs.com/package/@vaadin/context-menu)
8
8
  [![Discord](https://img.shields.io/discord/732335336448852018?label=discord)](https://discord.gg/PHmkCKC)
@@ -33,7 +33,7 @@ A web component that can be attached to any component to display a context menu.
33
33
  </script>
34
34
  ```
35
35
 
36
- [<img src="https://raw.githubusercontent.com/vaadin/web-components/master/packages/context-menu/screenshot.png" width="493" alt="Screenshot of vaadin-context-menu">](https://vaadin.com/docs/latest/ds/components/context-menu)
36
+ [<img src="https://raw.githubusercontent.com/vaadin/web-components/master/packages/context-menu/screenshot.png" width="493" alt="Screenshot of vaadin-context-menu">](https://vaadin.com/docs/latest/components/context-menu)
37
37
 
38
38
  **Note:** [`<vaadin-list-box>`](https://github.com/vaadin/vaadin-list-box) component used in the above example should be installed and imported separately.
39
39
 
@@ -53,7 +53,7 @@ import '@vaadin/context-menu';
53
53
 
54
54
  ## Themes
55
55
 
56
- Vaadin components come with two built-in [themes](https://vaadin.com/docs/latest/ds/customization/using-themes), Lumo and Material.
56
+ Vaadin components come with two built-in [themes](https://vaadin.com/docs/latest/styling), Lumo and Material.
57
57
  The [main entrypoint](https://github.com/vaadin/web-components/blob/master/packages/context-menu/vaadin-context-menu.js) of the package uses the Lumo theme.
58
58
 
59
59
  To use the Material theme, import the component from the `theme/material` folder:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/context-menu",
3
- "version": "23.2.0-dev.8a7678b70",
3
+ "version": "23.3.0-alpha1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -25,7 +25,9 @@
25
25
  "src",
26
26
  "theme",
27
27
  "vaadin-*.d.ts",
28
- "vaadin-*.js"
28
+ "vaadin-*.js",
29
+ "web-types.json",
30
+ "web-types.lit.json"
29
31
  ],
30
32
  "keywords": [
31
33
  "Vaadin",
@@ -37,20 +39,24 @@
37
39
  "dependencies": {
38
40
  "@open-wc/dedupe-mixin": "^1.3.0",
39
41
  "@polymer/polymer": "^3.0.0",
40
- "@vaadin/component-base": "23.2.0-dev.8a7678b70",
41
- "@vaadin/item": "23.2.0-dev.8a7678b70",
42
- "@vaadin/list-box": "23.2.0-dev.8a7678b70",
43
- "@vaadin/lit-renderer": "23.2.0-dev.8a7678b70",
44
- "@vaadin/vaadin-lumo-styles": "23.2.0-dev.8a7678b70",
45
- "@vaadin/vaadin-material-styles": "23.2.0-dev.8a7678b70",
46
- "@vaadin/vaadin-overlay": "23.2.0-dev.8a7678b70",
47
- "@vaadin/vaadin-themable-mixin": "23.2.0-dev.8a7678b70"
42
+ "@vaadin/component-base": "23.3.0-alpha1",
43
+ "@vaadin/item": "23.3.0-alpha1",
44
+ "@vaadin/list-box": "23.3.0-alpha1",
45
+ "@vaadin/lit-renderer": "23.3.0-alpha1",
46
+ "@vaadin/vaadin-lumo-styles": "23.3.0-alpha1",
47
+ "@vaadin/vaadin-material-styles": "23.3.0-alpha1",
48
+ "@vaadin/vaadin-overlay": "23.3.0-alpha1",
49
+ "@vaadin/vaadin-themable-mixin": "23.3.0-alpha1"
48
50
  },
49
51
  "devDependencies": {
50
52
  "@esm-bundle/chai": "^4.3.4",
51
- "@vaadin/polymer-legacy-adapter": "23.2.0-dev.8a7678b70",
53
+ "@vaadin/polymer-legacy-adapter": "23.3.0-alpha1",
52
54
  "@vaadin/testing-helpers": "^0.3.2",
53
55
  "sinon": "^13.0.2"
54
56
  },
55
- "gitHead": "85b403f96d8282f262322b56c0ff4289f843d02a"
57
+ "web-types": [
58
+ "web-types.json",
59
+ "web-types.lit.json"
60
+ ],
61
+ "gitHead": "beabc527d4b1274eb798ff701d406fed45cfe638"
56
62
  }
@@ -3,10 +3,10 @@
3
3
  * Copyright (c) 2017 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { TemplateResult } from 'lit';
7
- import { DirectiveResult } from 'lit/directive.js';
6
+ import type { TemplateResult } from 'lit';
7
+ import type { DirectiveResult } from 'lit/directive.js';
8
8
  import { LitRendererDirective } from '@vaadin/lit-renderer';
9
- import { ContextMenu, ContextMenuRendererContext } from '../vaadin-context-menu.js';
9
+ import type { ContextMenu, ContextMenuRendererContext } from '../vaadin-context-menu.js';
10
10
 
11
11
  export type ContextMenuLitRenderer = (context: ContextMenuRendererContext, menu: ContextMenu) => TemplateResult;
12
12
 
@@ -207,7 +207,7 @@ export interface ContextMenuEventMap extends HTMLElementEventMap, ContextMenuCus
207
207
  * See [`<vaadin-overlay>`](#/elements/vaadin-overlay)
208
208
  * documentation for `<vaadin-context-menu-overlay>` stylable parts.
209
209
  *
210
- * See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
210
+ * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
211
211
  *
212
212
  * ### Internal components
213
213
  *
@@ -289,13 +289,13 @@ declare class ContextMenu extends ElementMixin(ThemePropertyMixin(ItemsMixin(HTM
289
289
  addEventListener<K extends keyof ContextMenuEventMap>(
290
290
  type: K,
291
291
  listener: (this: ContextMenu, ev: ContextMenuEventMap[K]) => void,
292
- options?: boolean | AddEventListenerOptions,
292
+ options?: AddEventListenerOptions | boolean,
293
293
  ): void;
294
294
 
295
295
  removeEventListener<K extends keyof ContextMenuEventMap>(
296
296
  type: K,
297
297
  listener: (this: ContextMenu, ev: ContextMenuEventMap[K]) => void,
298
- options?: boolean | EventListenerOptions,
298
+ options?: EventListenerOptions | boolean,
299
299
  ): void;
300
300
  }
301
301
 
@@ -180,7 +180,7 @@ import { ItemsMixin } from './vaadin-contextmenu-items-mixin.js';
180
180
  * See [`<vaadin-overlay>`](#/elements/vaadin-overlay)
181
181
  * documentation for `<vaadin-context-menu-overlay>` stylable parts.
182
182
  *
183
- * See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
183
+ * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
184
184
  *
185
185
  * ### Internal components
186
186
  *
@@ -3,16 +3,16 @@
3
3
  * Copyright (c) 2016 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { Constructor } from '@open-wc/dedupe-mixin';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
7
  import { Item } from '@vaadin/item/src/vaadin-item.js';
8
8
  import { ListBox } from '@vaadin/list-box/src/vaadin-list-box.js';
9
9
 
10
10
  export interface ContextMenuItem {
11
11
  text?: string;
12
- component?: string | HTMLElement;
12
+ component?: HTMLElement | string;
13
13
  disabled?: boolean;
14
14
  checked?: boolean;
15
- theme?: string | string[];
15
+ theme?: string[] | string;
16
16
  children?: ContextMenuItem[];
17
17
  }
18
18
 
@@ -37,7 +37,7 @@ declare global {
37
37
  */
38
38
  declare class ContextMenuListBox extends ListBox {}
39
39
 
40
- export declare function ItemsMixin<T extends Constructor<HTMLElement>>(base: T): T & Constructor<ItemsMixinClass>;
40
+ export declare function ItemsMixin<T extends Constructor<HTMLElement>>(base: T): Constructor<ItemsMixinClass> & T;
41
41
 
42
42
  export declare class ItemsMixinClass {
43
43
  /**
@@ -105,7 +105,7 @@ export const ItemsMixin = (superClass) =>
105
105
  // Overlay's outside click listener doesn't work with modeless
106
106
  // overlays (submenus) so we need additional logic for it
107
107
  this.__itemsOutsideClickListener = (e) => {
108
- if (!e.composedPath().filter((el) => el.localName === 'vaadin-context-menu-overlay')[0]) {
108
+ if (!e.composedPath().some((el) => el.localName === 'vaadin-context-menu-overlay')) {
109
109
  this.dispatchEvent(new CustomEvent('items-outside-click'));
110
110
  }
111
111
  };
@@ -330,10 +330,12 @@ export const ItemsMixin = (superClass) =>
330
330
  }
331
331
  });
332
332
 
333
- requestAnimationFrame(() => (this.__openListenerActive = true));
333
+ requestAnimationFrame(() => {
334
+ this.__openListenerActive = true;
335
+ });
334
336
  const openSubMenu = (
335
337
  e,
336
- itemElement = e.composedPath().filter((e) => e.localName === 'vaadin-context-menu-item')[0],
338
+ itemElement = e.composedPath().find((e) => e.localName === 'vaadin-context-menu-item'),
337
339
  ) => {
338
340
  // Delay enabling the mouseover listener to avoid it from triggering on parent menu open
339
341
  if (!this.__openListenerActive) {
package/web-types.json ADDED
@@ -0,0 +1,130 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/web-types",
3
+ "name": "@vaadin/context-menu",
4
+ "version": "23.3.0-alpha1",
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.\n\n```javascript\ncontextMenu.items = [\n {text: 'Menu Item 1', theme: 'primary', children:\n [\n {text: 'Menu Item 1-1', checked: 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/23.3.0-alpha1/#/elements/vaadin-overlay)\ndocumentation for `<vaadin-context-menu-overlay>` stylable parts.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/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/23.3.0-alpha1/#/elements/vaadin-item).\n- `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha1/#/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": "selector",
15
+ "description": "CSS selector that can be used to target any child element\nof the context menu to listen for `openOn` events.",
16
+ "value": {
17
+ "type": [
18
+ "string",
19
+ "null",
20
+ "undefined"
21
+ ]
22
+ }
23
+ },
24
+ {
25
+ "name": "open-on",
26
+ "description": "Event name to listen for opening the context menu.",
27
+ "value": {
28
+ "type": [
29
+ "string"
30
+ ]
31
+ }
32
+ },
33
+ {
34
+ "name": "close-on",
35
+ "description": "Event name to listen for closing the context menu.",
36
+ "value": {
37
+ "type": [
38
+ "string"
39
+ ]
40
+ }
41
+ },
42
+ {
43
+ "name": "theme",
44
+ "description": "The theme variants to apply to the component.",
45
+ "value": {
46
+ "type": [
47
+ "string",
48
+ "null",
49
+ "undefined"
50
+ ]
51
+ }
52
+ }
53
+ ],
54
+ "js": {
55
+ "properties": [
56
+ {
57
+ "name": "items",
58
+ "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},\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```",
59
+ "value": {
60
+ "type": [
61
+ "Array.<ContextMenuItem>",
62
+ "undefined"
63
+ ]
64
+ }
65
+ },
66
+ {
67
+ "name": "selector",
68
+ "description": "CSS selector that can be used to target any child element\nof the context menu to listen for `openOn` events.",
69
+ "value": {
70
+ "type": [
71
+ "string",
72
+ "null",
73
+ "undefined"
74
+ ]
75
+ }
76
+ },
77
+ {
78
+ "name": "openOn",
79
+ "description": "Event name to listen for opening the context menu.",
80
+ "value": {
81
+ "type": [
82
+ "string"
83
+ ]
84
+ }
85
+ },
86
+ {
87
+ "name": "listenOn",
88
+ "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.",
89
+ "value": {
90
+ "type": [
91
+ "HTMLElement"
92
+ ]
93
+ }
94
+ },
95
+ {
96
+ "name": "closeOn",
97
+ "description": "Event name to listen for closing the context menu.",
98
+ "value": {
99
+ "type": [
100
+ "string"
101
+ ]
102
+ }
103
+ },
104
+ {
105
+ "name": "renderer",
106
+ "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.",
107
+ "value": {
108
+ "type": [
109
+ "ContextMenuRenderer",
110
+ "undefined"
111
+ ]
112
+ }
113
+ }
114
+ ],
115
+ "events": [
116
+ {
117
+ "name": "item-selected",
118
+ "description": "Fired when an item is selected when the context menu is populated using the `items` API."
119
+ },
120
+ {
121
+ "name": "opened-changed",
122
+ "description": "Fired when the `opened` property changes."
123
+ }
124
+ ]
125
+ }
126
+ }
127
+ ]
128
+ }
129
+ }
130
+ }
@@ -0,0 +1,83 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/web-types",
3
+ "name": "@vaadin/context-menu",
4
+ "version": "23.3.0-alpha1",
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.\n\n```javascript\ncontextMenu.items = [\n {text: 'Menu Item 1', theme: 'primary', children:\n [\n {text: 'Menu Item 1-1', checked: 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/23.3.0-alpha1/#/elements/vaadin-overlay)\ndocumentation for `<vaadin-context-menu-overlay>` stylable parts.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/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/23.3.0-alpha1/#/elements/vaadin-item).\n- `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha1/#/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": ".items",
24
+ "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},\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```",
25
+ "value": {
26
+ "kind": "expression"
27
+ }
28
+ },
29
+ {
30
+ "name": ".selector",
31
+ "description": "CSS selector that can be used to target any child element\nof the context menu to listen for `openOn` events.",
32
+ "value": {
33
+ "kind": "expression"
34
+ }
35
+ },
36
+ {
37
+ "name": ".openOn",
38
+ "description": "Event name to listen for opening the context menu.",
39
+ "value": {
40
+ "kind": "expression"
41
+ }
42
+ },
43
+ {
44
+ "name": ".listenOn",
45
+ "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.",
46
+ "value": {
47
+ "kind": "expression"
48
+ }
49
+ },
50
+ {
51
+ "name": ".closeOn",
52
+ "description": "Event name to listen for closing the context menu.",
53
+ "value": {
54
+ "kind": "expression"
55
+ }
56
+ },
57
+ {
58
+ "name": ".renderer",
59
+ "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.",
60
+ "value": {
61
+ "kind": "expression"
62
+ }
63
+ },
64
+ {
65
+ "name": "@item-selected",
66
+ "description": "Fired when an item is selected when the context menu is populated using the `items` API.",
67
+ "value": {
68
+ "kind": "expression"
69
+ }
70
+ },
71
+ {
72
+ "name": "@opened-changed",
73
+ "description": "Fired when the `opened` property changes.",
74
+ "value": {
75
+ "kind": "expression"
76
+ }
77
+ }
78
+ ]
79
+ }
80
+ ]
81
+ }
82
+ }
83
+ }