@vaadin/context-menu 25.3.0-alpha8 → 25.3.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.
- package/custom-elements.json +51 -5
- package/package.json +13 -13
- package/src/vaadin-context-menu-mixin.js +11 -3
- package/src/vaadin-context-menu-overlay.js +3 -1
- package/src/vaadin-context-menu.d.ts +8 -2
- package/src/vaadin-context-menu.js +3 -2
- package/src/vaadin-contextmenu-event.js +23 -0
- package/src/vaadin-contextmenu-items-mixin.js +8 -46
- package/src/vaadin-menu-overlay-mixin.js +28 -0
- package/web-types.json +4 -4
- package/web-types.lit.json +4 -4
package/custom-elements.json
CHANGED
|
@@ -468,6 +468,16 @@
|
|
|
468
468
|
"name": "ItemsMixin",
|
|
469
469
|
"module": "src/vaadin-contextmenu-items-mixin.js"
|
|
470
470
|
}
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
"name": "items-outside-click",
|
|
474
|
+
"type": {
|
|
475
|
+
"text": "CustomEvent"
|
|
476
|
+
},
|
|
477
|
+
"inheritedFrom": {
|
|
478
|
+
"name": "ItemsMixin",
|
|
479
|
+
"module": "src/vaadin-contextmenu-items-mixin.js"
|
|
480
|
+
}
|
|
471
481
|
}
|
|
472
482
|
],
|
|
473
483
|
"attributes": [
|
|
@@ -788,7 +798,7 @@
|
|
|
788
798
|
"type": {
|
|
789
799
|
"text": "CustomEvent"
|
|
790
800
|
},
|
|
791
|
-
"description": "Fired when all menus should close, e.g., after pressing Tab or on submenu close.",
|
|
801
|
+
"description": "Fired when all menus should close, e.g., after pressing Tab or on submenu close. This event is deprecated and will be removed in Vaadin 26. Use `closed` instead.",
|
|
792
802
|
"inheritedFrom": {
|
|
793
803
|
"name": "ItemsMixin",
|
|
794
804
|
"module": "src/vaadin-contextmenu-items-mixin.js"
|
|
@@ -817,11 +827,15 @@
|
|
|
817
827
|
}
|
|
818
828
|
},
|
|
819
829
|
{
|
|
830
|
+
"name": "items-outside-click",
|
|
820
831
|
"type": {
|
|
821
832
|
"text": "CustomEvent"
|
|
822
833
|
},
|
|
823
|
-
"description": "Fired when a click happens outside any open sub-menus.",
|
|
824
|
-
"
|
|
834
|
+
"description": "Fired when a click happens outside any open sub-menus. This event is deprecated and will be removed in Vaadin 26. Use `closed` instead.",
|
|
835
|
+
"inheritedFrom": {
|
|
836
|
+
"name": "ItemsMixin",
|
|
837
|
+
"module": "src/vaadin-contextmenu-items-mixin.js"
|
|
838
|
+
}
|
|
825
839
|
},
|
|
826
840
|
{
|
|
827
841
|
"type": {
|
|
@@ -995,6 +1009,12 @@
|
|
|
995
1009
|
"type": {
|
|
996
1010
|
"text": "CustomEvent"
|
|
997
1011
|
}
|
|
1012
|
+
},
|
|
1013
|
+
{
|
|
1014
|
+
"name": "items-outside-click",
|
|
1015
|
+
"type": {
|
|
1016
|
+
"text": "CustomEvent"
|
|
1017
|
+
}
|
|
998
1018
|
}
|
|
999
1019
|
],
|
|
1000
1020
|
"attributes": [],
|
|
@@ -1025,6 +1045,20 @@
|
|
|
1025
1045
|
"description": "",
|
|
1026
1046
|
"name": "MenuOverlayMixin",
|
|
1027
1047
|
"members": [
|
|
1048
|
+
{
|
|
1049
|
+
"kind": "field",
|
|
1050
|
+
"name": "autofocus",
|
|
1051
|
+
"privacy": "public",
|
|
1052
|
+
"type": {
|
|
1053
|
+
"text": "boolean"
|
|
1054
|
+
},
|
|
1055
|
+
"description": "Set to true to move focus into the overlay automatically on open.\n\nFocus moves to the first tabbable element in the tab order. This\ncan be the overlay itself if it has `tabindex` attribute set to `0`\non the host element or the `overlay` shadow DOM part.",
|
|
1056
|
+
"attribute": "autofocus",
|
|
1057
|
+
"inheritedFrom": {
|
|
1058
|
+
"name": "OverlayFocusMixin",
|
|
1059
|
+
"package": "@vaadin/overlay/src/vaadin-overlay-focus-mixin.js"
|
|
1060
|
+
}
|
|
1061
|
+
},
|
|
1028
1062
|
{
|
|
1029
1063
|
"kind": "field",
|
|
1030
1064
|
"name": "focusTrap",
|
|
@@ -1032,7 +1066,7 @@
|
|
|
1032
1066
|
"type": {
|
|
1033
1067
|
"text": "boolean"
|
|
1034
1068
|
},
|
|
1035
|
-
"description": "
|
|
1069
|
+
"description": "Set to true to move focus into the overlay automatically on open\nand keep it inside: Tab and Shift+Tab cycle through the overlay's\ncontent until the overlay is closed.\n\nFocus moves to the first tabbable element in the tab order. This\ncan be the overlay itself if it has `tabindex` attribute set to `0`\non the host element or the `overlay` shadow DOM part.",
|
|
1036
1070
|
"attribute": "focus-trap",
|
|
1037
1071
|
"inheritedFrom": {
|
|
1038
1072
|
"name": "OverlayFocusMixin",
|
|
@@ -1163,12 +1197,24 @@
|
|
|
1163
1197
|
}
|
|
1164
1198
|
],
|
|
1165
1199
|
"attributes": [
|
|
1200
|
+
{
|
|
1201
|
+
"name": "autofocus",
|
|
1202
|
+
"type": {
|
|
1203
|
+
"text": "boolean"
|
|
1204
|
+
},
|
|
1205
|
+
"description": "Set to true to move focus into the overlay automatically on open.\n\nFocus moves to the first tabbable element in the tab order. This\ncan be the overlay itself if it has `tabindex` attribute set to `0`\non the host element or the `overlay` shadow DOM part.",
|
|
1206
|
+
"fieldName": "autofocus",
|
|
1207
|
+
"inheritedFrom": {
|
|
1208
|
+
"name": "OverlayFocusMixin",
|
|
1209
|
+
"package": "@vaadin/overlay/src/vaadin-overlay-focus-mixin.js"
|
|
1210
|
+
}
|
|
1211
|
+
},
|
|
1166
1212
|
{
|
|
1167
1213
|
"name": "focus-trap",
|
|
1168
1214
|
"type": {
|
|
1169
1215
|
"text": "boolean"
|
|
1170
1216
|
},
|
|
1171
|
-
"description": "
|
|
1217
|
+
"description": "Set to true to move focus into the overlay automatically on open\nand keep it inside: Tab and Shift+Tab cycle through the overlay's\ncontent until the overlay is closed.\n\nFocus moves to the first tabbable element in the tab order. This\ncan be the overlay itself if it has `tabindex` attribute set to `0`\non the host element or the `overlay` shadow DOM part.",
|
|
1172
1218
|
"fieldName": "focusTrap",
|
|
1173
1219
|
"inheritedFrom": {
|
|
1174
1220
|
"name": "OverlayFocusMixin",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/context-menu",
|
|
3
|
-
"version": "25.3.0-
|
|
3
|
+
"version": "25.3.0-beta1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -37,21 +37,21 @@
|
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
40
|
-
"@vaadin/a11y-base": "25.3.0-
|
|
41
|
-
"@vaadin/component-base": "25.3.0-
|
|
42
|
-
"@vaadin/item": "25.3.0-
|
|
43
|
-
"@vaadin/list-box": "25.3.0-
|
|
44
|
-
"@vaadin/lit-renderer": "25.3.0-
|
|
45
|
-
"@vaadin/overlay": "25.3.0-
|
|
46
|
-
"@vaadin/vaadin-themable-mixin": "25.3.0-
|
|
40
|
+
"@vaadin/a11y-base": "25.3.0-beta1",
|
|
41
|
+
"@vaadin/component-base": "25.3.0-beta1",
|
|
42
|
+
"@vaadin/item": "25.3.0-beta1",
|
|
43
|
+
"@vaadin/list-box": "25.3.0-beta1",
|
|
44
|
+
"@vaadin/lit-renderer": "25.3.0-beta1",
|
|
45
|
+
"@vaadin/overlay": "25.3.0-beta1",
|
|
46
|
+
"@vaadin/vaadin-themable-mixin": "25.3.0-beta1",
|
|
47
47
|
"lit": "^3.0.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@vaadin/aura": "25.3.0-
|
|
51
|
-
"@vaadin/chai-plugins": "25.3.0-
|
|
52
|
-
"@vaadin/test-runner-commands": "25.3.0-
|
|
50
|
+
"@vaadin/aura": "25.3.0-beta1",
|
|
51
|
+
"@vaadin/chai-plugins": "25.3.0-beta1",
|
|
52
|
+
"@vaadin/test-runner-commands": "25.3.0-beta1",
|
|
53
53
|
"@vaadin/testing-helpers": "^2.0.0",
|
|
54
|
-
"@vaadin/vaadin-lumo-styles": "25.3.0-
|
|
54
|
+
"@vaadin/vaadin-lumo-styles": "25.3.0-beta1",
|
|
55
55
|
"sinon": "^22.0.0"
|
|
56
56
|
},
|
|
57
57
|
"customElements": "custom-elements.json",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"web-types.json",
|
|
60
60
|
"web-types.lit.json"
|
|
61
61
|
],
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "295432e44a6967e1aff36462b2e3e1d0e64eb8cc"
|
|
63
63
|
}
|
|
@@ -206,7 +206,8 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
206
206
|
);
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
//
|
|
209
|
+
// Clicks on items bubble to the overlay and must not close the menu
|
|
210
|
+
// (items with `keepOpen` or with children), so disable `closeOn`.
|
|
210
211
|
if (this.items && this.closeOn === 'click') {
|
|
211
212
|
this.closeOn = '';
|
|
212
213
|
}
|
|
@@ -224,9 +225,12 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
224
225
|
}
|
|
225
226
|
|
|
226
227
|
const opened = event.detail.value;
|
|
227
|
-
this._setOpened(opened);
|
|
228
228
|
if (opened) {
|
|
229
|
+
this._setOpened(true);
|
|
229
230
|
this.__alignOverlayPosition();
|
|
231
|
+
} else if (this.opened) {
|
|
232
|
+
// Use `close()` to also reset menu-bar button on outside click.
|
|
233
|
+
this.close();
|
|
230
234
|
}
|
|
231
235
|
}
|
|
232
236
|
|
|
@@ -315,7 +319,11 @@ export const ContextMenuMixin = (superClass) =>
|
|
|
315
319
|
|
|
316
320
|
/** @private */
|
|
317
321
|
_preventDefault(e) {
|
|
318
|
-
|
|
322
|
+
// With items, `closeOn` is cleared to not close the menu on clicks bubbling
|
|
323
|
+
// from the items to the overlay, and the menu still closes on outside click.
|
|
324
|
+
if (!this.items) {
|
|
325
|
+
e.preventDefault();
|
|
326
|
+
}
|
|
319
327
|
}
|
|
320
328
|
|
|
321
329
|
/** @private */
|
|
@@ -21,7 +21,7 @@ import { MenuOverlayMixin } from './vaadin-menu-overlay-mixin.js';
|
|
|
21
21
|
* @extends HTMLElement
|
|
22
22
|
* @protected
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
class ContextMenuOverlay extends MenuOverlayMixin(
|
|
25
25
|
OverlayMixin(DirMixin(ThemableMixin(PolylitMixin(LumoInjectionMixin(LitElement))))),
|
|
26
26
|
) {
|
|
27
27
|
static get is() {
|
|
@@ -105,3 +105,5 @@ export class ContextMenuOverlay extends MenuOverlayMixin(
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
defineCustomElement(ContextMenuOverlay);
|
|
108
|
+
|
|
109
|
+
export { ContextMenuOverlay };
|
|
@@ -57,8 +57,14 @@ export interface ContextMenuCustomEventMap<TItem extends ContextMenuItemData = C
|
|
|
57
57
|
|
|
58
58
|
'item-selected': ContextMenuItemSelectedEvent<TItem>;
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated This event is deprecated and will be removed in Vaadin 26. Use `closed` instead.
|
|
62
|
+
*/
|
|
60
63
|
'close-all-menus': Event;
|
|
61
64
|
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated This event is deprecated and will be removed in Vaadin 26. Use `closed` instead.
|
|
67
|
+
*/
|
|
62
68
|
'items-outside-click': Event;
|
|
63
69
|
|
|
64
70
|
closed: ContextMenuClosedEvent;
|
|
@@ -303,8 +309,8 @@ export interface ContextMenuEventMap<TItem extends ContextMenuItemData = Context
|
|
|
303
309
|
* @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
|
|
304
310
|
* @fires {CustomEvent} item-selected - Fired when an item is selected when the context menu is populated using the `items` API.
|
|
305
311
|
* @fires {CustomEvent} closed - Fired when the context menu is closed.
|
|
306
|
-
* @fires {CustomEvent} close-all-menus - Fired when all menus should close, e.g., after pressing Tab or on submenu close.
|
|
307
|
-
* @fires {CustomEvent} items-outside-click - Fired when a click happens outside any open sub-menus.
|
|
312
|
+
* @fires {CustomEvent} close-all-menus - Fired when all menus should close, e.g., after pressing Tab or on submenu close. This event is deprecated and will be removed in Vaadin 26. Use `closed` instead.
|
|
313
|
+
* @fires {CustomEvent} items-outside-click - Fired when a click happens outside any open sub-menus. This event is deprecated and will be removed in Vaadin 26. Use `closed` instead.
|
|
308
314
|
*/
|
|
309
315
|
declare class ContextMenu<TItem extends ContextMenuItemData = ContextMenuItemData> extends HTMLElement {
|
|
310
316
|
/**
|
|
@@ -251,8 +251,8 @@ import { ContextMenuMixin } from './vaadin-context-menu-mixin.js';
|
|
|
251
251
|
* @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
|
|
252
252
|
* @fires {CustomEvent} item-selected - Fired when an item is selected when the context menu is populated using the `items` API.
|
|
253
253
|
* @fires {CustomEvent} closed - Fired when the context menu is closed.
|
|
254
|
-
* @fires {CustomEvent} close-all-menus - Fired when all menus should close, e.g., after pressing Tab or on submenu close.
|
|
255
|
-
* @fires {CustomEvent} items-outside-click - Fired when a click happens outside any open sub-menus.
|
|
254
|
+
* @fires {CustomEvent} close-all-menus - Fired when all menus should close, e.g., after pressing Tab or on submenu close. This event is deprecated and will be removed in Vaadin 26. Use `closed` instead.
|
|
255
|
+
* @fires {CustomEvent} items-outside-click - Fired when a click happens outside any open sub-menus. This event is deprecated and will be removed in Vaadin 26. Use `closed` instead.
|
|
256
256
|
*
|
|
257
257
|
* @attr {string} theme - The theme variants to apply to the component.
|
|
258
258
|
* @customElement vaadin-context-menu
|
|
@@ -362,4 +362,5 @@ class ContextMenu extends ContextMenuMixin(ElementMixin(ThemePropertyMixin(Polyl
|
|
|
362
362
|
}
|
|
363
363
|
|
|
364
364
|
defineCustomElement(ContextMenu);
|
|
365
|
+
|
|
365
366
|
export { ContextMenu };
|
|
@@ -7,6 +7,11 @@ import { isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
|
|
|
7
7
|
import { isFirefox, isIOS } from '@vaadin/component-base/src/browser-utils.js';
|
|
8
8
|
import { prevent, register } from '@vaadin/component-base/src/gestures.js';
|
|
9
9
|
|
|
10
|
+
// A `contextmenu` caused by a selection change on touch focus (e.g. with `autoselect`) is
|
|
11
|
+
// dispatched in the same input turn as the tap, measured at ~80 ms after `touchstart`. A long
|
|
12
|
+
// press needs the finger held for 500 ms or more, which platform settings can shorten.
|
|
13
|
+
const SELECTION_CONTEXTMENU_MAX_DELAY = 200;
|
|
14
|
+
|
|
10
15
|
register({
|
|
11
16
|
name: 'vaadin-contextmenu',
|
|
12
17
|
deps: ['touchstart', 'touchmove', 'touchend', 'contextmenu'],
|
|
@@ -21,6 +26,10 @@ register({
|
|
|
21
26
|
sourceEvent: null,
|
|
22
27
|
},
|
|
23
28
|
|
|
29
|
+
// Deliberately not cleared in `reset()`: it runs when the `contextmenu` handling starts,
|
|
30
|
+
// which is exactly when this value is needed.
|
|
31
|
+
_touchStartTime: null,
|
|
32
|
+
|
|
24
33
|
reset() {
|
|
25
34
|
this.info.sourceEvent = null;
|
|
26
35
|
this._cancelTimer();
|
|
@@ -49,6 +58,8 @@ register({
|
|
|
49
58
|
touchstart(e) {
|
|
50
59
|
this._setSourceEvent(e);
|
|
51
60
|
|
|
61
|
+
this._touchStartTime = performance.now();
|
|
62
|
+
|
|
52
63
|
this.info.touchStartCoords = {
|
|
53
64
|
x: e.changedTouches[0].clientX,
|
|
54
65
|
y: e.changedTouches[0].clientY,
|
|
@@ -92,6 +103,18 @@ register({
|
|
|
92
103
|
},
|
|
93
104
|
|
|
94
105
|
contextmenu(e) {
|
|
106
|
+
// Ignore a `contextmenu` that fires too soon after `touchstart` to be a long press. On
|
|
107
|
+
// touch, changing the text selection on focus (e.g. with `autoselect`) makes the browser
|
|
108
|
+
// fire `contextmenu` as a side effect of the tap itself. Mouse and keyboard events do
|
|
109
|
+
// not follow a touch this closely in practice.
|
|
110
|
+
//
|
|
111
|
+
// Uses `performance.now()` rather than `e.timeStamp`: on Android, the `contextmenu` of a
|
|
112
|
+
// long press carries the timestamp of the touch that started it, so `e.timeStamp` would
|
|
113
|
+
// report no elapsed time and suppress every long press.
|
|
114
|
+
if (this._touchStartTime !== null && performance.now() - this._touchStartTime < SELECTION_CONTEXTMENU_MAX_DELAY) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
95
118
|
if (!e.shiftKey) {
|
|
96
119
|
this._setSourceEvent(e);
|
|
97
120
|
if (isFirefox && isKeyboardActive()) {
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
|
|
7
7
|
import { isTouch } from '@vaadin/component-base/src/browser-utils.js';
|
|
8
|
+
import { setOrRemoveAttribute } from '@vaadin/component-base/src/dom-utils.js';
|
|
8
9
|
|
|
9
10
|
export const ItemsMixin = (superClass) =>
|
|
10
11
|
class ItemsMixin extends superClass {
|
|
@@ -86,21 +87,6 @@ export const ItemsMixin = (superClass) =>
|
|
|
86
87
|
};
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
constructor() {
|
|
90
|
-
super();
|
|
91
|
-
|
|
92
|
-
// Overlay's outside click listener doesn't work with modeless
|
|
93
|
-
// overlays (submenus) so we need additional logic for it
|
|
94
|
-
this.__itemsOutsideClickListener = (e) => {
|
|
95
|
-
if (this._shouldCloseOnOutsideClick(e)) {
|
|
96
|
-
this.dispatchEvent(new CustomEvent('items-outside-click'));
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
this.addEventListener('items-outside-click', () => {
|
|
100
|
-
this.items && this.close();
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
90
|
/**
|
|
105
91
|
* Tag name prefix used by overlay, list-box and items.
|
|
106
92
|
* @protected
|
|
@@ -110,33 +96,12 @@ export const ItemsMixin = (superClass) =>
|
|
|
110
96
|
return 'vaadin-context-menu';
|
|
111
97
|
}
|
|
112
98
|
|
|
113
|
-
/** @protected */
|
|
114
|
-
connectedCallback() {
|
|
115
|
-
super.connectedCallback();
|
|
116
|
-
// Firefox leaks click to document on contextmenu even if prevented
|
|
117
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=990614
|
|
118
|
-
document.documentElement.addEventListener('click', this.__itemsOutsideClickListener);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
99
|
/** @protected */
|
|
122
100
|
disconnectedCallback() {
|
|
123
101
|
super.disconnectedCallback();
|
|
124
|
-
document.documentElement.removeEventListener('click', this.__itemsOutsideClickListener);
|
|
125
102
|
this._tooltipController.setTarget(null);
|
|
126
103
|
}
|
|
127
104
|
|
|
128
|
-
/**
|
|
129
|
-
* Whether to close the overlay on outside click or not.
|
|
130
|
-
* Override this method to customize the closing logic.
|
|
131
|
-
*
|
|
132
|
-
* @param {Event} event
|
|
133
|
-
* @return {boolean}
|
|
134
|
-
* @protected
|
|
135
|
-
*/
|
|
136
|
-
_shouldCloseOnOutsideClick(event) {
|
|
137
|
-
return !event.composedPath().some((el) => el.localName === `${this._tagNamePrefix}-overlay`);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
105
|
/** @protected */
|
|
141
106
|
__forwardFocus() {
|
|
142
107
|
const overlay = this._overlayElement;
|
|
@@ -165,11 +130,7 @@ export const ItemsMixin = (superClass) =>
|
|
|
165
130
|
subMenuOverlay._setParentOverlay(parent);
|
|
166
131
|
|
|
167
132
|
// Set theme attribute from parent element
|
|
168
|
-
|
|
169
|
-
subMenu.setAttribute('theme', parent.getAttribute('theme'));
|
|
170
|
-
} else {
|
|
171
|
-
subMenu.removeAttribute('theme');
|
|
172
|
-
}
|
|
133
|
+
setOrRemoveAttribute(subMenu, 'theme', parent.getAttribute('theme'));
|
|
173
134
|
|
|
174
135
|
const content = subMenuOverlay.$.content;
|
|
175
136
|
content.style.minWidth = '';
|
|
@@ -293,6 +254,11 @@ export const ItemsMixin = (superClass) =>
|
|
|
293
254
|
this.close();
|
|
294
255
|
});
|
|
295
256
|
|
|
257
|
+
// TODO: deprecated, fires for backwards compatibility. Remove in Vaadin 26
|
|
258
|
+
overlay.addEventListener('vaadin-overlay-outside-click', () => {
|
|
259
|
+
this.dispatchEvent(new CustomEvent('items-outside-click'));
|
|
260
|
+
});
|
|
261
|
+
|
|
296
262
|
// Open a submenu on click event when a touch device is used.
|
|
297
263
|
// On desktop, a submenu opens on hover.
|
|
298
264
|
overlay.addEventListener(isTouch ? 'click' : 'mouseover', (event) => {
|
|
@@ -547,11 +513,7 @@ export const ItemsMixin = (superClass) =>
|
|
|
547
513
|
|
|
548
514
|
/** @private */
|
|
549
515
|
__updateTheme(component, theme) {
|
|
550
|
-
|
|
551
|
-
component.setAttribute('theme', theme);
|
|
552
|
-
} else {
|
|
553
|
-
component.removeAttribute('theme');
|
|
554
|
-
}
|
|
516
|
+
setOrRemoveAttribute(component, 'theme', theme);
|
|
555
517
|
}
|
|
556
518
|
|
|
557
519
|
close() {
|
|
@@ -85,6 +85,34 @@ export const MenuOverlayMixin = (superClass) =>
|
|
|
85
85
|
this.close();
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Override method from `OverlayMixin` to close the menu from its root overlay.
|
|
90
|
+
*
|
|
91
|
+
* @param {Event} event
|
|
92
|
+
* @return {boolean}
|
|
93
|
+
* @protected
|
|
94
|
+
* @override
|
|
95
|
+
*/
|
|
96
|
+
_shouldCloseOnOutsideClick(event) {
|
|
97
|
+
// Only close the menu from its root overlay
|
|
98
|
+
if (this.parentOverlay) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Ignore clicks on nested menu items
|
|
103
|
+
if (event.composedPath().includes(this)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// With items, overlays above the root overlay belong to the menu itself,
|
|
108
|
+
// e.g. an open sub-menu or item tooltip, so ignore the overlay stack
|
|
109
|
+
if (this.owner.items) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return super._shouldCloseOnOutsideClick(event);
|
|
114
|
+
}
|
|
115
|
+
|
|
88
116
|
/**
|
|
89
117
|
* Returns the adjusted boundaries of the overlay.
|
|
90
118
|
*
|
package/web-types.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.3.0-
|
|
4
|
+
"version": "25.3.0-beta1",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"contributions": {
|
|
7
7
|
"html": {
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
},
|
|
130
130
|
{
|
|
131
131
|
"name": "vaadin-context-menu",
|
|
132
|
-
"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#### Disabled menu items\n\nWhen disabled, menu items are rendered as \"dimmed\".\n\nBy default, disabled items are not focusable and don't react to hover.\nAs a result, they are hidden from assistive technologies, and it's not\npossible to show a tooltip to explain why they are disabled. This can\nbe addressed by enabling the feature flag `accessibleDisabledMenuItems`,\nwhich makes disabled items focusable and hoverable, while still\npreventing them from being activated:\n\n```js\n// Set before any context menu is attached to the DOM.\nwindow.Vaadin.featureFlags.accessibleDisabledMenuItems = true;\n```\n\n#### Item tooltips\n\nMenu items can have tooltips that are shown on hover and keyboard\nfocus. To enable them, add a slotted `<vaadin-tooltip>` element\nand set the `tooltip` property on each item that should have one:\n\n```html\n<vaadin-context-menu>\n <vaadin-tooltip slot=\"tooltip\"></vaadin-tooltip>\n</vaadin-context-menu>\n```\n\n### Slotted list-box\n\nThe content of the menu can also be populated by providing a custom\n`<vaadin-context-menu-list-box>` with the `overlay` slot:\n\n```html\n<vaadin-context-menu>\n <vaadin-context-menu-list-box slot=\"overlay\">\n <vaadin-context-menu-item>Edit</vaadin-context-menu-item>\n <vaadin-context-menu-item>Delete</vaadin-context-menu-item>\n </vaadin-context-menu-list-box>\n</vaadin-context-menu>\n```\n\n**Note:** slotted list-box supports a single root-level menu only and\ncannot be combined with the `items` or `renderer` API.\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\n### Custom CSS Properties\n\nThe following custom CSS properties are available for styling:\n\nCustom CSS property | Description\n--------------------------------------|-------------\n`--vaadin-context-menu-offset-top` | Used as an offset when using `position` and the context menu is aligned vertically below the target\n`--vaadin-context-menu-offset-bottom` | Used as an offset when using `position` and the context menu is aligned vertically above the target\n`--vaadin-context-menu-offset-start` | Used as an offset when using `position` and the context menu is aligned horizontally after the target\n`--vaadin-context-menu-offset-end` | Used as an offset when using `position` and the context menu is aligned horizontally before the target\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.\n\n### Related components\n\nIn addition to `<vaadin-context-menu>` itself, the following components are themable:\n\n- [`<vaadin-context-menu-item>`](https://cdn.vaadin.com/vaadin-web-components/25.3.0-
|
|
132
|
+
"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#### Disabled menu items\n\nWhen disabled, menu items are rendered as \"dimmed\".\n\nBy default, disabled items are not focusable and don't react to hover.\nAs a result, they are hidden from assistive technologies, and it's not\npossible to show a tooltip to explain why they are disabled. This can\nbe addressed by enabling the feature flag `accessibleDisabledMenuItems`,\nwhich makes disabled items focusable and hoverable, while still\npreventing them from being activated:\n\n```js\n// Set before any context menu is attached to the DOM.\nwindow.Vaadin.featureFlags.accessibleDisabledMenuItems = true;\n```\n\n#### Item tooltips\n\nMenu items can have tooltips that are shown on hover and keyboard\nfocus. To enable them, add a slotted `<vaadin-tooltip>` element\nand set the `tooltip` property on each item that should have one:\n\n```html\n<vaadin-context-menu>\n <vaadin-tooltip slot=\"tooltip\"></vaadin-tooltip>\n</vaadin-context-menu>\n```\n\n### Slotted list-box\n\nThe content of the menu can also be populated by providing a custom\n`<vaadin-context-menu-list-box>` with the `overlay` slot:\n\n```html\n<vaadin-context-menu>\n <vaadin-context-menu-list-box slot=\"overlay\">\n <vaadin-context-menu-item>Edit</vaadin-context-menu-item>\n <vaadin-context-menu-item>Delete</vaadin-context-menu-item>\n </vaadin-context-menu-list-box>\n</vaadin-context-menu>\n```\n\n**Note:** slotted list-box supports a single root-level menu only and\ncannot be combined with the `items` or `renderer` API.\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\n### Custom CSS Properties\n\nThe following custom CSS properties are available for styling:\n\nCustom CSS property | Description\n--------------------------------------|-------------\n`--vaadin-context-menu-offset-top` | Used as an offset when using `position` and the context menu is aligned vertically below the target\n`--vaadin-context-menu-offset-bottom` | Used as an offset when using `position` and the context menu is aligned vertically above the target\n`--vaadin-context-menu-offset-start` | Used as an offset when using `position` and the context menu is aligned horizontally after the target\n`--vaadin-context-menu-offset-end` | Used as an offset when using `position` and the context menu is aligned horizontally before the target\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.\n\n### Related components\n\nIn addition to `<vaadin-context-menu>` itself, the following components are themable:\n\n- [`<vaadin-context-menu-item>`](https://cdn.vaadin.com/vaadin-web-components/25.3.0-beta1/#/elements/vaadin-context-menu-item) - an item element.\n- [`<vaadin-context-menu-list-box>`](https://cdn.vaadin.com/vaadin-web-components/25.3.0-beta1/#/elements/vaadin-context-menu-list-box) - a list-box element.",
|
|
133
133
|
"attributes": [
|
|
134
134
|
{
|
|
135
135
|
"name": "close-on",
|
|
@@ -248,7 +248,7 @@
|
|
|
248
248
|
"events": [
|
|
249
249
|
{
|
|
250
250
|
"name": "close-all-menus",
|
|
251
|
-
"description": "Fired when all menus should close, e.g., after pressing Tab or on submenu close."
|
|
251
|
+
"description": "Fired when all menus should close, e.g., after pressing Tab or on submenu close. This event is deprecated and will be removed in Vaadin 26. Use `closed` instead."
|
|
252
252
|
},
|
|
253
253
|
{
|
|
254
254
|
"name": "closed",
|
|
@@ -260,7 +260,7 @@
|
|
|
260
260
|
},
|
|
261
261
|
{
|
|
262
262
|
"name": "items-outside-click",
|
|
263
|
-
"description": "Fired when a click happens outside any open sub-menus."
|
|
263
|
+
"description": "Fired when a click happens outside any open sub-menus. This event is deprecated and will be removed in Vaadin 26. Use `closed` instead."
|
|
264
264
|
},
|
|
265
265
|
{
|
|
266
266
|
"name": "opened-changed",
|
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.3.0-
|
|
4
|
+
"version": "25.3.0-beta1",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"framework": "lit",
|
|
7
7
|
"framework-config": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
"name": "vaadin-context-menu",
|
|
68
|
-
"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#### Disabled menu items\n\nWhen disabled, menu items are rendered as \"dimmed\".\n\nBy default, disabled items are not focusable and don't react to hover.\nAs a result, they are hidden from assistive technologies, and it's not\npossible to show a tooltip to explain why they are disabled. This can\nbe addressed by enabling the feature flag `accessibleDisabledMenuItems`,\nwhich makes disabled items focusable and hoverable, while still\npreventing them from being activated:\n\n```js\n// Set before any context menu is attached to the DOM.\nwindow.Vaadin.featureFlags.accessibleDisabledMenuItems = true;\n```\n\n#### Item tooltips\n\nMenu items can have tooltips that are shown on hover and keyboard\nfocus. To enable them, add a slotted `<vaadin-tooltip>` element\nand set the `tooltip` property on each item that should have one:\n\n```html\n<vaadin-context-menu>\n <vaadin-tooltip slot=\"tooltip\"></vaadin-tooltip>\n</vaadin-context-menu>\n```\n\n### Slotted list-box\n\nThe content of the menu can also be populated by providing a custom\n`<vaadin-context-menu-list-box>` with the `overlay` slot:\n\n```html\n<vaadin-context-menu>\n <vaadin-context-menu-list-box slot=\"overlay\">\n <vaadin-context-menu-item>Edit</vaadin-context-menu-item>\n <vaadin-context-menu-item>Delete</vaadin-context-menu-item>\n </vaadin-context-menu-list-box>\n</vaadin-context-menu>\n```\n\n**Note:** slotted list-box supports a single root-level menu only and\ncannot be combined with the `items` or `renderer` API.\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\n### Custom CSS Properties\n\nThe following custom CSS properties are available for styling:\n\nCustom CSS property | Description\n--------------------------------------|-------------\n`--vaadin-context-menu-offset-top` | Used as an offset when using `position` and the context menu is aligned vertically below the target\n`--vaadin-context-menu-offset-bottom` | Used as an offset when using `position` and the context menu is aligned vertically above the target\n`--vaadin-context-menu-offset-start` | Used as an offset when using `position` and the context menu is aligned horizontally after the target\n`--vaadin-context-menu-offset-end` | Used as an offset when using `position` and the context menu is aligned horizontally before the target\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.\n\n### Related components\n\nIn addition to `<vaadin-context-menu>` itself, the following components are themable:\n\n- [`<vaadin-context-menu-item>`](https://cdn.vaadin.com/vaadin-web-components/25.3.0-
|
|
68
|
+
"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#### Disabled menu items\n\nWhen disabled, menu items are rendered as \"dimmed\".\n\nBy default, disabled items are not focusable and don't react to hover.\nAs a result, they are hidden from assistive technologies, and it's not\npossible to show a tooltip to explain why they are disabled. This can\nbe addressed by enabling the feature flag `accessibleDisabledMenuItems`,\nwhich makes disabled items focusable and hoverable, while still\npreventing them from being activated:\n\n```js\n// Set before any context menu is attached to the DOM.\nwindow.Vaadin.featureFlags.accessibleDisabledMenuItems = true;\n```\n\n#### Item tooltips\n\nMenu items can have tooltips that are shown on hover and keyboard\nfocus. To enable them, add a slotted `<vaadin-tooltip>` element\nand set the `tooltip` property on each item that should have one:\n\n```html\n<vaadin-context-menu>\n <vaadin-tooltip slot=\"tooltip\"></vaadin-tooltip>\n</vaadin-context-menu>\n```\n\n### Slotted list-box\n\nThe content of the menu can also be populated by providing a custom\n`<vaadin-context-menu-list-box>` with the `overlay` slot:\n\n```html\n<vaadin-context-menu>\n <vaadin-context-menu-list-box slot=\"overlay\">\n <vaadin-context-menu-item>Edit</vaadin-context-menu-item>\n <vaadin-context-menu-item>Delete</vaadin-context-menu-item>\n </vaadin-context-menu-list-box>\n</vaadin-context-menu>\n```\n\n**Note:** slotted list-box supports a single root-level menu only and\ncannot be combined with the `items` or `renderer` API.\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\n### Custom CSS Properties\n\nThe following custom CSS properties are available for styling:\n\nCustom CSS property | Description\n--------------------------------------|-------------\n`--vaadin-context-menu-offset-top` | Used as an offset when using `position` and the context menu is aligned vertically below the target\n`--vaadin-context-menu-offset-bottom` | Used as an offset when using `position` and the context menu is aligned vertically above the target\n`--vaadin-context-menu-offset-start` | Used as an offset when using `position` and the context menu is aligned horizontally after the target\n`--vaadin-context-menu-offset-end` | Used as an offset when using `position` and the context menu is aligned horizontally before the target\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.\n\n### Related components\n\nIn addition to `<vaadin-context-menu>` itself, the following components are themable:\n\n- [`<vaadin-context-menu-item>`](https://cdn.vaadin.com/vaadin-web-components/25.3.0-beta1/#/elements/vaadin-context-menu-item) - an item element.\n- [`<vaadin-context-menu-list-box>`](https://cdn.vaadin.com/vaadin-web-components/25.3.0-beta1/#/elements/vaadin-context-menu-list-box) - a list-box element.",
|
|
69
69
|
"extension": true,
|
|
70
70
|
"attributes": [
|
|
71
71
|
{
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
},
|
|
120
120
|
{
|
|
121
121
|
"name": "@close-all-menus",
|
|
122
|
-
"description": "Fired when all menus should close, e.g., after pressing Tab or on submenu close.",
|
|
122
|
+
"description": "Fired when all menus should close, e.g., after pressing Tab or on submenu close. This event is deprecated and will be removed in Vaadin 26. Use `closed` instead.",
|
|
123
123
|
"value": {
|
|
124
124
|
"kind": "expression"
|
|
125
125
|
}
|
|
@@ -140,7 +140,7 @@
|
|
|
140
140
|
},
|
|
141
141
|
{
|
|
142
142
|
"name": "@items-outside-click",
|
|
143
|
-
"description": "Fired when a click happens outside any open sub-menus.",
|
|
143
|
+
"description": "Fired when a click happens outside any open sub-menus. This event is deprecated and will be removed in Vaadin 26. Use `closed` instead.",
|
|
144
144
|
"value": {
|
|
145
145
|
"kind": "expression"
|
|
146
146
|
}
|