@vaadin/context-menu 24.0.0-alpha8 → 24.0.0-beta1

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.
@@ -3,37 +3,10 @@
3
3
  * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import './vaadin-context-menu-item.js';
7
+ import './vaadin-context-menu-list-box.js';
6
8
  import { isTouch } from '@vaadin/component-base/src/browser-utils.js';
7
9
  import { Item } from '@vaadin/item/src/vaadin-item.js';
8
- import { ListBox } from '@vaadin/list-box/src/vaadin-list-box.js';
9
-
10
- /**
11
- * An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
12
- *
13
- * @extends Item
14
- * @protected
15
- */
16
- class ContextMenuItemElement extends Item {
17
- static get is() {
18
- return 'vaadin-context-menu-item';
19
- }
20
- }
21
-
22
- customElements.define(ContextMenuItemElement.is, ContextMenuItemElement);
23
-
24
- /**
25
- * An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
26
- *
27
- * @extends ListBox
28
- * @protected
29
- */
30
- class ContextMenuListBox extends ListBox {
31
- static get is() {
32
- return 'vaadin-context-menu-list-box';
33
- }
34
- }
35
-
36
- customElements.define(ContextMenuListBox.is, ContextMenuListBox);
37
10
 
38
11
  /**
39
12
  * @polymerMixin
@@ -65,20 +38,20 @@ export const ItemsMixin = (superClass) =>
65
38
  *
66
39
  * ```javascript
67
40
  * contextMenu.items = [
68
- * {text: 'Menu Item 1', theme: 'primary', children:
41
+ * { text: 'Menu Item 1', theme: 'primary', children:
69
42
  * [
70
- * {text: 'Menu Item 1-1', checked: true},
71
- * {text: 'Menu Item 1-2'}
43
+ * { text: 'Menu Item 1-1', checked: true },
44
+ * { text: 'Menu Item 1-2' }
72
45
  * ]
73
46
  * },
74
- * {component: 'hr'},
75
- * {text: 'Menu Item 2', children:
47
+ * { component: 'hr' },
48
+ * { text: 'Menu Item 2', children:
76
49
  * [
77
- * {text: 'Menu Item 2-1'},
78
- * {text: 'Menu Item 2-2', disabled: true}
50
+ * { text: 'Menu Item 2-1' },
51
+ * { text: 'Menu Item 2-2', disabled: true }
79
52
  * ]
80
53
  * },
81
- * {text: 'Menu Item 3', disabled: true}
54
+ * { text: 'Menu Item 3', disabled: true }
82
55
  * ];
83
56
  * ```
84
57
  *
@@ -98,6 +71,15 @@ export const ItemsMixin = (superClass) =>
98
71
  };
99
72
  }
100
73
 
74
+ /**
75
+ * Tag name prefix used by overlay, list-box and items.
76
+ * @protected
77
+ * @return {string}
78
+ */
79
+ get _tagNamePrefix() {
80
+ return 'vaadin-context-menu';
81
+ }
82
+
101
83
  /** @protected */
102
84
  ready() {
103
85
  super.ready();
@@ -105,7 +87,7 @@ export const ItemsMixin = (superClass) =>
105
87
  // Overlay's outside click listener doesn't work with modeless
106
88
  // overlays (submenus) so we need additional logic for it
107
89
  this.__itemsOutsideClickListener = (e) => {
108
- if (!e.composedPath().some((el) => el.localName === 'vaadin-context-menu-overlay')) {
90
+ if (!e.composedPath().some((el) => el.localName === `${this._tagNamePrefix}-overlay`)) {
109
91
  this.dispatchEvent(new CustomEvent('items-outside-click'));
110
92
  }
111
93
  };
@@ -144,9 +126,10 @@ export const ItemsMixin = (superClass) =>
144
126
  }
145
127
 
146
128
  /** @private */
147
- __openSubMenu(subMenu, itemElement) {
129
+ __openSubMenu(subMenu, itemElement, overlayClass) {
148
130
  subMenu.items = itemElement._item.children;
149
131
  subMenu.listenOn = itemElement;
132
+ subMenu.overlayClass = overlayClass;
150
133
 
151
134
  const parent = this.$.overlay;
152
135
 
@@ -187,7 +170,7 @@ export const ItemsMixin = (superClass) =>
187
170
  const subMenu = root.querySelector(this.constructor.is);
188
171
  subMenu.closeOn = menu.closeOn;
189
172
 
190
- const listBox = root.querySelector('vaadin-context-menu-list-box');
173
+ const listBox = root.querySelector(`${this._tagNamePrefix}-list-box`);
191
174
 
192
175
  listBox.innerHTML = '';
193
176
 
@@ -198,7 +181,7 @@ export const ItemsMixin = (superClass) =>
198
181
  if (item.component instanceof HTMLElement) {
199
182
  component = item.component;
200
183
  } else {
201
- component = document.createElement(item.component || 'vaadin-context-menu-item');
184
+ component = document.createElement(item.component || `${this._tagNamePrefix}-item`);
202
185
  }
203
186
 
204
187
  if (component instanceof Item) {
@@ -261,7 +244,7 @@ export const ItemsMixin = (superClass) =>
261
244
  /** @private */
262
245
  __initMenu(root, menu) {
263
246
  if (!root.firstElementChild) {
264
- const listBox = document.createElement('vaadin-context-menu-list-box');
247
+ const listBox = document.createElement(`${this._tagNamePrefix}-list-box`);
265
248
  root.appendChild(listBox);
266
249
 
267
250
  if (this._theme) {
@@ -323,7 +306,7 @@ export const ItemsMixin = (superClass) =>
323
306
  });
324
307
  const openSubMenu = (
325
308
  e,
326
- itemElement = e.composedPath().find((e) => e.localName === 'vaadin-context-menu-item'),
309
+ itemElement = e.composedPath().find((e) => e.localName === `${this._tagNamePrefix}-item`),
327
310
  ) => {
328
311
  // Delay enabling the mouseover listener to avoid it from triggering on parent menu open
329
312
  if (!this.__openListenerActive) {
@@ -346,7 +329,10 @@ export const ItemsMixin = (superClass) =>
346
329
  if (itemElement._item.children && itemElement._item.children.length) {
347
330
  itemElement.setAttribute('aria-expanded', 'true');
348
331
  itemElement.setAttribute('expanded', '');
349
- this.__openSubMenu(subMenu, itemElement);
332
+
333
+ // Forward parent overlay class
334
+ const { overlayClass } = menu;
335
+ this.__openSubMenu(subMenu, itemElement, overlayClass);
350
336
  } else {
351
337
  subMenu.listenOn.focus();
352
338
  }
@@ -367,7 +353,7 @@ export const ItemsMixin = (superClass) =>
367
353
  }
368
354
  });
369
355
  } else {
370
- const listBox = root.querySelector('vaadin-context-menu-list-box');
356
+ const listBox = root.querySelector(`${this._tagNamePrefix}-list-box`);
371
357
  if (this._theme) {
372
358
  listBox.setAttribute('theme', this._theme);
373
359
  } else {
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { PositionMixinClass } from '@vaadin/overlay/src/vaadin-overlay-position-mixin.js';
8
+
9
+ export declare function MenuOverlayMixin<T extends Constructor<HTMLElement>>(
10
+ base: T,
11
+ ): Constructor<MenuOverlayMixinClass> & Constructor<PositionMixinClass> & T;
12
+
13
+ export declare class MenuOverlayMixinClass {
14
+ protected readonly parentOverlay: HTMLElement | undefined;
15
+
16
+ /**
17
+ * Returns the adjusted boundaries of the overlay.
18
+ */
19
+ getBoundaries(): { xMax: number; xMin: number; yMax: number };
20
+
21
+ /**
22
+ * Returns the first element in the overlay content.
23
+ */
24
+ getFirstChild(): HTMLElement;
25
+ }
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { PositionMixin } from '@vaadin/overlay/src/vaadin-overlay-position-mixin.js';
7
+
8
+ /**
9
+ * @polymerMixin
10
+ */
11
+ export const MenuOverlayMixin = (superClass) =>
12
+ class MenuOverlayMixin extends PositionMixin(superClass) {
13
+ static get properties() {
14
+ return {
15
+ /**
16
+ * @protected
17
+ */
18
+ parentOverlay: {
19
+ type: Object,
20
+ readOnly: true,
21
+ },
22
+ };
23
+ }
24
+
25
+ static get observers() {
26
+ return ['_themeChanged(_theme)'];
27
+ }
28
+
29
+ /** @protected */
30
+ ready() {
31
+ super.ready();
32
+
33
+ this.addEventListener('keydown', (e) => {
34
+ if (!e.defaultPrevented && e.composedPath()[0] === this.$.overlay && [38, 40].indexOf(e.keyCode) > -1) {
35
+ const child = this.getFirstChild();
36
+ if (child && Array.isArray(child.items) && child.items.length) {
37
+ e.preventDefault();
38
+ if (e.keyCode === 38) {
39
+ child.items[child.items.length - 1].focus();
40
+ } else {
41
+ child.focus();
42
+ }
43
+ }
44
+ }
45
+ });
46
+ }
47
+
48
+ /**
49
+ * Returns the first element in the overlay content.
50
+ *
51
+ * @returns {HTMLElement}
52
+ */
53
+ getFirstChild() {
54
+ return this.querySelector(':not(style):not(slot)');
55
+ }
56
+
57
+ /** @private */
58
+ _themeChanged() {
59
+ this.close();
60
+ }
61
+
62
+ /**
63
+ * Returns the adjusted boundaries of the overlay.
64
+ *
65
+ * @returns {object}
66
+ */
67
+ getBoundaries() {
68
+ // Measure actual overlay and content sizes
69
+ const overlayRect = this.getBoundingClientRect();
70
+ const contentRect = this.$.overlay.getBoundingClientRect();
71
+
72
+ // Maximum x and y values are imposed by content size and overlay limits.
73
+ let yMax = overlayRect.bottom - contentRect.height;
74
+
75
+ // Adjust constraints to ensure bottom-aligned applies to sub-menu.
76
+ const parent = this.parentOverlay;
77
+ if (parent && parent.hasAttribute('bottom-aligned')) {
78
+ const parentStyle = getComputedStyle(parent);
79
+ yMax = yMax - parseFloat(parentStyle.bottom) - parseFloat(parentStyle.height);
80
+ }
81
+
82
+ return {
83
+ xMax: overlayRect.right - contentRect.width,
84
+ xMin: overlayRect.left + contentRect.width,
85
+ yMax,
86
+ };
87
+ }
88
+
89
+ /**
90
+ * @protected
91
+ * @override
92
+ */
93
+ _updatePosition() {
94
+ super._updatePosition();
95
+
96
+ if (this.positionTarget && this.parentOverlay) {
97
+ // This overlay is positioned by a parent menu item,
98
+ // adjust the position by the overlay content paddings
99
+ const content = this.$.content;
100
+ const style = getComputedStyle(content);
101
+
102
+ // Horizontal adjustment
103
+ const isLeftAligned = !!this.style.left;
104
+ if (isLeftAligned) {
105
+ this.style.left = `${parseFloat(this.style.left) + parseFloat(style.paddingLeft)}px`;
106
+ } else {
107
+ this.style.right = `${parseFloat(this.style.right) + parseFloat(style.paddingRight)}px`;
108
+ }
109
+
110
+ // Vertical adjustment
111
+ const isBottomAligned = !!this.style.bottom;
112
+ if (isBottomAligned) {
113
+ this.style.bottom = `${parseFloat(this.style.bottom) - parseFloat(style.paddingBottom)}px`;
114
+ } else {
115
+ this.style.top = `${parseFloat(this.style.top) - parseFloat(style.paddingTop)}px`;
116
+ }
117
+ }
118
+ }
119
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import type { CSSResult } from 'lit';
7
+
8
+ export const styles: CSSResult;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { css } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
7
+
8
+ export const styles = css`
9
+ :host {
10
+ align-items: flex-start;
11
+ justify-content: flex-start;
12
+ }
13
+
14
+ :host([right-aligned]),
15
+ :host([end-aligned]) {
16
+ align-items: flex-end;
17
+ }
18
+
19
+ :host([bottom-aligned]) {
20
+ justify-content: flex-end;
21
+ }
22
+
23
+ [part='overlay'] {
24
+ background-color: #fff;
25
+ }
26
+ `;
@@ -0,0 +1,46 @@
1
+ import '@vaadin/vaadin-lumo-styles/color.js';
2
+ import '@vaadin/vaadin-lumo-styles/font-icons.js';
3
+ import '@vaadin/vaadin-lumo-styles/sizing.js';
4
+ import '@vaadin/vaadin-lumo-styles/spacing.js';
5
+ import { item } from '@vaadin/item/theme/lumo/vaadin-item-styles.js';
6
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
7
+
8
+ const contextMenuItem = css`
9
+ /* :hover needed to workaround https://github.com/vaadin/web-components/issues/3133 */
10
+ :host(:hover) {
11
+ user-select: none;
12
+ -ms-user-select: none;
13
+ -webkit-user-select: none;
14
+ }
15
+
16
+ :host([role='menuitem'][menu-item-checked]) [part='checkmark']::before {
17
+ opacity: 1;
18
+ }
19
+
20
+ :host([aria-haspopup='true'])::after {
21
+ font-family: lumo-icons;
22
+ font-size: var(--lumo-icon-size-xs);
23
+ content: var(--lumo-icons-angle-right);
24
+ color: var(--lumo-tertiary-text-color);
25
+ }
26
+
27
+ :host(:not([dir='rtl'])[aria-haspopup='true'])::after {
28
+ margin-right: calc(var(--lumo-space-m) * -1);
29
+ padding-left: var(--lumo-space-m);
30
+ }
31
+
32
+ :host([expanded]) {
33
+ background-color: var(--lumo-primary-color-10pct);
34
+ }
35
+
36
+ /* RTL styles */
37
+ :host([dir='rtl'][aria-haspopup='true'])::after {
38
+ content: var(--lumo-icons-angle-left);
39
+ margin-left: calc(var(--lumo-space-m) * -1);
40
+ padding-right: var(--lumo-space-m);
41
+ }
42
+ `;
43
+
44
+ registerStyles('vaadin-context-menu-item', [item, contextMenuItem], { moduleId: 'lumo-context-menu-item' });
45
+
46
+ export { contextMenuItem };
@@ -0,0 +1,47 @@
1
+ import '@vaadin/vaadin-lumo-styles/color.js';
2
+ import '@vaadin/vaadin-lumo-styles/spacing.js';
3
+ import '@vaadin/vaadin-lumo-styles/style.js';
4
+ import { listBox } from '@vaadin/list-box/theme/lumo/vaadin-list-box-styles.js';
5
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
6
+
7
+ const contextMenuListBox = css`
8
+ :host {
9
+ --_lumo-list-box-item-selected-icon-display: block;
10
+ }
11
+
12
+ /* Normal item */
13
+ [part='items'] ::slotted([role='menuitem']) {
14
+ -webkit-tap-highlight-color: var(--lumo-primary-color-10pct);
15
+ cursor: default;
16
+ outline: none;
17
+ border-radius: var(--lumo-border-radius-m);
18
+ padding-left: calc(var(--lumo-border-radius-m) / 4);
19
+ padding-right: calc(var(--lumo-space-l) + var(--lumo-border-radius-m) / 4);
20
+ }
21
+
22
+ /* Hovered item */
23
+ /* TODO a workaround until we have "focus-follows-mouse". After that, use the hover style for focus-ring as well */
24
+ [part='items'] ::slotted([role='menuitem']:hover:not([disabled])),
25
+ [part='items'] ::slotted([role='menuitem'][expanded]:not([disabled])) {
26
+ background-color: var(--lumo-primary-color-10pct);
27
+ }
28
+
29
+ /* RTL styles */
30
+ :host([dir='rtl']) [part='items'] ::slotted([role='menuitem']) {
31
+ padding-left: calc(var(--lumo-space-l) + var(--lumo-border-radius-m) / 4);
32
+ padding-right: calc(var(--lumo-border-radius-m) / 4);
33
+ }
34
+
35
+ /* Focused item */
36
+ @media (pointer: coarse) {
37
+ [part='items'] ::slotted([role='menuitem']:hover:not([expanded]):not([disabled])) {
38
+ background-color: transparent;
39
+ }
40
+ }
41
+ `;
42
+
43
+ registerStyles('vaadin-context-menu-list-box', [listBox, contextMenuListBox], {
44
+ moduleId: 'lumo-context-menu-list-box',
45
+ });
46
+
47
+ export { contextMenuListBox };
@@ -0,0 +1,33 @@
1
+ import '@vaadin/vaadin-lumo-styles/spacing.js';
2
+ import '@vaadin/vaadin-lumo-styles/style.js';
3
+ import { menuOverlay } from '@vaadin/vaadin-lumo-styles/mixins/menu-overlay.js';
4
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
5
+
6
+ const contextMenuOverlay = css`
7
+ :host([phone]) {
8
+ top: 0 !important;
9
+ right: 0 !important;
10
+ bottom: var(--vaadin-overlay-viewport-bottom) !important;
11
+ left: 0 !important;
12
+ align-items: stretch;
13
+ justify-content: flex-end;
14
+ }
15
+
16
+ /* TODO These style overrides should not be needed.
17
+ We should instead offer a way to have non-selectable items inside the context menu. */
18
+
19
+ :host {
20
+ --_lumo-list-box-item-selected-icon-display: none;
21
+ --_lumo-list-box-item-padding-left: calc(var(--lumo-space-m) + var(--lumo-border-radius-m) / 4);
22
+ }
23
+
24
+ [part='overlay'] {
25
+ outline: none;
26
+ }
27
+ `;
28
+
29
+ registerStyles('vaadin-context-menu-overlay', [menuOverlay, contextMenuOverlay], {
30
+ moduleId: 'lumo-context-menu-overlay',
31
+ });
32
+
33
+ export { contextMenuOverlay };
@@ -1,5 +1,5 @@
1
- import './vaadin-context-menu-styles.js';
2
- import '@vaadin/item/theme/lumo/vaadin-item.js';
3
- import '@vaadin/list-box/theme/lumo/vaadin-list-box.js';
1
+ import './vaadin-context-menu-item-styles.js';
2
+ import './vaadin-context-menu-list-box-styles.js';
3
+ import './vaadin-context-menu-overlay-styles.js';
4
4
  import '@vaadin/overlay/theme/lumo/vaadin-overlay.js';
5
5
  import '../../src/vaadin-context-menu.js';
@@ -0,0 +1,36 @@
1
+ import '@vaadin/vaadin-material-styles/font-icons.js';
2
+ import '@vaadin/vaadin-material-styles/color.js';
3
+ import '@vaadin/vaadin-material-styles/typography.js';
4
+ import { item } from '@vaadin/item/theme/material/vaadin-item-styles.js';
5
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
6
+
7
+ const contextMenuItem = css`
8
+ :host([aria-haspopup='true'])::after {
9
+ font-family: material-icons;
10
+ font-size: var(--material-icon-font-size);
11
+ }
12
+
13
+ :host(:not([dir='rtl'])[aria-haspopup='true'])::after {
14
+ content: var(--material-icons-chevron-right);
15
+ padding-left: 9px;
16
+ margin-right: -9px;
17
+ }
18
+
19
+ :host([dir='rtl'][aria-haspopup='true'])::after {
20
+ content: var(--material-icons-chevron-left);
21
+ padding-right: 9px;
22
+ margin-left: -9px;
23
+ }
24
+
25
+ :host([menu-item-checked]) [part='checkmark']::before {
26
+ content: var(--material-icons-check);
27
+ }
28
+
29
+ :host([expanded]) {
30
+ background-color: var(--material-secondary-background-color);
31
+ }
32
+ `;
33
+
34
+ registerStyles('vaadin-context-menu-item', [item, contextMenuItem], { moduleId: 'material-context-menu-item' });
35
+
36
+ export { contextMenuItem };
@@ -0,0 +1,38 @@
1
+ import '@vaadin/vaadin-material-styles/color.js';
2
+ import '@vaadin/vaadin-material-styles/typography.js';
3
+ import { listBox } from '@vaadin/list-box/theme/material/vaadin-list-box-styles.js';
4
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
5
+
6
+ const contextMenuListBox = css`
7
+ [part='items'] ::slotted([role='menuitem']) {
8
+ min-height: 36px;
9
+ padding: 8px 32px 8px 10px;
10
+ font-size: var(--material-small-font-size);
11
+ line-height: 24px;
12
+ }
13
+
14
+ :host([dir='rtl']) [part='items'] ::slotted([role='menuitem']) {
15
+ padding: 8px 10px 8px 32px;
16
+ }
17
+
18
+ [part='items'] ::slotted([role='menuitem']:hover:not([disabled])) {
19
+ background-color: var(--material-secondary-background-color);
20
+ }
21
+
22
+ [part='items'] ::slotted([role='menuitem'][focused]:not([disabled])) {
23
+ background-color: var(--material-divider-color);
24
+ }
25
+
26
+ @media (pointer: coarse) {
27
+ [part='items'] ::slotted([role='menuitem']:hover:not([disabled])),
28
+ [part='items'] ::slotted([role='menuitem'][focused]:not([disabled])) {
29
+ background-color: transparent;
30
+ }
31
+ }
32
+ `;
33
+
34
+ registerStyles('vaadin-context-menu-list-box', [listBox, contextMenuListBox], {
35
+ moduleId: 'material-context-menu-list-box',
36
+ });
37
+
38
+ export { contextMenuListBox };
@@ -0,0 +1,15 @@
1
+ import { menuOverlay } from '@vaadin/vaadin-material-styles/mixins/menu-overlay.js';
2
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
3
+
4
+ const contextMenuOverlay = css`
5
+ [part='overlay'] {
6
+ outline: none;
7
+ will-change: transform, opacity;
8
+ }
9
+ `;
10
+
11
+ registerStyles('vaadin-context-menu-overlay', [menuOverlay, contextMenuOverlay], {
12
+ moduleId: 'material-context-menu-overlay',
13
+ });
14
+
15
+ export { contextMenuOverlay };
@@ -1,5 +1,5 @@
1
- import './vaadin-context-menu-styles.js';
2
- import '@vaadin/item/theme/material/vaadin-item.js';
3
- import '@vaadin/list-box/theme/material/vaadin-list-box.js';
1
+ import './vaadin-context-menu-item-styles.js';
2
+ import './vaadin-context-menu-list-box-styles.js';
3
+ import './vaadin-context-menu-overlay-styles.js';
4
4
  import '@vaadin/overlay/theme/material/vaadin-overlay.js';
5
5
  import '../../src/vaadin-context-menu.js';
package/web-types.json CHANGED
@@ -1,15 +1,26 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/context-menu",
4
- "version": "24.0.0-alpha8",
4
+ "version": "24.0.0-alpha12",
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.\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/24.0.0-alpha8/#/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/24.0.0-alpha8/#/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.0.0-alpha8/#/elements/vaadin-list-box).\n\nNote: the `theme` attribute value set on `<vaadin-context-menu>` is\npropagated to the internal components listed above.",
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/24.0.0-alpha12/#/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/24.0.0-alpha12/#/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.0.0-alpha12/#/elements/vaadin-list-box).\n\nNote: the `theme` attribute value set on `<vaadin-context-menu>` is\npropagated to the internal components listed above.",
12
12
  "attributes": [
13
+ {
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
+ },
13
24
  {
14
25
  "name": "selector",
15
26
  "description": "CSS selector that can be used to target any child element\nof the context menu to listen for `openOn` events.",
@@ -53,6 +64,17 @@
53
64
  ],
54
65
  "js": {
55
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
+ },
56
78
  {
57
79
  "name": "items",
58
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},\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```",