@vaadin/context-menu 25.0.0-alpha1 → 25.0.0-alpha10
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 +15 -13
- package/src/styles/vaadin-context-menu-item-base-styles.d.ts +8 -0
- package/src/styles/vaadin-context-menu-item-base-styles.js +34 -0
- package/src/styles/vaadin-context-menu-item-core-styles.d.ts +8 -0
- package/src/styles/vaadin-context-menu-item-core-styles.js +8 -0
- package/src/styles/vaadin-context-menu-overlay-base-styles.d.ts +8 -0
- package/src/styles/vaadin-context-menu-overlay-base-styles.js +9 -0
- package/src/styles/vaadin-context-menu-overlay-core-styles.d.ts +8 -0
- package/src/styles/vaadin-context-menu-overlay-core-styles.js +9 -0
- package/src/{vaadin-menu-overlay-styles.d.ts → styles/vaadin-menu-overlay-base-styles.d.ts} +1 -1
- package/src/styles/vaadin-menu-overlay-base-styles.js +31 -0
- package/src/styles/vaadin-menu-overlay-core-styles.d.ts +8 -0
- package/src/{vaadin-menu-overlay-styles.js → styles/vaadin-menu-overlay-core-styles.js} +1 -1
- package/src/vaadin-context-menu-item.js +5 -11
- package/src/vaadin-context-menu-list-box.js +5 -18
- package/src/vaadin-context-menu-mixin.js +118 -74
- package/src/vaadin-context-menu-overlay.js +5 -4
- package/src/vaadin-context-menu.d.ts +15 -6
- package/src/vaadin-context-menu.js +30 -17
- package/src/vaadin-contextmenu-items-mixin.js +37 -27
- package/src/vaadin-menu-overlay-mixin.d.ts +0 -5
- package/src/vaadin-menu-overlay-mixin.js +22 -27
- package/web-types.json +6 -2
- package/web-types.lit.json +9 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/context-menu",
|
|
3
|
-
"version": "25.0.0-
|
|
3
|
+
"version": "25.0.0-alpha10",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
"lit.d.ts",
|
|
24
24
|
"lit.js",
|
|
25
25
|
"src",
|
|
26
|
+
"!src/styles/*-base-styles.d.ts",
|
|
27
|
+
"!src/styles/*-base-styles.js",
|
|
26
28
|
"theme",
|
|
27
29
|
"vaadin-*.d.ts",
|
|
28
30
|
"vaadin-*.js",
|
|
@@ -37,25 +39,25 @@
|
|
|
37
39
|
],
|
|
38
40
|
"dependencies": {
|
|
39
41
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
40
|
-
"@vaadin/a11y-base": "25.0.0-
|
|
41
|
-
"@vaadin/component-base": "25.0.0-
|
|
42
|
-
"@vaadin/item": "25.0.0-
|
|
43
|
-
"@vaadin/list-box": "25.0.0-
|
|
44
|
-
"@vaadin/lit-renderer": "25.0.0-
|
|
45
|
-
"@vaadin/overlay": "25.0.0-
|
|
46
|
-
"@vaadin/vaadin-lumo-styles": "25.0.0-
|
|
47
|
-
"@vaadin/vaadin-themable-mixin": "25.0.0-
|
|
42
|
+
"@vaadin/a11y-base": "25.0.0-alpha10",
|
|
43
|
+
"@vaadin/component-base": "25.0.0-alpha10",
|
|
44
|
+
"@vaadin/item": "25.0.0-alpha10",
|
|
45
|
+
"@vaadin/list-box": "25.0.0-alpha10",
|
|
46
|
+
"@vaadin/lit-renderer": "25.0.0-alpha10",
|
|
47
|
+
"@vaadin/overlay": "25.0.0-alpha10",
|
|
48
|
+
"@vaadin/vaadin-lumo-styles": "25.0.0-alpha10",
|
|
49
|
+
"@vaadin/vaadin-themable-mixin": "25.0.0-alpha10",
|
|
48
50
|
"lit": "^3.0.0"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
|
-
"@vaadin/chai-plugins": "25.0.0-
|
|
52
|
-
"@vaadin/test-runner-commands": "25.0.0-
|
|
53
|
-
"@vaadin/testing-helpers": "^
|
|
53
|
+
"@vaadin/chai-plugins": "25.0.0-alpha10",
|
|
54
|
+
"@vaadin/test-runner-commands": "25.0.0-alpha10",
|
|
55
|
+
"@vaadin/testing-helpers": "^2.0.0",
|
|
54
56
|
"sinon": "^18.0.0"
|
|
55
57
|
},
|
|
56
58
|
"web-types": [
|
|
57
59
|
"web-types.json",
|
|
58
60
|
"web-types.lit.json"
|
|
59
61
|
],
|
|
60
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "6cc6c94079e805fa5b2f0af4dbf3b2a7485e57d0"
|
|
61
63
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2025 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import '@vaadin/component-base/src/style-props.js';
|
|
7
|
+
import { css } from 'lit';
|
|
8
|
+
import { itemStyles } from '@vaadin/item/src/styles/vaadin-item-base-styles.js';
|
|
9
|
+
|
|
10
|
+
const menuItemStyles = css`
|
|
11
|
+
:host::after {
|
|
12
|
+
background: var(--vaadin-color-subtle);
|
|
13
|
+
content: '';
|
|
14
|
+
display: block;
|
|
15
|
+
height: var(--vaadin-icon-size, 1lh);
|
|
16
|
+
mask-image: var(--_vaadin-icon-chevron-down);
|
|
17
|
+
rotate: -90deg;
|
|
18
|
+
visibility: hidden;
|
|
19
|
+
width: var(--vaadin-icon-size, 1lh);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
:host([dir='rtl'])::after {
|
|
23
|
+
rotate: 90deg;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* TODO would be nice to only reserve the space for these if
|
|
27
|
+
one or mote items in the list is checkable or has child items */
|
|
28
|
+
:host([aria-haspopup='true'])::after,
|
|
29
|
+
:host([menu-item-checked]) [part='checkmark'] {
|
|
30
|
+
visibility: visible;
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
export const contextMenuItemStyles = [itemStyles, menuItemStyles];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2025 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { itemStyles } from '@vaadin/item/src/styles/vaadin-item-core-styles.js';
|
|
7
|
+
|
|
8
|
+
export const contextMenuItemStyles = [itemStyles];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2025 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { overlayStyles } from '@vaadin/overlay/src/styles/vaadin-overlay-base-styles.js';
|
|
7
|
+
import { menuOverlayStyles } from './vaadin-menu-overlay-base-styles.js';
|
|
8
|
+
|
|
9
|
+
export const contextMenuOverlayStyles = [overlayStyles, menuOverlayStyles];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2025 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { overlayStyles } from '@vaadin/overlay/src/styles/vaadin-overlay-core-styles.js';
|
|
7
|
+
import { menuOverlayStyles } from './vaadin-menu-overlay-core-styles.js';
|
|
8
|
+
|
|
9
|
+
export const contextMenuOverlayStyles = [overlayStyles, menuOverlayStyles];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2025 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { css } from 'lit';
|
|
7
|
+
|
|
8
|
+
export const menuOverlayStyles = 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='content'] {
|
|
24
|
+
padding: var(--vaadin-item-overlay-padding, 4px);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* TODO keyboard focus becomes visible even when navigating the menu with the mouse */
|
|
28
|
+
[part='overlay']:focus-visible {
|
|
29
|
+
outline: none;
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
* Copyright (c) 2016 - 2025 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { html, LitElement } from 'lit';
|
|
7
7
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
8
8
|
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
9
9
|
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
|
|
10
10
|
import { ItemMixin } from '@vaadin/item/src/vaadin-item-mixin.js';
|
|
11
|
+
import { LumoInjectionMixin } from '@vaadin/vaadin-themable-mixin/lumo-injection-mixin.js';
|
|
11
12
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
13
|
+
import { contextMenuItemStyles } from './styles/vaadin-context-menu-item-core-styles.js';
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
@@ -20,21 +22,13 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
|
|
|
20
22
|
* @mixes ThemableMixin
|
|
21
23
|
* @protected
|
|
22
24
|
*/
|
|
23
|
-
class ContextMenuItem extends ItemMixin(ThemableMixin(DirMixin(PolylitMixin(LitElement)))) {
|
|
25
|
+
class ContextMenuItem extends ItemMixin(ThemableMixin(DirMixin(PolylitMixin(LumoInjectionMixin(LitElement))))) {
|
|
24
26
|
static get is() {
|
|
25
27
|
return 'vaadin-context-menu-item';
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
static get styles() {
|
|
29
|
-
return
|
|
30
|
-
:host {
|
|
31
|
-
display: inline-block;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
:host([hidden]) {
|
|
35
|
-
display: none !important;
|
|
36
|
-
}
|
|
37
|
-
`;
|
|
31
|
+
return contextMenuItemStyles;
|
|
38
32
|
}
|
|
39
33
|
|
|
40
34
|
/** @protected */
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
* Copyright (c) 2016 - 2025 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { html, LitElement } from 'lit';
|
|
7
7
|
import { ListMixin } from '@vaadin/a11y-base/src/list-mixin.js';
|
|
8
8
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
9
9
|
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
10
10
|
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
|
|
11
|
+
import { listBoxStyles } from '@vaadin/list-box/src/styles/vaadin-list-box-core-styles.js';
|
|
12
|
+
import { LumoInjectionMixin } from '@vaadin/vaadin-themable-mixin/lumo-injection-mixin.js';
|
|
11
13
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -20,28 +22,13 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
|
|
|
20
22
|
* @mixes ThemableMixin
|
|
21
23
|
* @protected
|
|
22
24
|
*/
|
|
23
|
-
class ContextMenuListBox extends ListMixin(ThemableMixin(DirMixin(PolylitMixin(LitElement)))) {
|
|
25
|
+
class ContextMenuListBox extends ListMixin(ThemableMixin(DirMixin(PolylitMixin(LumoInjectionMixin(LitElement))))) {
|
|
24
26
|
static get is() {
|
|
25
27
|
return 'vaadin-context-menu-list-box';
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
static get styles() {
|
|
29
|
-
return
|
|
30
|
-
:host {
|
|
31
|
-
display: flex;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
:host([hidden]) {
|
|
35
|
-
display: none !important;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
[part='items'] {
|
|
39
|
-
height: 100%;
|
|
40
|
-
width: 100%;
|
|
41
|
-
overflow-y: auto;
|
|
42
|
-
-webkit-overflow-scrolling: touch;
|
|
43
|
-
}
|
|
44
|
-
`;
|
|
31
|
+
return listBoxStyles;
|
|
45
32
|
}
|
|
46
33
|
|
|
47
34
|
static get properties() {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright (c) 2016 - 2025 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import { isElementFocusable } from '@vaadin/a11y-base/src/focus-utils.js';
|
|
6
|
+
import { isElementFocusable, isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
|
|
7
7
|
import { isAndroid, isIOS } from '@vaadin/component-base/src/browser-utils.js';
|
|
8
8
|
import { addListener, deepTargetFind, gestures, removeListener } from '@vaadin/component-base/src/gestures.js';
|
|
9
9
|
import { MediaQueryController } from '@vaadin/component-base/src/media-query-controller.js';
|
|
@@ -31,6 +31,8 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
31
31
|
*/
|
|
32
32
|
opened: {
|
|
33
33
|
type: Boolean,
|
|
34
|
+
reflectToAttribute: true,
|
|
35
|
+
observer: '_openedChanged',
|
|
34
36
|
value: false,
|
|
35
37
|
notify: true,
|
|
36
38
|
readOnly: true,
|
|
@@ -123,22 +125,15 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
123
125
|
|
|
124
126
|
static get observers() {
|
|
125
127
|
return [
|
|
126
|
-
'_openedChanged(opened)',
|
|
127
128
|
'_targetOrOpenOnChanged(listenOn, openOn)',
|
|
128
129
|
'_rendererChanged(renderer, items)',
|
|
129
130
|
'_fullscreenChanged(_fullscreen)',
|
|
130
|
-
'_overlayContextChanged(_overlayElement, _context)',
|
|
131
|
-
'_overlayModelessChanged(_overlayElement, _modeless)',
|
|
132
|
-
'_overlayPhoneChanged(_overlayElement, _phone)',
|
|
133
|
-
'_overlayThemeChanged(_overlayElement, _theme)',
|
|
134
131
|
];
|
|
135
132
|
}
|
|
136
133
|
|
|
137
134
|
constructor() {
|
|
138
135
|
super();
|
|
139
136
|
|
|
140
|
-
this._createOverlay();
|
|
141
|
-
|
|
142
137
|
this._boundOpen = this.open.bind(this);
|
|
143
138
|
this._boundClose = this.close.bind(this);
|
|
144
139
|
this._boundPreventDefault = this._preventDefault.bind(this);
|
|
@@ -170,8 +165,10 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
170
165
|
}
|
|
171
166
|
|
|
172
167
|
/** @protected */
|
|
173
|
-
|
|
174
|
-
super.
|
|
168
|
+
firstUpdated() {
|
|
169
|
+
super.firstUpdated();
|
|
170
|
+
|
|
171
|
+
this._overlayElement = this.$.overlay;
|
|
175
172
|
|
|
176
173
|
this.addController(
|
|
177
174
|
new MediaQueryController(this._fullscreenMediaQuery, (matches) => {
|
|
@@ -180,29 +177,17 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
180
177
|
);
|
|
181
178
|
}
|
|
182
179
|
|
|
183
|
-
/** @private */
|
|
184
|
-
_createOverlay() {
|
|
185
|
-
// Create an overlay in the constructor to use in observers before `ready()`
|
|
186
|
-
const overlay = document.createElement(`${this._tagNamePrefix}-overlay`);
|
|
187
|
-
overlay.owner = this;
|
|
188
|
-
|
|
189
|
-
overlay.addEventListener('opened-changed', (e) => {
|
|
190
|
-
this._onOverlayOpened(e);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
overlay.addEventListener('vaadin-overlay-open', (e) => {
|
|
194
|
-
this._onVaadinOverlayOpen(e);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
this._overlayElement = overlay;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
180
|
/**
|
|
201
181
|
* Runs before overlay is fully rendered
|
|
202
182
|
* @private
|
|
203
183
|
*/
|
|
204
|
-
_onOverlayOpened(
|
|
205
|
-
|
|
184
|
+
_onOverlayOpened(event) {
|
|
185
|
+
// Ignore events from submenus
|
|
186
|
+
if (event.target !== this._overlayElement) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const opened = event.detail.value;
|
|
206
191
|
this._setOpened(opened);
|
|
207
192
|
if (opened) {
|
|
208
193
|
this.__alignOverlayPosition();
|
|
@@ -213,43 +198,23 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
213
198
|
* Runs after overlay is fully rendered
|
|
214
199
|
* @private
|
|
215
200
|
*/
|
|
216
|
-
_onVaadinOverlayOpen() {
|
|
217
|
-
|
|
218
|
-
this._overlayElement
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/** @private */
|
|
223
|
-
_overlayContextChanged(overlay, context) {
|
|
224
|
-
if (overlay) {
|
|
225
|
-
overlay.model = context;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/** @private */
|
|
230
|
-
_overlayModelessChanged(overlay, modeless) {
|
|
231
|
-
if (overlay) {
|
|
232
|
-
overlay.modeless = modeless;
|
|
201
|
+
_onVaadinOverlayOpen(event) {
|
|
202
|
+
// Ignore events from submenus
|
|
203
|
+
if (event.target !== this._overlayElement) {
|
|
204
|
+
return;
|
|
233
205
|
}
|
|
234
|
-
}
|
|
235
206
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
overlay.toggleAttribute('phone', phone);
|
|
240
|
-
overlay.withBackdrop = phone;
|
|
241
|
-
}
|
|
207
|
+
this.__alignOverlayPosition();
|
|
208
|
+
this._overlayElement.style.visibility = '';
|
|
209
|
+
this.__forwardFocus();
|
|
242
210
|
}
|
|
243
211
|
|
|
244
|
-
/**
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
overlay.removeAttribute('theme');
|
|
251
|
-
}
|
|
252
|
-
}
|
|
212
|
+
/**
|
|
213
|
+
* Runs after overlay's closing animation is finished
|
|
214
|
+
* @private
|
|
215
|
+
*/
|
|
216
|
+
_onVaadinOverlayClosed() {
|
|
217
|
+
this.dispatchEvent(new CustomEvent('closed'));
|
|
253
218
|
}
|
|
254
219
|
|
|
255
220
|
/** @private */
|
|
@@ -318,17 +283,14 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
318
283
|
}
|
|
319
284
|
|
|
320
285
|
/** @private */
|
|
321
|
-
_openedChanged(opened) {
|
|
286
|
+
_openedChanged(opened, oldOpened) {
|
|
322
287
|
if (opened) {
|
|
323
288
|
document.documentElement.addEventListener('contextmenu', this._boundOnGlobalContextMenu, true);
|
|
324
|
-
} else {
|
|
289
|
+
} else if (oldOpened) {
|
|
325
290
|
document.documentElement.removeEventListener('contextmenu', this._boundOnGlobalContextMenu, true);
|
|
326
291
|
}
|
|
327
292
|
|
|
328
293
|
this.__setListenOnUserSelect(opened);
|
|
329
|
-
|
|
330
|
-
// Has to be set after instance has been created
|
|
331
|
-
this._overlayElement.opened = opened;
|
|
332
294
|
}
|
|
333
295
|
|
|
334
296
|
/**
|
|
@@ -338,11 +300,18 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
338
300
|
* It is not guaranteed that the update happens immediately (synchronously) after it is requested.
|
|
339
301
|
*/
|
|
340
302
|
requestContentUpdate() {
|
|
341
|
-
if (!this._overlayElement
|
|
303
|
+
if (!this._overlayElement) {
|
|
342
304
|
return;
|
|
343
305
|
}
|
|
344
306
|
|
|
307
|
+
// Store state to be restored after re-rendering
|
|
308
|
+
this.__preserveMenuState();
|
|
309
|
+
|
|
310
|
+
// Run overlay renderer to re-create DOM elements
|
|
345
311
|
this._overlayElement.requestContentUpdate();
|
|
312
|
+
|
|
313
|
+
// Restore focused item, update sub-menu if needed
|
|
314
|
+
this.__restoreMenuState();
|
|
346
315
|
}
|
|
347
316
|
|
|
348
317
|
/** @private */
|
|
@@ -355,11 +324,7 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
355
324
|
if (this.closeOn === 'click') {
|
|
356
325
|
this.closeOn = '';
|
|
357
326
|
}
|
|
358
|
-
|
|
359
|
-
renderer = this.__itemsRenderer;
|
|
360
327
|
}
|
|
361
|
-
|
|
362
|
-
this._overlayElement.renderer = renderer;
|
|
363
328
|
}
|
|
364
329
|
|
|
365
330
|
/**
|
|
@@ -386,6 +351,11 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
386
351
|
* @param {!Event | undefined} e used as the context for the menu. Overlay coordinates are taken from this event.
|
|
387
352
|
*/
|
|
388
353
|
open(e) {
|
|
354
|
+
// Ignore events from the overlay
|
|
355
|
+
if (this._overlayElement && e.composedPath().includes(this._overlayElement)) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
|
|
389
359
|
if (e && !this.opened) {
|
|
390
360
|
this._context = {
|
|
391
361
|
detail: e.detail,
|
|
@@ -403,12 +373,76 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
403
373
|
this.__y = this._getEventCoordinate(e, 'y');
|
|
404
374
|
this.__pageYOffset = window.pageYOffset;
|
|
405
375
|
|
|
406
|
-
|
|
376
|
+
// Hide overlay until it is fully rendered and positioned
|
|
377
|
+
this._overlayElement.style.visibility = 'hidden';
|
|
407
378
|
this._setOpened(true);
|
|
408
379
|
}
|
|
409
380
|
}
|
|
410
381
|
}
|
|
411
382
|
|
|
383
|
+
/** @private */
|
|
384
|
+
__preserveMenuState() {
|
|
385
|
+
const listBox = this.__getListBox();
|
|
386
|
+
if (listBox) {
|
|
387
|
+
this.__focusedIndex = listBox.items.indexOf(listBox.focused);
|
|
388
|
+
|
|
389
|
+
if (this._subMenu && this._subMenu.opened) {
|
|
390
|
+
this.__subMenuIndex = listBox.items.indexOf(this._subMenu.listenOn);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** @private */
|
|
396
|
+
__restoreMenuState() {
|
|
397
|
+
const focusedIndex = this.__focusedIndex;
|
|
398
|
+
const subMenuIndex = this.__subMenuIndex;
|
|
399
|
+
const selectedIndex = this.__selectedIndex;
|
|
400
|
+
|
|
401
|
+
const listBox = this.__getListBox();
|
|
402
|
+
|
|
403
|
+
if (listBox) {
|
|
404
|
+
// Initialize menu items synchronously
|
|
405
|
+
listBox._observer.flush();
|
|
406
|
+
|
|
407
|
+
if (subMenuIndex > -1) {
|
|
408
|
+
const itemToOpen = listBox.items[subMenuIndex];
|
|
409
|
+
if (itemToOpen) {
|
|
410
|
+
if (Array.isArray(itemToOpen._item.children) && itemToOpen._item.children.length) {
|
|
411
|
+
// Keep nested sub-menu opened and update it
|
|
412
|
+
this.__updateSubMenuForItem(this._subMenu, itemToOpen);
|
|
413
|
+
this._subMenu.requestContentUpdate();
|
|
414
|
+
} else {
|
|
415
|
+
// Item no longer has children, close sub-menu
|
|
416
|
+
this._subMenu.close();
|
|
417
|
+
this.__focusItem(itemToOpen);
|
|
418
|
+
}
|
|
419
|
+
} else {
|
|
420
|
+
// Item no longer exists, focus the list-box
|
|
421
|
+
listBox.focus();
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// Focus previously selected item, in case it was clicked with
|
|
426
|
+
// `keepOpen` option, or the previously focused item, if any
|
|
427
|
+
this.__focusItem(selectedIndex > -1 ? listBox.children[selectedIndex] : listBox.items[focusedIndex]);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
this.__focusedIndex = undefined;
|
|
431
|
+
this.__subMenuIndex = undefined;
|
|
432
|
+
this.__selectedIndex = undefined;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** @private */
|
|
436
|
+
__focusItem(item) {
|
|
437
|
+
if (item) {
|
|
438
|
+
item.focus();
|
|
439
|
+
|
|
440
|
+
if (isKeyboardActive()) {
|
|
441
|
+
item.setAttribute('focus-ring', '');
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
412
446
|
/** @private */
|
|
413
447
|
__onScroll() {
|
|
414
448
|
if (!this.opened) {
|
|
@@ -600,7 +634,11 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
600
634
|
// Dispatch another contextmenu at the same coordinates after the overlay is closed
|
|
601
635
|
this._overlayElement.addEventListener(
|
|
602
636
|
'vaadin-overlay-closed',
|
|
603
|
-
() =>
|
|
637
|
+
(closeEvent) => {
|
|
638
|
+
if (closeEvent.target === this._overlayElement) {
|
|
639
|
+
this.__contextMenuAt(e.clientX, e.clientY);
|
|
640
|
+
}
|
|
641
|
+
},
|
|
604
642
|
{
|
|
605
643
|
once: true,
|
|
606
644
|
},
|
|
@@ -611,4 +649,10 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
611
649
|
this.close();
|
|
612
650
|
}
|
|
613
651
|
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Fired when the context menu is closed.
|
|
655
|
+
*
|
|
656
|
+
* @event closed
|
|
657
|
+
*/
|
|
614
658
|
};
|
|
@@ -8,10 +8,10 @@ import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
|
8
8
|
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
9
9
|
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
|
|
10
10
|
import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js';
|
|
11
|
-
import {
|
|
11
|
+
import { LumoInjectionMixin } from '@vaadin/vaadin-themable-mixin/lumo-injection-mixin.js';
|
|
12
12
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
13
|
+
import { contextMenuOverlayStyles } from './styles/vaadin-context-menu-overlay-core-styles.js';
|
|
13
14
|
import { MenuOverlayMixin } from './vaadin-menu-overlay-mixin.js';
|
|
14
|
-
import { styles } from './vaadin-menu-overlay-styles.js';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
@@ -25,14 +25,14 @@ import { styles } from './vaadin-menu-overlay-styles.js';
|
|
|
25
25
|
* @protected
|
|
26
26
|
*/
|
|
27
27
|
export class ContextMenuOverlay extends MenuOverlayMixin(
|
|
28
|
-
OverlayMixin(DirMixin(ThemableMixin(PolylitMixin(LitElement)))),
|
|
28
|
+
OverlayMixin(DirMixin(ThemableMixin(PolylitMixin(LumoInjectionMixin(LitElement))))),
|
|
29
29
|
) {
|
|
30
30
|
static get is() {
|
|
31
31
|
return 'vaadin-context-menu-overlay';
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
static get styles() {
|
|
35
|
-
return
|
|
35
|
+
return contextMenuOverlayStyles;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/** @protected */
|
|
@@ -42,6 +42,7 @@ export class ContextMenuOverlay extends MenuOverlayMixin(
|
|
|
42
42
|
<div part="overlay" id="overlay" tabindex="0">
|
|
43
43
|
<div part="content" id="content">
|
|
44
44
|
<slot></slot>
|
|
45
|
+
<slot name="submenu"></slot>
|
|
45
46
|
</div>
|
|
46
47
|
</div>
|
|
47
48
|
`;
|
|
@@ -34,6 +34,11 @@ export type ContextMenuItemSelectedEvent<TItem extends ContextMenuItem = Context
|
|
|
34
34
|
value: TItem;
|
|
35
35
|
}>;
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Fired when the context menu is closed.
|
|
39
|
+
*/
|
|
40
|
+
export type ContextMenuClosedEvent = CustomEvent;
|
|
41
|
+
|
|
37
42
|
export interface ContextMenuCustomEventMap<TItem extends ContextMenuItem = ContextMenuItem> {
|
|
38
43
|
'opened-changed': ContextMenuOpenedChangedEvent;
|
|
39
44
|
|
|
@@ -42,6 +47,8 @@ export interface ContextMenuCustomEventMap<TItem extends ContextMenuItem = Conte
|
|
|
42
47
|
'close-all-menus': Event;
|
|
43
48
|
|
|
44
49
|
'items-outside-click': Event;
|
|
50
|
+
|
|
51
|
+
closed: ContextMenuClosedEvent;
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
export interface ContextMenuEventMap<TItem extends ContextMenuItem = ContextMenuItem>
|
|
@@ -208,18 +215,19 @@ export interface ContextMenuEventMap<TItem extends ContextMenuItem = ContextMenu
|
|
|
208
215
|
*
|
|
209
216
|
* ### Styling
|
|
210
217
|
*
|
|
211
|
-
*
|
|
212
|
-
* themable component as the actual visible context menu overlay.
|
|
218
|
+
* The following shadow DOM parts are available for styling:
|
|
213
219
|
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
220
|
+
* Part name | Description
|
|
221
|
+
* -----------------|-------------------------------------------
|
|
222
|
+
* `backdrop` | Backdrop of the overlay
|
|
223
|
+
* `overlay` | The overlay container
|
|
224
|
+
* `content` | The overlay content
|
|
216
225
|
*
|
|
217
226
|
* See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
|
|
218
227
|
*
|
|
219
228
|
* ### Internal components
|
|
220
229
|
*
|
|
221
|
-
* When using `items` API
|
|
222
|
-
* internal components are themable:
|
|
230
|
+
* When using `items` API the following internal components are themable:
|
|
223
231
|
*
|
|
224
232
|
* - `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](#/elements/vaadin-item).
|
|
225
233
|
* - `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](#/elements/vaadin-list-box).
|
|
@@ -236,6 +244,7 @@ export interface ContextMenuEventMap<TItem extends ContextMenuItem = ContextMenu
|
|
|
236
244
|
*
|
|
237
245
|
* @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
|
|
238
246
|
* @fires {CustomEvent} item-selected - Fired when an item is selected when the context menu is populated using the `items` API.
|
|
247
|
+
* @fires {CustomEvent} closed - Fired when the context menu is closed.
|
|
239
248
|
*/
|
|
240
249
|
declare class ContextMenu<TItem extends ContextMenuItem = ContextMenuItem> extends HTMLElement {
|
|
241
250
|
addEventListener<K extends keyof ContextMenuEventMap>(
|
|
@@ -8,6 +8,7 @@ import './vaadin-context-menu-item.js';
|
|
|
8
8
|
import './vaadin-context-menu-list-box.js';
|
|
9
9
|
import './vaadin-context-menu-overlay.js';
|
|
10
10
|
import { css, html, LitElement } from 'lit';
|
|
11
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
11
12
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
12
13
|
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
13
14
|
import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
|
|
@@ -175,18 +176,19 @@ import { ContextMenuMixin } from './vaadin-context-menu-mixin.js';
|
|
|
175
176
|
*
|
|
176
177
|
* ### Styling
|
|
177
178
|
*
|
|
178
|
-
*
|
|
179
|
-
* themable component as the actual visible context menu overlay.
|
|
179
|
+
* The following shadow DOM parts are available for styling:
|
|
180
180
|
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
181
|
+
* Part name | Description
|
|
182
|
+
* -----------------|-------------------------------------------
|
|
183
|
+
* `backdrop` | Backdrop of the overlay
|
|
184
|
+
* `overlay` | The overlay container
|
|
185
|
+
* `content` | The overlay content
|
|
183
186
|
*
|
|
184
187
|
* See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
|
|
185
188
|
*
|
|
186
189
|
* ### Internal components
|
|
187
190
|
*
|
|
188
|
-
* When using `items` API
|
|
189
|
-
* internal components are themable:
|
|
191
|
+
* When using `items` API the following internal components are themable:
|
|
190
192
|
*
|
|
191
193
|
* - `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](#/elements/vaadin-item).
|
|
192
194
|
* - `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](#/elements/vaadin-list-box).
|
|
@@ -203,6 +205,7 @@ import { ContextMenuMixin } from './vaadin-context-menu-mixin.js';
|
|
|
203
205
|
*
|
|
204
206
|
* @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
|
|
205
207
|
* @fires {CustomEvent} item-selected - Fired when an item is selected when the context menu is populated using the `items` API.
|
|
208
|
+
* @fires {CustomEvent} closed - Fired when the context menu is closed.
|
|
206
209
|
*
|
|
207
210
|
* @customElement
|
|
208
211
|
* @extends HTMLElement
|
|
@@ -232,17 +235,27 @@ class ContextMenu extends ContextMenuMixin(
|
|
|
232
235
|
|
|
233
236
|
/** @protected */
|
|
234
237
|
render() {
|
|
235
|
-
return html
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
238
|
+
return html`
|
|
239
|
+
<slot id="slot"></slot>
|
|
240
|
+
<vaadin-context-menu-overlay
|
|
241
|
+
id="overlay"
|
|
242
|
+
.owner="${this}"
|
|
243
|
+
.opened="${this.opened}"
|
|
244
|
+
.model="${this._context}"
|
|
245
|
+
.modeless="${this._modeless}"
|
|
246
|
+
.renderer="${this.items ? this.__itemsRenderer : this.renderer}"
|
|
247
|
+
.withBackdrop="${this._phone}"
|
|
248
|
+
?phone="${this._phone}"
|
|
249
|
+
theme="${ifDefined(this._theme)}"
|
|
250
|
+
exportparts="backdrop, overlay, content"
|
|
251
|
+
@opened-changed="${this._onOverlayOpened}"
|
|
252
|
+
@vaadin-overlay-open="${this._onVaadinOverlayOpen}"
|
|
253
|
+
@vaadin-overlay-closed="${this._onVaadinOverlayClosed}"
|
|
254
|
+
>
|
|
255
|
+
<slot name="overlay"></slot>
|
|
256
|
+
<slot name="submenu" slot="submenu"></slot>
|
|
257
|
+
</vaadin-context-menu-overlay>
|
|
258
|
+
`;
|
|
246
259
|
}
|
|
247
260
|
|
|
248
261
|
/**
|
|
@@ -116,10 +116,10 @@ export const ItemsMixin = (superClass) =>
|
|
|
116
116
|
/** @protected */
|
|
117
117
|
__forwardFocus() {
|
|
118
118
|
const overlay = this._overlayElement;
|
|
119
|
-
const child = overlay.
|
|
119
|
+
const child = overlay._contentRoot.firstElementChild;
|
|
120
120
|
// If parent item is not focused, do not focus submenu
|
|
121
121
|
if (overlay.parentOverlay) {
|
|
122
|
-
const parent = overlay.parentOverlay.querySelector('[expanded]');
|
|
122
|
+
const parent = overlay.parentOverlay._contentRoot.querySelector('[expanded]');
|
|
123
123
|
if (parent && parent.hasAttribute('focused') && child) {
|
|
124
124
|
child.focus();
|
|
125
125
|
} else {
|
|
@@ -132,14 +132,12 @@ export const ItemsMixin = (superClass) =>
|
|
|
132
132
|
|
|
133
133
|
/** @private */
|
|
134
134
|
__openSubMenu(subMenu, itemElement, overlayClass) {
|
|
135
|
-
subMenu
|
|
136
|
-
subMenu.listenOn = itemElement;
|
|
135
|
+
this.__updateSubMenuForItem(subMenu, itemElement);
|
|
137
136
|
subMenu.overlayClass = overlayClass;
|
|
138
137
|
|
|
139
138
|
const parent = this._overlayElement;
|
|
140
139
|
|
|
141
140
|
const subMenuOverlay = subMenu._overlayElement;
|
|
142
|
-
subMenuOverlay.positionTarget = itemElement;
|
|
143
141
|
subMenuOverlay.noHorizontalOverlap = true;
|
|
144
142
|
// Store the reference parent overlay
|
|
145
143
|
subMenuOverlay._setParentOverlay(parent);
|
|
@@ -163,6 +161,13 @@ export const ItemsMixin = (superClass) =>
|
|
|
163
161
|
);
|
|
164
162
|
}
|
|
165
163
|
|
|
164
|
+
/** @private */
|
|
165
|
+
__updateSubMenuForItem(subMenu, itemElement) {
|
|
166
|
+
subMenu.items = itemElement._item.children;
|
|
167
|
+
subMenu.listenOn = itemElement;
|
|
168
|
+
subMenu._overlayElement.positionTarget = itemElement;
|
|
169
|
+
}
|
|
170
|
+
|
|
166
171
|
/**
|
|
167
172
|
* @param {!ContextMenuItem} item
|
|
168
173
|
* @return {HTMLElement}
|
|
@@ -248,10 +253,20 @@ export const ItemsMixin = (superClass) =>
|
|
|
248
253
|
// Open a submenu on click event when a touch device is used.
|
|
249
254
|
// On desktop, a submenu opens on hover.
|
|
250
255
|
overlay.addEventListener(isTouch ? 'click' : 'mouseover', (event) => {
|
|
256
|
+
// Ignore events from the submenus
|
|
257
|
+
if (event.composedPath().includes(this._subMenu)) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
|
|
251
261
|
this.__showSubMenu(event);
|
|
252
262
|
});
|
|
253
263
|
|
|
254
264
|
overlay.addEventListener('keydown', (event) => {
|
|
265
|
+
// Ignore events from the submenus
|
|
266
|
+
if (event.composedPath().includes(this._subMenu)) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
255
270
|
const { key } = event;
|
|
256
271
|
const isRTL = this.__isRTL;
|
|
257
272
|
|
|
@@ -283,10 +298,6 @@ export const ItemsMixin = (superClass) =>
|
|
|
283
298
|
subMenu._modeless = true;
|
|
284
299
|
subMenu.openOn = 'opensubmenu';
|
|
285
300
|
|
|
286
|
-
// Sub-menu doesn't have a target to wrap,
|
|
287
|
-
// so there is no need to keep it visible.
|
|
288
|
-
subMenu.setAttribute('hidden', '');
|
|
289
|
-
|
|
290
301
|
// Close sub-menu when the parent menu closes.
|
|
291
302
|
this.addEventListener('opened-changed', (event) => {
|
|
292
303
|
if (!event.detail.value) {
|
|
@@ -317,14 +328,10 @@ export const ItemsMixin = (superClass) =>
|
|
|
317
328
|
const menu = e.target;
|
|
318
329
|
const selectedItem = e.detail.value;
|
|
319
330
|
const index = menu.items.indexOf(selectedItem);
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
menu._listBox._observer.flush();
|
|
325
|
-
|
|
326
|
-
const newItem = menu._listBox.children[index];
|
|
327
|
-
newItem.focus();
|
|
331
|
+
// Menu can be no longer opened if parent menu items changed
|
|
332
|
+
if (!!selectedItem.keepOpen && index > -1 && menu.opened) {
|
|
333
|
+
menu.__selectedIndex = index;
|
|
334
|
+
menu.requestContentUpdate();
|
|
328
335
|
} else if (!selectedItem.keepOpen) {
|
|
329
336
|
this.close();
|
|
330
337
|
}
|
|
@@ -365,7 +372,7 @@ export const ItemsMixin = (superClass) =>
|
|
|
365
372
|
const { children } = item._item;
|
|
366
373
|
|
|
367
374
|
// Check if the sub-menu was focused before closing it.
|
|
368
|
-
const child = subMenu._overlayElement.
|
|
375
|
+
const child = subMenu._overlayElement._contentRoot.firstElementChild;
|
|
369
376
|
const isSubmenuFocused = child && child.focused;
|
|
370
377
|
|
|
371
378
|
if (subMenu.items !== children) {
|
|
@@ -391,24 +398,26 @@ export const ItemsMixin = (superClass) =>
|
|
|
391
398
|
}
|
|
392
399
|
}
|
|
393
400
|
|
|
401
|
+
/** @protected */
|
|
402
|
+
__getListBox() {
|
|
403
|
+
return this._overlayElement._contentRoot.querySelector(`${this._tagNamePrefix}-list-box`);
|
|
404
|
+
}
|
|
405
|
+
|
|
394
406
|
/**
|
|
395
407
|
* @param {!HTMLElement} root
|
|
396
408
|
* @param {!ContextMenu} menu
|
|
397
409
|
* @param {!ContextMenuRendererContext} context
|
|
398
410
|
* @protected
|
|
399
411
|
*/
|
|
400
|
-
__itemsRenderer(root, menu
|
|
412
|
+
__itemsRenderer(root, menu) {
|
|
401
413
|
this.__initMenu(root, menu);
|
|
402
414
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
const listBox = root.querySelector(`${this._tagNamePrefix}-list-box`);
|
|
407
|
-
listBox.innerHTML = '';
|
|
415
|
+
this._subMenu.closeOn = menu.closeOn;
|
|
416
|
+
this._listBox.innerHTML = '';
|
|
408
417
|
|
|
409
|
-
|
|
418
|
+
menu.items.forEach((item) => {
|
|
410
419
|
const component = this.__createComponent(item);
|
|
411
|
-
|
|
420
|
+
this._listBox.appendChild(component);
|
|
412
421
|
});
|
|
413
422
|
}
|
|
414
423
|
|
|
@@ -449,8 +458,9 @@ export const ItemsMixin = (superClass) =>
|
|
|
449
458
|
root.appendChild(listBox);
|
|
450
459
|
|
|
451
460
|
const subMenu = this.__initSubMenu();
|
|
461
|
+
subMenu.slot = 'submenu';
|
|
452
462
|
this._subMenu = subMenu;
|
|
453
|
-
|
|
463
|
+
this.appendChild(subMenu);
|
|
454
464
|
|
|
455
465
|
requestAnimationFrame(() => {
|
|
456
466
|
this.__openListenerActive = true;
|
|
@@ -18,9 +18,4 @@ export declare class MenuOverlayMixinClass {
|
|
|
18
18
|
* Returns the adjusted boundaries of the overlay.
|
|
19
19
|
*/
|
|
20
20
|
getBoundaries(): { xMax: number; xMin: number; yMax: number };
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Returns the first element in the overlay content.
|
|
24
|
-
*/
|
|
25
|
-
getFirstChild(): HTMLElement;
|
|
26
21
|
}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Copyright (c) 2016 - 2025 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import { getClosestElement } from '@vaadin/component-base/src/dom-utils.js';
|
|
7
6
|
import { OverlayFocusMixin } from '@vaadin/overlay/src/vaadin-overlay-focus-mixin.js';
|
|
8
7
|
import { PositionMixin } from '@vaadin/overlay/src/vaadin-overlay-position-mixin.js';
|
|
9
8
|
|
|
@@ -37,6 +36,23 @@ export const MenuOverlayMixin = (superClass) =>
|
|
|
37
36
|
return ['_themeChanged(_theme)'];
|
|
38
37
|
}
|
|
39
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Override method from OverlayFocusMixin to use slotted div as the content root.
|
|
41
|
+
* @protected
|
|
42
|
+
* @override
|
|
43
|
+
*/
|
|
44
|
+
get _contentRoot() {
|
|
45
|
+
if (!this.__savedRoot) {
|
|
46
|
+
const root = document.createElement('div');
|
|
47
|
+
root.setAttribute('slot', 'overlay');
|
|
48
|
+
root.style.display = 'contents';
|
|
49
|
+
this.owner.appendChild(root);
|
|
50
|
+
this.__savedRoot = root;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return this.__savedRoot;
|
|
54
|
+
}
|
|
55
|
+
|
|
40
56
|
/** @protected */
|
|
41
57
|
ready() {
|
|
42
58
|
super.ready();
|
|
@@ -45,7 +61,7 @@ export const MenuOverlayMixin = (superClass) =>
|
|
|
45
61
|
|
|
46
62
|
this.addEventListener('keydown', (e) => {
|
|
47
63
|
if (!e.defaultPrevented && e.composedPath()[0] === this.$.overlay && [38, 40].indexOf(e.keyCode) > -1) {
|
|
48
|
-
const child = this.
|
|
64
|
+
const child = this._contentRoot.firstElementChild;
|
|
49
65
|
if (child && Array.isArray(child.items) && child.items.length) {
|
|
50
66
|
e.preventDefault();
|
|
51
67
|
if (e.keyCode === 38) {
|
|
@@ -58,15 +74,6 @@ export const MenuOverlayMixin = (superClass) =>
|
|
|
58
74
|
});
|
|
59
75
|
}
|
|
60
76
|
|
|
61
|
-
/**
|
|
62
|
-
* Returns the first element in the overlay content.
|
|
63
|
-
*
|
|
64
|
-
* @returns {HTMLElement}
|
|
65
|
-
*/
|
|
66
|
-
getFirstChild() {
|
|
67
|
-
return this.querySelector(':not(style):not(slot)');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
77
|
/** @private */
|
|
71
78
|
_themeChanged() {
|
|
72
79
|
this.close();
|
|
@@ -149,9 +156,9 @@ export const MenuOverlayMixin = (superClass) =>
|
|
|
149
156
|
}
|
|
150
157
|
|
|
151
158
|
/**
|
|
152
|
-
* Override method inherited from `OverlayFocusMixin` to
|
|
153
|
-
*
|
|
154
|
-
*
|
|
159
|
+
* Override method inherited from `OverlayFocusMixin` to check if the
|
|
160
|
+
* node is contained within the overlay's owner element (the menu),
|
|
161
|
+
* where all content (overlay content, sub-menus, etc.) is slotted.
|
|
155
162
|
*
|
|
156
163
|
* @protected
|
|
157
164
|
* @override
|
|
@@ -159,18 +166,6 @@ export const MenuOverlayMixin = (superClass) =>
|
|
|
159
166
|
* @return {boolean}
|
|
160
167
|
*/
|
|
161
168
|
_deepContains(node) {
|
|
162
|
-
|
|
163
|
-
let overlay = getClosestElement(this.localName, node);
|
|
164
|
-
while (overlay) {
|
|
165
|
-
if (overlay === this) {
|
|
166
|
-
// The node is inside a descendant menu overlay.
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Traverse the overlay hierarchy to check parent overlays.
|
|
171
|
-
overlay = overlay.parentOverlay;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return false;
|
|
169
|
+
return this.owner.contains(node);
|
|
175
170
|
}
|
|
176
171
|
};
|
package/web-types.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/web-types",
|
|
3
3
|
"name": "@vaadin/context-menu",
|
|
4
|
-
"version": "25.0.0-
|
|
4
|
+
"version": "25.0.0-alpha10",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"contributions": {
|
|
7
7
|
"html": {
|
|
8
8
|
"elements": [
|
|
9
9
|
{
|
|
10
10
|
"name": "vaadin-context-menu",
|
|
11
|
-
"description": "`<vaadin-context-menu>` is a Web Component for creating context menus.\n\n### Items\n\nItems is a higher level convenience API for defining a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nWhen an item is selected, `<vaadin-context-menu>` dispatches an \"item-selected\" event\nwith the selected item as `event.detail.value` property.\nIf item does not have `keepOpen` property the menu will be closed.\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n\ncontextMenu.addEventListener('item-selected', e => {\n const item = e.detail.value;\n console.log(`${item.text} selected`);\n});\n```\n\n**NOTE:** when the `items` array is defined, the renderer cannot be used.\n\n### Rendering\n\nThe content of the menu can be populated by using the renderer callback function.\n\nThe renderer function provides `root`, `contextMenu`, `model` arguments when applicable.\nGenerate DOM content by using `model` object properties if needed, append it to the `root`\nelement and control the state of the host element by accessing `contextMenu`. Before generating\nnew content, the renderer function should check if there is already content in `root` for reusing it.\n\n```html\n<vaadin-context-menu id=\"contextMenu\">\n <p>This paragraph has a context menu.</p>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'Content of the selector: ' + context.target.textContent;\n};\n```\n\nYou can access the menu context inside the renderer using\n`context.target` and `context.detail`.\n\nRenderer is called on the opening of the context-menu and each time the related context is updated.\nDOM generated during the renderer call can be reused\nin the next renderer call and will be provided with the `root` argument.\nOn first call it will be empty.\n\n### `vaadin-contextmenu` Gesture Event\n\n`vaadin-contextmenu` is a gesture event (a custom event),\nwhich is dispatched after either `contextmenu` or long touch events.\nThis enables support for both mouse and touch environments in a uniform way.\n\n`<vaadin-context-menu>` opens the menu overlay on the `vaadin-contextmenu`\nevent by default.\n\n### Menu Listener\n\nBy default, the `<vaadin-context-menu>` element listens for the menu opening\nevent on itself. In case if you do not want to wrap the target, you can listen for\nevents on an element outside the `<vaadin-context-menu>` by setting the\n`listenOn` property:\n\n```html\n<vaadin-context-menu id=\"contextMenu\"></vaadin-context-menu>\n\n<div id=\"menuListener\">The element that listens for the contextmenu event.</div>\n```\n```javascript\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.listenOn = document.querySelector('#menuListener');\n```\n\n### Filtering Menu Targets\n\nBy default, the listener element and all its descendants open the context\nmenu. You can filter the menu targets to a smaller set of elements inside\nthe listener element by setting the `selector` property.\n\nIn the following example, only the elements matching `.has-menu` will open the context menu:\n\n```html\n<vaadin-context-menu selector=\".has-menu\">\n <p class=\"has-menu\">This paragraph opens the context menu</p>\n <p>This paragraph does not open the context menu</p>\n</vaadin-context-menu>\n```\n\n### Menu Context\n\nThe following properties are available in the `context` argument:\n\n- `target` is the menu opening event target, which is the element that\nthe user has called the context menu for\n- `detail` is the menu opening event detail\n\nIn the following example, the menu item text is composed with the contents\nof the element that opened the menu:\n\n```html\n<vaadin-context-menu selector=\"li\" id=\"contextMenu\">\n <ul>\n <li>Foo</li>\n <li>Bar</li>\n <li>Baz</li>\n </ul>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'The menu target: ' + context.target.textContent;\n};\n```\n\n### Styling\n\
|
|
11
|
+
"description": "`<vaadin-context-menu>` is a Web Component for creating context menus.\n\n### Items\n\nItems is a higher level convenience API for defining a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nWhen an item is selected, `<vaadin-context-menu>` dispatches an \"item-selected\" event\nwith the selected item as `event.detail.value` property.\nIf item does not have `keepOpen` property the menu will be closed.\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n\ncontextMenu.addEventListener('item-selected', e => {\n const item = e.detail.value;\n console.log(`${item.text} selected`);\n});\n```\n\n**NOTE:** when the `items` array is defined, the renderer cannot be used.\n\n### Rendering\n\nThe content of the menu can be populated by using the renderer callback function.\n\nThe renderer function provides `root`, `contextMenu`, `model` arguments when applicable.\nGenerate DOM content by using `model` object properties if needed, append it to the `root`\nelement and control the state of the host element by accessing `contextMenu`. Before generating\nnew content, the renderer function should check if there is already content in `root` for reusing it.\n\n```html\n<vaadin-context-menu id=\"contextMenu\">\n <p>This paragraph has a context menu.</p>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'Content of the selector: ' + context.target.textContent;\n};\n```\n\nYou can access the menu context inside the renderer using\n`context.target` and `context.detail`.\n\nRenderer is called on the opening of the context-menu and each time the related context is updated.\nDOM generated during the renderer call can be reused\nin the next renderer call and will be provided with the `root` argument.\nOn first call it will be empty.\n\n### `vaadin-contextmenu` Gesture Event\n\n`vaadin-contextmenu` is a gesture event (a custom event),\nwhich is dispatched after either `contextmenu` or long touch events.\nThis enables support for both mouse and touch environments in a uniform way.\n\n`<vaadin-context-menu>` opens the menu overlay on the `vaadin-contextmenu`\nevent by default.\n\n### Menu Listener\n\nBy default, the `<vaadin-context-menu>` element listens for the menu opening\nevent on itself. In case if you do not want to wrap the target, you can listen for\nevents on an element outside the `<vaadin-context-menu>` by setting the\n`listenOn` property:\n\n```html\n<vaadin-context-menu id=\"contextMenu\"></vaadin-context-menu>\n\n<div id=\"menuListener\">The element that listens for the contextmenu event.</div>\n```\n```javascript\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.listenOn = document.querySelector('#menuListener');\n```\n\n### Filtering Menu Targets\n\nBy default, the listener element and all its descendants open the context\nmenu. You can filter the menu targets to a smaller set of elements inside\nthe listener element by setting the `selector` property.\n\nIn the following example, only the elements matching `.has-menu` will open the context menu:\n\n```html\n<vaadin-context-menu selector=\".has-menu\">\n <p class=\"has-menu\">This paragraph opens the context menu</p>\n <p>This paragraph does not open the context menu</p>\n</vaadin-context-menu>\n```\n\n### Menu Context\n\nThe following properties are available in the `context` argument:\n\n- `target` is the menu opening event target, which is the element that\nthe user has called the context menu for\n- `detail` is the menu opening event detail\n\nIn the following example, the menu item text is composed with the contents\nof the element that opened the menu:\n\n```html\n<vaadin-context-menu selector=\"li\" id=\"contextMenu\">\n <ul>\n <li>Foo</li>\n <li>Bar</li>\n <li>Baz</li>\n </ul>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'The menu target: ' + context.target.textContent;\n};\n```\n\n### Styling\n\nThe following shadow DOM parts are available for styling:\n\nPart name | Description\n-----------------|-------------------------------------------\n`backdrop` | Backdrop of the overlay\n`overlay` | The overlay container\n`content` | The overlay content\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.\n\n### Internal components\n\nWhen using `items` API the following internal components are themable:\n\n- `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/25.0.0-alpha10/#/elements/vaadin-item).\n- `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/25.0.0-alpha10/#/elements/vaadin-list-box).\n\nThe `<vaadin-context-menu-item>` sub-menu elements have the following additional state attributes\non top of the built-in `<vaadin-item>` state attributes:\n\nAttribute | Description\n---------- |-------------\n`expanded` | Expanded parent item.\n\nNote: the `theme` attribute value set on `<vaadin-context-menu>` is\npropagated to the internal components listed above.",
|
|
12
12
|
"attributes": [
|
|
13
13
|
{
|
|
14
14
|
"name": "selector",
|
|
@@ -135,6 +135,10 @@
|
|
|
135
135
|
}
|
|
136
136
|
],
|
|
137
137
|
"events": [
|
|
138
|
+
{
|
|
139
|
+
"name": "closed",
|
|
140
|
+
"description": "Fired when the context menu is closed."
|
|
141
|
+
},
|
|
138
142
|
{
|
|
139
143
|
"name": "item-selected",
|
|
140
144
|
"description": "Fired when an item is selected when the context menu is populated using the `items` API."
|
package/web-types.lit.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/web-types",
|
|
3
3
|
"name": "@vaadin/context-menu",
|
|
4
|
-
"version": "25.0.0-
|
|
4
|
+
"version": "25.0.0-alpha10",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"framework": "lit",
|
|
7
7
|
"framework-config": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"elements": [
|
|
17
17
|
{
|
|
18
18
|
"name": "vaadin-context-menu",
|
|
19
|
-
"description": "`<vaadin-context-menu>` is a Web Component for creating context menus.\n\n### Items\n\nItems is a higher level convenience API for defining a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nWhen an item is selected, `<vaadin-context-menu>` dispatches an \"item-selected\" event\nwith the selected item as `event.detail.value` property.\nIf item does not have `keepOpen` property the menu will be closed.\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n\ncontextMenu.addEventListener('item-selected', e => {\n const item = e.detail.value;\n console.log(`${item.text} selected`);\n});\n```\n\n**NOTE:** when the `items` array is defined, the renderer cannot be used.\n\n### Rendering\n\nThe content of the menu can be populated by using the renderer callback function.\n\nThe renderer function provides `root`, `contextMenu`, `model` arguments when applicable.\nGenerate DOM content by using `model` object properties if needed, append it to the `root`\nelement and control the state of the host element by accessing `contextMenu`. Before generating\nnew content, the renderer function should check if there is already content in `root` for reusing it.\n\n```html\n<vaadin-context-menu id=\"contextMenu\">\n <p>This paragraph has a context menu.</p>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'Content of the selector: ' + context.target.textContent;\n};\n```\n\nYou can access the menu context inside the renderer using\n`context.target` and `context.detail`.\n\nRenderer is called on the opening of the context-menu and each time the related context is updated.\nDOM generated during the renderer call can be reused\nin the next renderer call and will be provided with the `root` argument.\nOn first call it will be empty.\n\n### `vaadin-contextmenu` Gesture Event\n\n`vaadin-contextmenu` is a gesture event (a custom event),\nwhich is dispatched after either `contextmenu` or long touch events.\nThis enables support for both mouse and touch environments in a uniform way.\n\n`<vaadin-context-menu>` opens the menu overlay on the `vaadin-contextmenu`\nevent by default.\n\n### Menu Listener\n\nBy default, the `<vaadin-context-menu>` element listens for the menu opening\nevent on itself. In case if you do not want to wrap the target, you can listen for\nevents on an element outside the `<vaadin-context-menu>` by setting the\n`listenOn` property:\n\n```html\n<vaadin-context-menu id=\"contextMenu\"></vaadin-context-menu>\n\n<div id=\"menuListener\">The element that listens for the contextmenu event.</div>\n```\n```javascript\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.listenOn = document.querySelector('#menuListener');\n```\n\n### Filtering Menu Targets\n\nBy default, the listener element and all its descendants open the context\nmenu. You can filter the menu targets to a smaller set of elements inside\nthe listener element by setting the `selector` property.\n\nIn the following example, only the elements matching `.has-menu` will open the context menu:\n\n```html\n<vaadin-context-menu selector=\".has-menu\">\n <p class=\"has-menu\">This paragraph opens the context menu</p>\n <p>This paragraph does not open the context menu</p>\n</vaadin-context-menu>\n```\n\n### Menu Context\n\nThe following properties are available in the `context` argument:\n\n- `target` is the menu opening event target, which is the element that\nthe user has called the context menu for\n- `detail` is the menu opening event detail\n\nIn the following example, the menu item text is composed with the contents\nof the element that opened the menu:\n\n```html\n<vaadin-context-menu selector=\"li\" id=\"contextMenu\">\n <ul>\n <li>Foo</li>\n <li>Bar</li>\n <li>Baz</li>\n </ul>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'The menu target: ' + context.target.textContent;\n};\n```\n\n### Styling\n\
|
|
19
|
+
"description": "`<vaadin-context-menu>` is a Web Component for creating context menus.\n\n### Items\n\nItems is a higher level convenience API for defining a (hierarchical) menu structure for the component.\nIf a menu item has a non-empty `children` set, a sub-menu with the child items is opened\nnext to the parent menu on mouseover, tap or a right arrow keypress.\n\nWhen an item is selected, `<vaadin-context-menu>` dispatches an \"item-selected\" event\nwith the selected item as `event.detail.value` property.\nIf item does not have `keepOpen` property the menu will be closed.\n\n```javascript\ncontextMenu.items = [\n { text: 'Menu Item 1', theme: 'primary', className: 'first', children:\n [\n { text: 'Menu Item 1-1', checked: true, keepOpen: true },\n { text: 'Menu Item 1-2' }\n ]\n },\n { component: 'hr' },\n { text: 'Menu Item 2', children:\n [\n { text: 'Menu Item 2-1' },\n { text: 'Menu Item 2-2', disabled: true }\n ]\n },\n { text: 'Menu Item 3', disabled: true, className: 'last' }\n];\n\ncontextMenu.addEventListener('item-selected', e => {\n const item = e.detail.value;\n console.log(`${item.text} selected`);\n});\n```\n\n**NOTE:** when the `items` array is defined, the renderer cannot be used.\n\n### Rendering\n\nThe content of the menu can be populated by using the renderer callback function.\n\nThe renderer function provides `root`, `contextMenu`, `model` arguments when applicable.\nGenerate DOM content by using `model` object properties if needed, append it to the `root`\nelement and control the state of the host element by accessing `contextMenu`. Before generating\nnew content, the renderer function should check if there is already content in `root` for reusing it.\n\n```html\n<vaadin-context-menu id=\"contextMenu\">\n <p>This paragraph has a context menu.</p>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'Content of the selector: ' + context.target.textContent;\n};\n```\n\nYou can access the menu context inside the renderer using\n`context.target` and `context.detail`.\n\nRenderer is called on the opening of the context-menu and each time the related context is updated.\nDOM generated during the renderer call can be reused\nin the next renderer call and will be provided with the `root` argument.\nOn first call it will be empty.\n\n### `vaadin-contextmenu` Gesture Event\n\n`vaadin-contextmenu` is a gesture event (a custom event),\nwhich is dispatched after either `contextmenu` or long touch events.\nThis enables support for both mouse and touch environments in a uniform way.\n\n`<vaadin-context-menu>` opens the menu overlay on the `vaadin-contextmenu`\nevent by default.\n\n### Menu Listener\n\nBy default, the `<vaadin-context-menu>` element listens for the menu opening\nevent on itself. In case if you do not want to wrap the target, you can listen for\nevents on an element outside the `<vaadin-context-menu>` by setting the\n`listenOn` property:\n\n```html\n<vaadin-context-menu id=\"contextMenu\"></vaadin-context-menu>\n\n<div id=\"menuListener\">The element that listens for the contextmenu event.</div>\n```\n```javascript\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.listenOn = document.querySelector('#menuListener');\n```\n\n### Filtering Menu Targets\n\nBy default, the listener element and all its descendants open the context\nmenu. You can filter the menu targets to a smaller set of elements inside\nthe listener element by setting the `selector` property.\n\nIn the following example, only the elements matching `.has-menu` will open the context menu:\n\n```html\n<vaadin-context-menu selector=\".has-menu\">\n <p class=\"has-menu\">This paragraph opens the context menu</p>\n <p>This paragraph does not open the context menu</p>\n</vaadin-context-menu>\n```\n\n### Menu Context\n\nThe following properties are available in the `context` argument:\n\n- `target` is the menu opening event target, which is the element that\nthe user has called the context menu for\n- `detail` is the menu opening event detail\n\nIn the following example, the menu item text is composed with the contents\nof the element that opened the menu:\n\n```html\n<vaadin-context-menu selector=\"li\" id=\"contextMenu\">\n <ul>\n <li>Foo</li>\n <li>Bar</li>\n <li>Baz</li>\n </ul>\n</vaadin-context-menu>\n```\n```js\nconst contextMenu = document.querySelector('#contextMenu');\ncontextMenu.renderer = (root, contextMenu, context) => {\n let listBox = root.firstElementChild;\n if (!listBox) {\n listBox = document.createElement('vaadin-list-box');\n root.appendChild(listBox);\n }\n\n let item = listBox.querySelector('vaadin-item');\n if (!item) {\n item = document.createElement('vaadin-item');\n listBox.appendChild(item);\n }\n item.textContent = 'The menu target: ' + context.target.textContent;\n};\n```\n\n### Styling\n\nThe following shadow DOM parts are available for styling:\n\nPart name | Description\n-----------------|-------------------------------------------\n`backdrop` | Backdrop of the overlay\n`overlay` | The overlay container\n`content` | The overlay content\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.\n\n### Internal components\n\nWhen using `items` API the following internal components are themable:\n\n- `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/25.0.0-alpha10/#/elements/vaadin-item).\n- `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/25.0.0-alpha10/#/elements/vaadin-list-box).\n\nThe `<vaadin-context-menu-item>` sub-menu elements have the following additional state attributes\non top of the built-in `<vaadin-item>` state attributes:\n\nAttribute | Description\n---------- |-------------\n`expanded` | Expanded parent item.\n\nNote: the `theme` attribute value set on `<vaadin-context-menu>` is\npropagated to the internal components listed above.",
|
|
20
20
|
"extension": true,
|
|
21
21
|
"attributes": [
|
|
22
22
|
{
|
|
@@ -68,6 +68,13 @@
|
|
|
68
68
|
"kind": "expression"
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
|
+
{
|
|
72
|
+
"name": "@closed",
|
|
73
|
+
"description": "Fired when the context menu is closed.",
|
|
74
|
+
"value": {
|
|
75
|
+
"kind": "expression"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
71
78
|
{
|
|
72
79
|
"name": "@item-selected",
|
|
73
80
|
"description": "Fired when an item is selected when the context menu is populated using the `items` API.",
|