@vaadin/menu-bar 23.4.0-alpha2 → 23.4.0-alpha4
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 +9 -9
- package/src/vaadin-menu-bar-buttons-mixin.d.ts +7 -0
- package/src/vaadin-menu-bar-buttons-mixin.js +40 -10
- package/theme/lumo/vaadin-menu-bar-button-styles.js +4 -4
- package/theme/lumo/vaadin-menu-bar-styles.js +1 -1
- package/theme/material/vaadin-menu-bar-button-styles.js +6 -6
- package/theme/material/vaadin-menu-bar-styles.js +1 -1
- package/web-types.json +24 -2
- package/web-types.lit.json +9 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/menu-bar",
|
|
3
|
-
"version": "23.4.0-
|
|
3
|
+
"version": "23.4.0-alpha4",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -37,16 +37,16 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
39
39
|
"@polymer/polymer": "^3.0.0",
|
|
40
|
-
"@vaadin/button": "23.4.0-
|
|
41
|
-
"@vaadin/component-base": "23.4.0-
|
|
42
|
-
"@vaadin/context-menu": "23.4.0-
|
|
43
|
-
"@vaadin/vaadin-lumo-styles": "23.4.0-
|
|
44
|
-
"@vaadin/vaadin-material-styles": "23.4.0-
|
|
45
|
-
"@vaadin/vaadin-themable-mixin": "23.4.0-
|
|
40
|
+
"@vaadin/button": "23.4.0-alpha4",
|
|
41
|
+
"@vaadin/component-base": "23.4.0-alpha4",
|
|
42
|
+
"@vaadin/context-menu": "23.4.0-alpha4",
|
|
43
|
+
"@vaadin/vaadin-lumo-styles": "23.4.0-alpha4",
|
|
44
|
+
"@vaadin/vaadin-material-styles": "23.4.0-alpha4",
|
|
45
|
+
"@vaadin/vaadin-themable-mixin": "23.4.0-alpha4"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@esm-bundle/chai": "^4.3.4",
|
|
49
|
-
"@vaadin/icon": "23.4.0-
|
|
49
|
+
"@vaadin/icon": "23.4.0-alpha4",
|
|
50
50
|
"@vaadin/testing-helpers": "^0.3.2",
|
|
51
51
|
"sinon": "^13.0.2"
|
|
52
52
|
},
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"web-types.json",
|
|
55
55
|
"web-types.lit.json"
|
|
56
56
|
],
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "65c187361bd37957354719173f69aac19b82eae4"
|
|
58
58
|
}
|
|
@@ -11,6 +11,13 @@ export declare function ButtonsMixin<T extends Constructor<HTMLElement>>(
|
|
|
11
11
|
): Constructor<ButtonsMixinClass> & Constructor<ResizeMixinClass> & T;
|
|
12
12
|
|
|
13
13
|
export declare class ButtonsMixinClass {
|
|
14
|
+
/**
|
|
15
|
+
* If true, the buttons will be collapsed into the overflow menu
|
|
16
|
+
* starting from the "start" end of the bar instead of the "end".
|
|
17
|
+
* @attr {boolean} reverse-collapse
|
|
18
|
+
*/
|
|
19
|
+
reverseCollapse: boolean | null | undefined;
|
|
20
|
+
|
|
14
21
|
protected readonly _buttons: HTMLElement[];
|
|
15
22
|
|
|
16
23
|
protected readonly _container: HTMLElement;
|
|
@@ -13,6 +13,15 @@ export const ButtonsMixin = (superClass) =>
|
|
|
13
13
|
class extends ResizeMixin(superClass) {
|
|
14
14
|
static get properties() {
|
|
15
15
|
return {
|
|
16
|
+
/**
|
|
17
|
+
* If true, the buttons will be collapsed into the overflow menu
|
|
18
|
+
* starting from the "start" end of the bar instead of the "end".
|
|
19
|
+
* @attr {boolean} reverse-collapse
|
|
20
|
+
*/
|
|
21
|
+
reverseCollapse: {
|
|
22
|
+
type: Boolean,
|
|
23
|
+
},
|
|
24
|
+
|
|
16
25
|
/**
|
|
17
26
|
* @type {boolean}
|
|
18
27
|
* @protected
|
|
@@ -25,7 +34,7 @@ export const ButtonsMixin = (superClass) =>
|
|
|
25
34
|
}
|
|
26
35
|
|
|
27
36
|
static get observers() {
|
|
28
|
-
return ['_menuItemsChanged(items, items.splices)'];
|
|
37
|
+
return ['_menuItemsChanged(items, items.splices)', '_reverseCollapseChanged(reverseCollapse)'];
|
|
29
38
|
}
|
|
30
39
|
|
|
31
40
|
/**
|
|
@@ -125,6 +134,16 @@ export const ButtonsMixin = (superClass) =>
|
|
|
125
134
|
this._hasOverflow = items.length > 0;
|
|
126
135
|
}
|
|
127
136
|
|
|
137
|
+
/**
|
|
138
|
+
* A callback for the 'reverseCollapse' property observer.
|
|
139
|
+
*
|
|
140
|
+
* @param {boolean | null} _reverseCollapse
|
|
141
|
+
* @private
|
|
142
|
+
*/
|
|
143
|
+
_reverseCollapseChanged(_reverseCollapse) {
|
|
144
|
+
this.__detectOverflow();
|
|
145
|
+
}
|
|
146
|
+
|
|
128
147
|
/** @private */
|
|
129
148
|
__setOverflowItems(buttons, overflow) {
|
|
130
149
|
const container = this._container;
|
|
@@ -133,27 +152,30 @@ export const ButtonsMixin = (superClass) =>
|
|
|
133
152
|
this._hasOverflow = true;
|
|
134
153
|
|
|
135
154
|
const isRTL = this.getAttribute('dir') === 'rtl';
|
|
155
|
+
const containerLeft = container.getBoundingClientRect().left;
|
|
136
156
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
const
|
|
157
|
+
const remaining = [...buttons];
|
|
158
|
+
while (remaining.length) {
|
|
159
|
+
const lastButton = remaining[remaining.length - 1];
|
|
160
|
+
const btnLeft = lastButton.getBoundingClientRect().left - containerLeft;
|
|
141
161
|
|
|
142
162
|
// If this button isn't overflowing, then the rest aren't either
|
|
143
163
|
if (
|
|
144
|
-
(!isRTL &&
|
|
145
|
-
(isRTL &&
|
|
164
|
+
(!isRTL && btnLeft + lastButton.offsetWidth < container.offsetWidth - overflow.offsetWidth) ||
|
|
165
|
+
(isRTL && btnLeft >= overflow.offsetWidth)
|
|
146
166
|
) {
|
|
147
167
|
break;
|
|
148
168
|
}
|
|
149
169
|
|
|
170
|
+
const btn = this.reverseCollapse ? remaining.shift() : remaining.pop();
|
|
171
|
+
|
|
172
|
+
// Save width for buttons with component
|
|
173
|
+
btn.style.width = getComputedStyle(btn).width;
|
|
150
174
|
btn.disabled = true;
|
|
151
175
|
btn.style.visibility = 'hidden';
|
|
152
176
|
btn.style.position = 'absolute';
|
|
153
|
-
// Save width for buttons with component
|
|
154
|
-
btn.style.width = btnStyle.width;
|
|
155
177
|
}
|
|
156
|
-
const items = buttons.filter((
|
|
178
|
+
const items = buttons.filter((b) => !remaining.includes(b)).map((b) => b.item);
|
|
157
179
|
this.__updateOverflow(items);
|
|
158
180
|
}
|
|
159
181
|
}
|
|
@@ -177,6 +199,14 @@ export const ButtonsMixin = (superClass) =>
|
|
|
177
199
|
|
|
178
200
|
const isSingleButton = newOverflowCount === buttons.length || (newOverflowCount === 0 && buttons.length === 1);
|
|
179
201
|
this.toggleAttribute('has-single-button', isSingleButton);
|
|
202
|
+
|
|
203
|
+
// Apply first/last visible attributes to the visible buttons
|
|
204
|
+
buttons
|
|
205
|
+
.filter((btn) => btn.style.visibility !== 'hidden')
|
|
206
|
+
.forEach((btn, index, visibleButtons) => {
|
|
207
|
+
btn.toggleAttribute('first-visible', index === 0);
|
|
208
|
+
btn.toggleAttribute('last-visible', !this._hasOverflow && index === visibleButtons.length - 1);
|
|
209
|
+
});
|
|
180
210
|
}
|
|
181
211
|
|
|
182
212
|
/** @protected */
|
|
@@ -46,14 +46,14 @@ const menuBarButton = css`
|
|
|
46
46
|
padding: 0;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
:host(
|
|
49
|
+
:host([first-visible]) {
|
|
50
50
|
border-radius: var(--lumo-border-radius-m) 0 0 var(--lumo-border-radius-m);
|
|
51
51
|
|
|
52
52
|
/* Needed to retain the focus-ring with border-radius */
|
|
53
53
|
margin-left: calc(var(--lumo-space-xs) / 2);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
:host(
|
|
56
|
+
:host([last-visible]),
|
|
57
57
|
:host([part='overflow-button']) {
|
|
58
58
|
border-radius: 0 var(--lumo-border-radius-m) var(--lumo-border-radius-m) 0;
|
|
59
59
|
}
|
|
@@ -86,12 +86,12 @@ const menuBarButton = css`
|
|
|
86
86
|
border-radius: 0;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
:host([dir='rtl']
|
|
89
|
+
:host([dir='rtl'][first-visible]) {
|
|
90
90
|
border-radius: 0 var(--lumo-border-radius-m) var(--lumo-border-radius-m) 0;
|
|
91
91
|
margin-right: calc(var(--lumo-space-xs) / 2);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
:host([dir='rtl']
|
|
94
|
+
:host([dir='rtl'][last-visible]),
|
|
95
95
|
:host([dir='rtl'][part='overflow-button']) {
|
|
96
96
|
border-radius: var(--lumo-border-radius-m) 0 0 var(--lumo-border-radius-m);
|
|
97
97
|
}
|
|
@@ -8,7 +8,7 @@ registerStyles(
|
|
|
8
8
|
border-radius: var(--lumo-border-radius-m);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
:host([theme~='end-aligned']) [part$='button']
|
|
11
|
+
:host([theme~='end-aligned']) [part$='button'][first-visible],
|
|
12
12
|
:host([theme~='end-aligned'][has-single-button]) [part$='button'] {
|
|
13
13
|
margin-inline-start: auto;
|
|
14
14
|
}
|
|
@@ -49,11 +49,11 @@ const menuBarButton = css`
|
|
|
49
49
|
margin-right: 1px;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
:host(
|
|
52
|
+
:host([first-visible]) {
|
|
53
53
|
border-radius: 4px 0 0 4px;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
:host(
|
|
56
|
+
:host([last-visible]),
|
|
57
57
|
:host([part~='overflow-button']) {
|
|
58
58
|
border-radius: 0 4px 4px 0;
|
|
59
59
|
}
|
|
@@ -72,7 +72,7 @@ const menuBarButton = css`
|
|
|
72
72
|
margin-right: -1px;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
:host([theme~='outlined']:not([dir='rtl'])
|
|
75
|
+
:host([theme~='outlined']:not([dir='rtl'])[last-visible]),
|
|
76
76
|
:host([theme~='outlined']:not([dir='rtl'])[part~='overflow-button']) {
|
|
77
77
|
margin-right: 0;
|
|
78
78
|
}
|
|
@@ -83,11 +83,11 @@ const menuBarButton = css`
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/* RTL styles */
|
|
86
|
-
:host([dir='rtl']
|
|
86
|
+
:host([dir='rtl'][first-visible]) {
|
|
87
87
|
border-radius: 0 4px 4px 0;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
:host([dir='rtl']
|
|
90
|
+
:host([dir='rtl'][last-visible]),
|
|
91
91
|
:host([dir='rtl'][part='overflow-button']) {
|
|
92
92
|
border-radius: 4px 0 0 4px;
|
|
93
93
|
}
|
|
@@ -100,7 +100,7 @@ const menuBarButton = css`
|
|
|
100
100
|
margin-left: -1px;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
:host([theme~='outlined'][dir='rtl']
|
|
103
|
+
:host([theme~='outlined'][dir='rtl'][last-visible]),
|
|
104
104
|
:host([theme~='outlined'][dir='rtl'][part~='overflow-button']) {
|
|
105
105
|
margin-left: 0;
|
|
106
106
|
}
|
|
@@ -12,7 +12,7 @@ registerStyles(
|
|
|
12
12
|
border-radius: 4px;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
:host([theme~='end-aligned']) [part$='button']
|
|
15
|
+
:host([theme~='end-aligned']) [part$='button'][first-visible],
|
|
16
16
|
:host([theme~='end-aligned'][has-single-button]) [part$='button'] {
|
|
17
17
|
margin-inline-start: auto;
|
|
18
18
|
}
|
package/web-types.json
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/web-types",
|
|
3
3
|
"name": "@vaadin/menu-bar",
|
|
4
|
-
"version": "23.4.0-
|
|
4
|
+
"version": "23.4.0-alpha4",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"contributions": {
|
|
7
7
|
"html": {
|
|
8
8
|
"elements": [
|
|
9
9
|
{
|
|
10
10
|
"name": "vaadin-menu-bar",
|
|
11
|
-
"description": "`<vaadin-menu-bar>` is a Web Component providing a set of horizontally stacked buttons offering\nthe user quick access to a consistent set of commands. Each button can toggle a submenu with\nsupport for additional levels of nested menus.\n\nTo create the menu bar, first add the component to the page:\n\n```\n<vaadin-menu-bar></vaadin-menu-bar>\n```\n\nAnd then use [`items`](https://cdn.vaadin.com/vaadin-web-components/23.4.0-
|
|
11
|
+
"description": "`<vaadin-menu-bar>` is a Web Component providing a set of horizontally stacked buttons offering\nthe user quick access to a consistent set of commands. Each button can toggle a submenu with\nsupport for additional levels of nested menus.\n\nTo create the menu bar, first add the component to the page:\n\n```\n<vaadin-menu-bar></vaadin-menu-bar>\n```\n\nAnd then use [`items`](https://cdn.vaadin.com/vaadin-web-components/23.4.0-alpha4/#/elements/vaadin-menu-bar#property-items) property to initialize the structure:\n\n```\ndocument.querySelector('vaadin-menu-bar').items = [{text: 'File'}, {text: 'Edit'}];\n```\n\n### Styling\n\nThe following shadow DOM parts are exposed for styling:\n\nPart name | Description\n------------------|----------------\n`container` | The container wrapping menu bar buttons.\n`menu-bar-button` | The menu bar button.\n`overflow-button` | The \"overflow\" button appearing when menu bar width is not enough to fit all the buttons.\n\nThe following state attributes are available for styling:\n\nAttribute | Description\n--------------------|----------------------------------\n`disabled` | Set when the menu bar is disabled\n`has-single-button` | Set when there is only one button visible\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.\n\n### Internal components\n\nIn addition to `<vaadin-menu-bar>` itself, the following internal\ncomponents are themable:\n\n- `<vaadin-menu-bar-button>` - has the same API as [`<vaadin-button>`](https://cdn.vaadin.com/vaadin-web-components/23.4.0-alpha4/#/elements/vaadin-button).\n- `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/23.4.0-alpha4/#/elements/vaadin-item).\n- `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/23.4.0-alpha4/#/elements/vaadin-list-box).\n- `<vaadin-context-menu-overlay>` - has the same API as [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/23.4.0-alpha4/#/elements/vaadin-overlay).",
|
|
12
12
|
"attributes": [
|
|
13
|
+
{
|
|
14
|
+
"name": "reverse-collapse",
|
|
15
|
+
"description": "If true, the buttons will be collapsed into the overflow menu\nstarting from the \"start\" end of the bar instead of the \"end\".",
|
|
16
|
+
"value": {
|
|
17
|
+
"type": [
|
|
18
|
+
"boolean",
|
|
19
|
+
"null",
|
|
20
|
+
"undefined"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
13
24
|
{
|
|
14
25
|
"name": "open-on-hover",
|
|
15
26
|
"description": "If true, the submenu will open on hover (mouseover) instead of click.",
|
|
@@ -46,6 +57,17 @@
|
|
|
46
57
|
],
|
|
47
58
|
"js": {
|
|
48
59
|
"properties": [
|
|
60
|
+
{
|
|
61
|
+
"name": "reverseCollapse",
|
|
62
|
+
"description": "If true, the buttons will be collapsed into the overflow menu\nstarting from the \"start\" end of the bar instead of the \"end\".",
|
|
63
|
+
"value": {
|
|
64
|
+
"type": [
|
|
65
|
+
"boolean",
|
|
66
|
+
"null",
|
|
67
|
+
"undefined"
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
},
|
|
49
71
|
{
|
|
50
72
|
"name": "openOnHover",
|
|
51
73
|
"description": "If true, the submenu will open on hover (mouseover) instead of click.",
|
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/menu-bar",
|
|
4
|
-
"version": "23.4.0-
|
|
4
|
+
"version": "23.4.0-alpha4",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"framework": "lit",
|
|
7
7
|
"framework-config": {
|
|
@@ -16,9 +16,16 @@
|
|
|
16
16
|
"elements": [
|
|
17
17
|
{
|
|
18
18
|
"name": "vaadin-menu-bar",
|
|
19
|
-
"description": "`<vaadin-menu-bar>` is a Web Component providing a set of horizontally stacked buttons offering\nthe user quick access to a consistent set of commands. Each button can toggle a submenu with\nsupport for additional levels of nested menus.\n\nTo create the menu bar, first add the component to the page:\n\n```\n<vaadin-menu-bar></vaadin-menu-bar>\n```\n\nAnd then use [`items`](https://cdn.vaadin.com/vaadin-web-components/23.4.0-
|
|
19
|
+
"description": "`<vaadin-menu-bar>` is a Web Component providing a set of horizontally stacked buttons offering\nthe user quick access to a consistent set of commands. Each button can toggle a submenu with\nsupport for additional levels of nested menus.\n\nTo create the menu bar, first add the component to the page:\n\n```\n<vaadin-menu-bar></vaadin-menu-bar>\n```\n\nAnd then use [`items`](https://cdn.vaadin.com/vaadin-web-components/23.4.0-alpha4/#/elements/vaadin-menu-bar#property-items) property to initialize the structure:\n\n```\ndocument.querySelector('vaadin-menu-bar').items = [{text: 'File'}, {text: 'Edit'}];\n```\n\n### Styling\n\nThe following shadow DOM parts are exposed for styling:\n\nPart name | Description\n------------------|----------------\n`container` | The container wrapping menu bar buttons.\n`menu-bar-button` | The menu bar button.\n`overflow-button` | The \"overflow\" button appearing when menu bar width is not enough to fit all the buttons.\n\nThe following state attributes are available for styling:\n\nAttribute | Description\n--------------------|----------------------------------\n`disabled` | Set when the menu bar is disabled\n`has-single-button` | Set when there is only one button visible\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.\n\n### Internal components\n\nIn addition to `<vaadin-menu-bar>` itself, the following internal\ncomponents are themable:\n\n- `<vaadin-menu-bar-button>` - has the same API as [`<vaadin-button>`](https://cdn.vaadin.com/vaadin-web-components/23.4.0-alpha4/#/elements/vaadin-button).\n- `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/23.4.0-alpha4/#/elements/vaadin-item).\n- `<vaadin-context-menu-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/23.4.0-alpha4/#/elements/vaadin-list-box).\n- `<vaadin-context-menu-overlay>` - has the same API as [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/23.4.0-alpha4/#/elements/vaadin-overlay).",
|
|
20
20
|
"extension": true,
|
|
21
21
|
"attributes": [
|
|
22
|
+
{
|
|
23
|
+
"name": "?reverseCollapse",
|
|
24
|
+
"description": "If true, the buttons will be collapsed into the overflow menu\nstarting from the \"start\" end of the bar instead of the \"end\".",
|
|
25
|
+
"value": {
|
|
26
|
+
"kind": "expression"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
22
29
|
{
|
|
23
30
|
"name": "?openOnHover",
|
|
24
31
|
"description": "If true, the submenu will open on hover (mouseover) instead of click.",
|