@vaadin/context-menu 24.0.0-alpha8 → 24.0.0-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -11
- package/src/vaadin-context-menu-item.d.ts +21 -0
- package/src/vaadin-context-menu-item.js +53 -0
- package/src/vaadin-context-menu-list-box.d.ts +22 -0
- package/src/vaadin-context-menu-list-box.js +81 -0
- package/src/vaadin-context-menu-overlay.d.ts +20 -0
- package/src/vaadin-context-menu-overlay.js +6 -117
- package/src/vaadin-context-menu.d.ts +11 -10
- package/src/vaadin-context-menu.js +29 -27
- package/src/vaadin-contextmenu-items-mixin.d.ts +15 -31
- package/src/vaadin-contextmenu-items-mixin.js +31 -45
- package/src/vaadin-menu-overlay-mixin.d.ts +25 -0
- package/src/vaadin-menu-overlay-mixin.js +119 -0
- package/src/vaadin-menu-overlay-styles.d.ts +8 -0
- package/src/vaadin-menu-overlay-styles.js +26 -0
- package/theme/lumo/vaadin-context-menu-item-styles.js +46 -0
- package/theme/lumo/vaadin-context-menu-list-box-styles.js +47 -0
- package/theme/lumo/vaadin-context-menu-overlay-styles.js +33 -0
- package/theme/lumo/vaadin-context-menu.js +3 -3
- package/theme/material/vaadin-context-menu-item-styles.js +36 -0
- package/theme/material/vaadin-context-menu-list-box-styles.js +38 -0
- package/theme/material/vaadin-context-menu-overlay-styles.js +15 -0
- package/theme/material/vaadin-context-menu.js +3 -3
- package/web-types.json +24 -2
- package/web-types.lit.json +9 -2
- package/theme/lumo/vaadin-context-menu-styles.js +0 -115
- package/theme/material/vaadin-context-menu-styles.js +0 -79
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/context-menu",
|
|
3
|
-
"version": "24.0.0-
|
|
3
|
+
"version": "24.0.0-beta1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -39,18 +39,18 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
41
41
|
"@polymer/polymer": "^3.0.0",
|
|
42
|
-
"@vaadin/component-base": "24.0.0-
|
|
43
|
-
"@vaadin/item": "24.0.0-
|
|
44
|
-
"@vaadin/list-box": "24.0.0-
|
|
45
|
-
"@vaadin/lit-renderer": "24.0.0-
|
|
46
|
-
"@vaadin/overlay": "24.0.0-
|
|
47
|
-
"@vaadin/vaadin-lumo-styles": "24.0.0-
|
|
48
|
-
"@vaadin/vaadin-material-styles": "24.0.0-
|
|
49
|
-
"@vaadin/vaadin-themable-mixin": "24.0.0-
|
|
42
|
+
"@vaadin/component-base": "24.0.0-beta1",
|
|
43
|
+
"@vaadin/item": "24.0.0-beta1",
|
|
44
|
+
"@vaadin/list-box": "24.0.0-beta1",
|
|
45
|
+
"@vaadin/lit-renderer": "24.0.0-beta1",
|
|
46
|
+
"@vaadin/overlay": "24.0.0-beta1",
|
|
47
|
+
"@vaadin/vaadin-lumo-styles": "24.0.0-beta1",
|
|
48
|
+
"@vaadin/vaadin-material-styles": "24.0.0-beta1",
|
|
49
|
+
"@vaadin/vaadin-themable-mixin": "24.0.0-beta1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@esm-bundle/chai": "^4.3.4",
|
|
53
|
-
"@vaadin/testing-helpers": "^0.
|
|
53
|
+
"@vaadin/testing-helpers": "^0.4.0",
|
|
54
54
|
"lit": "^2.0.0",
|
|
55
55
|
"sinon": "^13.0.2"
|
|
56
56
|
},
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"web-types.json",
|
|
59
59
|
"web-types.lit.json"
|
|
60
60
|
],
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "c5b48921a62482746df8e46994b37e1490fec27e"
|
|
62
62
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
7
|
+
import { ItemMixin } from '@vaadin/item/src/vaadin-item-mixin.js';
|
|
8
|
+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
12
|
+
*/
|
|
13
|
+
declare class ContextMenuItem extends ItemMixin(DirMixin(ThemableMixin(HTMLElement))) {}
|
|
14
|
+
|
|
15
|
+
declare global {
|
|
16
|
+
interface HTMLElementTagNameMap {
|
|
17
|
+
'vaadin-context-menu-item': ContextMenuItem;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { ContextMenuItem };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
7
|
+
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
8
|
+
import { ItemMixin } from '@vaadin/item/src/vaadin-item-mixin.js';
|
|
9
|
+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
13
|
+
*
|
|
14
|
+
* @extends HTMLElement
|
|
15
|
+
* @mixes DirMixin
|
|
16
|
+
* @mixes ItemMixin
|
|
17
|
+
* @mixes ThemableMixin
|
|
18
|
+
* @protected
|
|
19
|
+
*/
|
|
20
|
+
class ContextMenuItem extends ItemMixin(ThemableMixin(DirMixin(PolymerElement))) {
|
|
21
|
+
static get is() {
|
|
22
|
+
return 'vaadin-context-menu-item';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static get template() {
|
|
26
|
+
return html`
|
|
27
|
+
<style>
|
|
28
|
+
:host {
|
|
29
|
+
display: inline-block;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
:host([hidden]) {
|
|
33
|
+
display: none !important;
|
|
34
|
+
}
|
|
35
|
+
</style>
|
|
36
|
+
<span part="checkmark" aria-hidden="true"></span>
|
|
37
|
+
<div part="content">
|
|
38
|
+
<slot></slot>
|
|
39
|
+
</div>
|
|
40
|
+
`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @protected */
|
|
44
|
+
ready() {
|
|
45
|
+
super.ready();
|
|
46
|
+
|
|
47
|
+
this.setAttribute('role', 'menuitem');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
customElements.define(ContextMenuItem.is, ContextMenuItem);
|
|
52
|
+
|
|
53
|
+
export { ContextMenuItem };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
|
|
7
|
+
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
8
|
+
import { ListMixin } from '@vaadin/component-base/src/list-mixin.js';
|
|
9
|
+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
13
|
+
*/
|
|
14
|
+
declare class ContextMenuListBox extends ListMixin(DirMixin(ThemableMixin(ControllerMixin(HTMLElement)))) {}
|
|
15
|
+
|
|
16
|
+
declare global {
|
|
17
|
+
interface HTMLElementTagNameMap {
|
|
18
|
+
'vaadin-context-menu-list-box': ContextMenuListBox;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { ContextMenuListBox };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
7
|
+
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
|
|
8
|
+
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
9
|
+
import { ListMixin } from '@vaadin/component-base/src/list-mixin.js';
|
|
10
|
+
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
14
|
+
*
|
|
15
|
+
* @extends HTMLElement
|
|
16
|
+
* @mixes ControllerMixin
|
|
17
|
+
* @mixes DirMixin
|
|
18
|
+
* @mixes ListMixin
|
|
19
|
+
* @mixes ThemableMixin
|
|
20
|
+
* @protected
|
|
21
|
+
*/
|
|
22
|
+
class ContextMenuListBox extends ListMixin(ThemableMixin(DirMixin(ControllerMixin(PolymerElement)))) {
|
|
23
|
+
static get is() {
|
|
24
|
+
return 'vaadin-context-menu-list-box';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static get template() {
|
|
28
|
+
return html`
|
|
29
|
+
<style>
|
|
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
|
+
</style>
|
|
45
|
+
<div part="items">
|
|
46
|
+
<slot></slot>
|
|
47
|
+
</div>
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static get properties() {
|
|
52
|
+
return {
|
|
53
|
+
// We don't need to define this property since super default is vertical,
|
|
54
|
+
// but we don't want it to be modified, or be shown in the API docs.
|
|
55
|
+
/** @private */
|
|
56
|
+
orientation: {
|
|
57
|
+
readOnly: true,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @return {!HTMLElement}
|
|
64
|
+
* @protected
|
|
65
|
+
* @override
|
|
66
|
+
*/
|
|
67
|
+
get _scrollerElement() {
|
|
68
|
+
return this.shadowRoot.querySelector('[part="items"]');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @protected */
|
|
72
|
+
ready() {
|
|
73
|
+
super.ready();
|
|
74
|
+
|
|
75
|
+
this.setAttribute('role', 'menu');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
customElements.define(ContextMenuListBox.is, ContextMenuListBox);
|
|
80
|
+
|
|
81
|
+
export { ContextMenuListBox };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 - 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { Overlay } from '@vaadin/overlay/src/vaadin-overlay.js';
|
|
7
|
+
import { MenuOverlayMixin } from './vaadin-menu-overlay-mixin.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
11
|
+
*/
|
|
12
|
+
declare class ContextMenuOverlay extends MenuOverlayMixin(Overlay) {}
|
|
13
|
+
|
|
14
|
+
declare global {
|
|
15
|
+
interface HTMLElementTagNameMap {
|
|
16
|
+
'vaadin-context-menu-overlay': ContextMenuOverlay;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { ContextMenuOverlay };
|
|
@@ -4,134 +4,23 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { Overlay } from '@vaadin/overlay/src/vaadin-overlay.js';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
8
|
+
import { MenuOverlayMixin } from './vaadin-menu-overlay-mixin.js';
|
|
9
|
+
import { styles } from './vaadin-menu-overlay-styles.js';
|
|
9
10
|
|
|
10
|
-
registerStyles(
|
|
11
|
-
'vaadin-context-menu-overlay',
|
|
12
|
-
css`
|
|
13
|
-
:host {
|
|
14
|
-
align-items: flex-start;
|
|
15
|
-
justify-content: flex-start;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
:host([right-aligned]),
|
|
19
|
-
:host([end-aligned]) {
|
|
20
|
-
align-items: flex-end;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
:host([bottom-aligned]) {
|
|
24
|
-
justify-content: flex-end;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
[part='overlay'] {
|
|
28
|
-
background-color: #fff;
|
|
29
|
-
}
|
|
30
|
-
`,
|
|
31
|
-
{ moduleId: 'vaadin-context-menu-overlay-styles' },
|
|
32
|
-
);
|
|
11
|
+
registerStyles('vaadin-context-menu-overlay', styles, { moduleId: 'vaadin-context-menu-overlay-styles' });
|
|
33
12
|
|
|
34
13
|
/**
|
|
35
14
|
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
36
15
|
*
|
|
37
16
|
* @extends Overlay
|
|
17
|
+
* @mixes MenuOverlayMixin
|
|
38
18
|
* @protected
|
|
39
19
|
*/
|
|
40
|
-
class ContextMenuOverlay extends
|
|
20
|
+
export class ContextMenuOverlay extends MenuOverlayMixin(Overlay) {
|
|
41
21
|
static get is() {
|
|
42
22
|
return 'vaadin-context-menu-overlay';
|
|
43
23
|
}
|
|
44
|
-
|
|
45
|
-
static get properties() {
|
|
46
|
-
return {
|
|
47
|
-
/**
|
|
48
|
-
* @protected
|
|
49
|
-
*/
|
|
50
|
-
parentOverlay: {
|
|
51
|
-
type: Object,
|
|
52
|
-
readOnly: true,
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
static get observers() {
|
|
58
|
-
return ['_themeChanged(_theme)'];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
ready() {
|
|
62
|
-
super.ready();
|
|
63
|
-
|
|
64
|
-
this.addEventListener('keydown', (e) => {
|
|
65
|
-
if (!e.defaultPrevented && e.composedPath()[0] === this.$.overlay && [38, 40].indexOf(e.keyCode) > -1) {
|
|
66
|
-
const child = this.getFirstChild();
|
|
67
|
-
if (child && Array.isArray(child.items) && child.items.length) {
|
|
68
|
-
e.preventDefault();
|
|
69
|
-
if (e.keyCode === 38) {
|
|
70
|
-
child.items[child.items.length - 1].focus();
|
|
71
|
-
} else {
|
|
72
|
-
child.focus();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
getFirstChild() {
|
|
80
|
-
return this.querySelector(':not(style):not(slot)');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
_themeChanged() {
|
|
84
|
-
this.close();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
getBoundaries() {
|
|
88
|
-
// Measure actual overlay and content sizes
|
|
89
|
-
const overlayRect = this.getBoundingClientRect();
|
|
90
|
-
const contentRect = this.$.overlay.getBoundingClientRect();
|
|
91
|
-
|
|
92
|
-
// Maximum x and y values are imposed by content size and overlay limits.
|
|
93
|
-
let yMax = overlayRect.bottom - contentRect.height;
|
|
94
|
-
|
|
95
|
-
// Adjust constraints to ensure bottom-aligned applies to sub-menu.
|
|
96
|
-
const parent = this.parentOverlay;
|
|
97
|
-
if (parent && parent.hasAttribute('bottom-aligned')) {
|
|
98
|
-
const parentStyle = getComputedStyle(parent);
|
|
99
|
-
yMax = yMax - parseFloat(parentStyle.bottom) - parseFloat(parentStyle.height);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
xMax: overlayRect.right - contentRect.width,
|
|
104
|
-
xMin: overlayRect.left + contentRect.width,
|
|
105
|
-
yMax,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
_updatePosition() {
|
|
110
|
-
super._updatePosition();
|
|
111
|
-
|
|
112
|
-
if (this.positionTarget && this.parentOverlay) {
|
|
113
|
-
// This overlay is positioned by a parent menu item,
|
|
114
|
-
// adjust the position by the overlay content paddings
|
|
115
|
-
const content = this.$.content;
|
|
116
|
-
const style = getComputedStyle(content);
|
|
117
|
-
|
|
118
|
-
// Horizontal adjustment
|
|
119
|
-
const isLeftAligned = !!this.style.left;
|
|
120
|
-
if (isLeftAligned) {
|
|
121
|
-
this.style.left = `${parseFloat(this.style.left) + parseFloat(style.paddingLeft)}px`;
|
|
122
|
-
} else {
|
|
123
|
-
this.style.right = `${parseFloat(this.style.right) + parseFloat(style.paddingRight)}px`;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Vertical adjustment
|
|
127
|
-
const isBottomAligned = !!this.style.bottom;
|
|
128
|
-
if (isBottomAligned) {
|
|
129
|
-
this.style.bottom = `${parseFloat(this.style.bottom) - parseFloat(style.paddingBottom)}px`;
|
|
130
|
-
} else {
|
|
131
|
-
this.style.top = `${parseFloat(this.style.top) - parseFloat(style.paddingTop)}px`;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
24
|
}
|
|
136
25
|
|
|
137
26
|
customElements.define(ContextMenuOverlay.is, ContextMenuOverlay);
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
7
|
+
import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
|
|
7
8
|
import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
|
|
8
9
|
import { ContextMenuItem, ItemsMixin } from './vaadin-contextmenu-items-mixin.js';
|
|
9
10
|
|
|
@@ -56,20 +57,20 @@ export interface ContextMenuEventMap extends HTMLElementEventMap, ContextMenuCus
|
|
|
56
57
|
*
|
|
57
58
|
* ```javascript
|
|
58
59
|
* contextMenu.items = [
|
|
59
|
-
* {text: 'Menu Item 1', theme: 'primary', children:
|
|
60
|
+
* { text: 'Menu Item 1', theme: 'primary', children:
|
|
60
61
|
* [
|
|
61
|
-
* {text: 'Menu Item 1-1', checked: true},
|
|
62
|
-
* {text: 'Menu Item 1-2'}
|
|
62
|
+
* { text: 'Menu Item 1-1', checked: true },
|
|
63
|
+
* { text: 'Menu Item 1-2' }
|
|
63
64
|
* ]
|
|
64
65
|
* },
|
|
65
|
-
* {component: 'hr'},
|
|
66
|
-
* {text: 'Menu Item 2', children:
|
|
66
|
+
* { component: 'hr' },
|
|
67
|
+
* { text: 'Menu Item 2', children:
|
|
67
68
|
* [
|
|
68
|
-
* {text: 'Menu Item 2-1'},
|
|
69
|
-
* {text: 'Menu Item 2-2', disabled: true}
|
|
69
|
+
* { text: 'Menu Item 2-1' },
|
|
70
|
+
* { text: 'Menu Item 2-2', disabled: true }
|
|
70
71
|
* ]
|
|
71
72
|
* },
|
|
72
|
-
* {text: 'Menu Item 3', disabled: true}
|
|
73
|
+
* { text: 'Menu Item 3', disabled: true }
|
|
73
74
|
* ];
|
|
74
75
|
*
|
|
75
76
|
* contextMenu.addEventListener('item-selected', e => {
|
|
@@ -120,7 +121,7 @@ export interface ContextMenuEventMap extends HTMLElementEventMap, ContextMenuCus
|
|
|
120
121
|
* in the next renderer call and will be provided with the `root` argument.
|
|
121
122
|
* On first call it will be empty.
|
|
122
123
|
*
|
|
123
|
-
* ###
|
|
124
|
+
* ### `vaadin-contextmenu` Gesture Event
|
|
124
125
|
*
|
|
125
126
|
* `vaadin-contextmenu` is a gesture event (a custom event),
|
|
126
127
|
* which is dispatched after either `contextmenu` or long touch events.
|
|
@@ -223,7 +224,7 @@ export interface ContextMenuEventMap extends HTMLElementEventMap, ContextMenuCus
|
|
|
223
224
|
* @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
|
|
224
225
|
* @fires {CustomEvent} item-selected - Fired when an item is selected when the context menu is populated using the `items` API.
|
|
225
226
|
*/
|
|
226
|
-
declare class ContextMenu extends ElementMixin(ThemePropertyMixin(ItemsMixin(HTMLElement))) {
|
|
227
|
+
declare class ContextMenu extends OverlayClassMixin(ElementMixin(ThemePropertyMixin(ItemsMixin(HTMLElement)))) {
|
|
227
228
|
/**
|
|
228
229
|
* CSS selector that can be used to target any child element
|
|
229
230
|
* of the context menu to listen for `openOn` events.
|
|
@@ -11,6 +11,7 @@ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js'
|
|
|
11
11
|
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
12
12
|
import { addListener, gestures, removeListener } from '@vaadin/component-base/src/gestures.js';
|
|
13
13
|
import { MediaQueryController } from '@vaadin/component-base/src/media-query-controller.js';
|
|
14
|
+
import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
|
|
14
15
|
import { processTemplates } from '@vaadin/component-base/src/templates.js';
|
|
15
16
|
import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
|
|
16
17
|
import { ItemsMixin } from './vaadin-contextmenu-items-mixin.js';
|
|
@@ -29,20 +30,20 @@ import { ItemsMixin } from './vaadin-contextmenu-items-mixin.js';
|
|
|
29
30
|
*
|
|
30
31
|
* ```javascript
|
|
31
32
|
* contextMenu.items = [
|
|
32
|
-
* {text: 'Menu Item 1', theme: 'primary', children:
|
|
33
|
+
* { text: 'Menu Item 1', theme: 'primary', children:
|
|
33
34
|
* [
|
|
34
|
-
* {text: 'Menu Item 1-1', checked: true},
|
|
35
|
-
* {text: 'Menu Item 1-2'}
|
|
35
|
+
* { text: 'Menu Item 1-1', checked: true },
|
|
36
|
+
* { text: 'Menu Item 1-2' }
|
|
36
37
|
* ]
|
|
37
38
|
* },
|
|
38
|
-
* {component: 'hr'},
|
|
39
|
-
* {text: 'Menu Item 2', children:
|
|
39
|
+
* { component: 'hr' },
|
|
40
|
+
* { text: 'Menu Item 2', children:
|
|
40
41
|
* [
|
|
41
|
-
* {text: 'Menu Item 2-1'},
|
|
42
|
-
* {text: 'Menu Item 2-2', disabled: true}
|
|
42
|
+
* { text: 'Menu Item 2-1' },
|
|
43
|
+
* { text: 'Menu Item 2-2', disabled: true }
|
|
43
44
|
* ]
|
|
44
45
|
* },
|
|
45
|
-
* {text: 'Menu Item 3', disabled: true}
|
|
46
|
+
* { text: 'Menu Item 3', disabled: true }
|
|
46
47
|
* ];
|
|
47
48
|
*
|
|
48
49
|
* contextMenu.addEventListener('item-selected', e => {
|
|
@@ -93,7 +94,7 @@ import { ItemsMixin } from './vaadin-contextmenu-items-mixin.js';
|
|
|
93
94
|
* in the next renderer call and will be provided with the `root` argument.
|
|
94
95
|
* On first call it will be empty.
|
|
95
96
|
*
|
|
96
|
-
* ###
|
|
97
|
+
* ### `vaadin-contextmenu` Gesture Event
|
|
97
98
|
*
|
|
98
99
|
* `vaadin-contextmenu` is a gesture event (a custom event),
|
|
99
100
|
* which is dispatched after either `contextmenu` or long touch events.
|
|
@@ -199,10 +200,13 @@ import { ItemsMixin } from './vaadin-contextmenu-items-mixin.js';
|
|
|
199
200
|
* @extends HTMLElement
|
|
200
201
|
* @mixes ElementMixin
|
|
201
202
|
* @mixes ControllerMixin
|
|
203
|
+
* @mixes OverlayClassMixin
|
|
202
204
|
* @mixes ThemePropertyMixin
|
|
203
205
|
* @mixes ItemsMixin
|
|
204
206
|
*/
|
|
205
|
-
class ContextMenu extends
|
|
207
|
+
class ContextMenu extends OverlayClassMixin(
|
|
208
|
+
ControllerMixin(ElementMixin(ThemePropertyMixin(ItemsMixin(PolymerElement)))),
|
|
209
|
+
) {
|
|
206
210
|
static get template() {
|
|
207
211
|
return html`
|
|
208
212
|
<style>
|
|
@@ -308,12 +312,6 @@ class ContextMenu extends ControllerMixin(ElementMixin(ThemePropertyMixin(ItemsM
|
|
|
308
312
|
/** @private */
|
|
309
313
|
_context: Object,
|
|
310
314
|
|
|
311
|
-
/** @private */
|
|
312
|
-
_boundClose: Object,
|
|
313
|
-
|
|
314
|
-
/** @private */
|
|
315
|
-
_boundOpen: Object,
|
|
316
|
-
|
|
317
315
|
/** @private */
|
|
318
316
|
_phone: {
|
|
319
317
|
type: Boolean,
|
|
@@ -351,6 +349,7 @@ class ContextMenu extends ControllerMixin(ElementMixin(ThemePropertyMixin(ItemsM
|
|
|
351
349
|
super();
|
|
352
350
|
this._boundOpen = this.open.bind(this);
|
|
353
351
|
this._boundClose = this.close.bind(this);
|
|
352
|
+
this._boundPreventDefault = this._preventDefault.bind(this);
|
|
354
353
|
this._boundOnGlobalContextMenu = this._onGlobalContextMenu.bind(this);
|
|
355
354
|
}
|
|
356
355
|
|
|
@@ -374,6 +373,8 @@ class ContextMenu extends ControllerMixin(ElementMixin(ThemePropertyMixin(ItemsM
|
|
|
374
373
|
ready() {
|
|
375
374
|
super.ready();
|
|
376
375
|
|
|
376
|
+
this._overlayElement = this.$.overlay;
|
|
377
|
+
|
|
377
378
|
this.addController(
|
|
378
379
|
new MediaQueryController(this._wideMediaQuery, (matches) => {
|
|
379
380
|
this._wide = matches;
|
|
@@ -443,22 +444,19 @@ class ContextMenu extends ControllerMixin(ElementMixin(ThemePropertyMixin(ItemsM
|
|
|
443
444
|
|
|
444
445
|
/** @private */
|
|
445
446
|
_closeOnChanged(closeOn, oldCloseOn) {
|
|
446
|
-
// Listen on this.$.overlay.root to workaround issue on
|
|
447
|
-
// ShadyDOM polyfill: https://github.com/webcomponents/shadydom/issues/159
|
|
448
|
-
|
|
449
447
|
// Outside click event from overlay
|
|
450
448
|
const evtOverlay = 'vaadin-overlay-outside-click';
|
|
451
449
|
|
|
450
|
+
const overlay = this.$.overlay;
|
|
451
|
+
|
|
452
452
|
if (oldCloseOn) {
|
|
453
|
-
this._unlisten(
|
|
454
|
-
this._unlisten(this.$.overlay.root, oldCloseOn, this._boundClose);
|
|
453
|
+
this._unlisten(overlay, oldCloseOn, this._boundClose);
|
|
455
454
|
}
|
|
456
455
|
if (closeOn) {
|
|
457
|
-
this._listen(
|
|
458
|
-
|
|
459
|
-
this._unlisten(this.$.overlay, evtOverlay, this._preventDefault);
|
|
456
|
+
this._listen(overlay, closeOn, this._boundClose);
|
|
457
|
+
overlay.removeEventListener(evtOverlay, this._boundPreventDefault);
|
|
460
458
|
} else {
|
|
461
|
-
|
|
459
|
+
overlay.addEventListener(evtOverlay, this._boundPreventDefault);
|
|
462
460
|
}
|
|
463
461
|
}
|
|
464
462
|
|
|
@@ -488,7 +486,11 @@ class ContextMenu extends ControllerMixin(ElementMixin(ThemePropertyMixin(ItemsM
|
|
|
488
486
|
* It is not guaranteed that the update happens immediately (synchronously) after it is requested.
|
|
489
487
|
*/
|
|
490
488
|
requestContentUpdate() {
|
|
491
|
-
this
|
|
489
|
+
if (!this._overlayElement || !this.renderer) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
this._overlayElement.requestContentUpdate();
|
|
492
494
|
}
|
|
493
495
|
|
|
494
496
|
/** @private */
|
|
@@ -539,7 +541,7 @@ class ContextMenu extends ControllerMixin(ElementMixin(ThemePropertyMixin(ItemsM
|
|
|
539
541
|
};
|
|
540
542
|
|
|
541
543
|
if (this._context.target) {
|
|
542
|
-
|
|
544
|
+
e.preventDefault();
|
|
543
545
|
e.stopPropagation();
|
|
544
546
|
|
|
545
547
|
// Used in alignment which is delayed until overlay is rendered
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Copyright (c) 2016 - 2023 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
+
import './vaadin-context-menu-item.js';
|
|
7
|
+
import './vaadin-context-menu-list-box.js';
|
|
6
8
|
import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
7
|
-
import { Item } from '@vaadin/item/src/vaadin-item.js';
|
|
8
|
-
import { ListBox } from '@vaadin/list-box/src/vaadin-list-box.js';
|
|
9
9
|
|
|
10
10
|
export interface ContextMenuItem {
|
|
11
11
|
text?: string;
|
|
@@ -16,27 +16,6 @@ export interface ContextMenuItem {
|
|
|
16
16
|
children?: ContextMenuItem[];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
21
|
-
*
|
|
22
|
-
* @protected
|
|
23
|
-
*/
|
|
24
|
-
declare class ContextMenuItemElement extends Item {}
|
|
25
|
-
|
|
26
|
-
declare global {
|
|
27
|
-
interface HTMLElementTagNameMap {
|
|
28
|
-
'vaadin-context-menu-item': ContextMenuItemElement;
|
|
29
|
-
'vaadin-context-menu-list-box': ContextMenuListBox;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
|
|
35
|
-
*
|
|
36
|
-
* @protected
|
|
37
|
-
*/
|
|
38
|
-
declare class ContextMenuListBox extends ListBox {}
|
|
39
|
-
|
|
40
19
|
export declare function ItemsMixin<T extends Constructor<HTMLElement>>(base: T): Constructor<ItemsMixinClass> & T;
|
|
41
20
|
|
|
42
21
|
export declare class ItemsMixinClass {
|
|
@@ -51,22 +30,27 @@ export declare class ItemsMixinClass {
|
|
|
51
30
|
*
|
|
52
31
|
* ```javascript
|
|
53
32
|
* contextMenu.items = [
|
|
54
|
-
* {text: 'Menu Item 1', theme: 'primary', children:
|
|
33
|
+
* { text: 'Menu Item 1', theme: 'primary', children:
|
|
55
34
|
* [
|
|
56
|
-
* {text: 'Menu Item 1-1', checked: true},
|
|
57
|
-
* {text: 'Menu Item 1-2'}
|
|
35
|
+
* { text: 'Menu Item 1-1', checked: true },
|
|
36
|
+
* { text: 'Menu Item 1-2' }
|
|
58
37
|
* ]
|
|
59
38
|
* },
|
|
60
|
-
* {component: 'hr'},
|
|
61
|
-
* {text: 'Menu Item 2', children:
|
|
39
|
+
* { component: 'hr' },
|
|
40
|
+
* { text: 'Menu Item 2', children:
|
|
62
41
|
* [
|
|
63
|
-
* {text: 'Menu Item 2-1'},
|
|
64
|
-
* {text: 'Menu Item 2-2', disabled: true}
|
|
42
|
+
* { text: 'Menu Item 2-1' },
|
|
43
|
+
* { text: 'Menu Item 2-2', disabled: true }
|
|
65
44
|
* ]
|
|
66
45
|
* },
|
|
67
|
-
* {text: 'Menu Item 3', disabled: true}
|
|
46
|
+
* { text: 'Menu Item 3', disabled: true }
|
|
68
47
|
* ];
|
|
69
48
|
* ```
|
|
70
49
|
*/
|
|
71
50
|
items: ContextMenuItem[] | undefined;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Tag name prefix used by overlay, list-box and items.
|
|
54
|
+
*/
|
|
55
|
+
protected readonly _tagNamePrefix: string;
|
|
72
56
|
}
|