@vaadin/menu-bar 24.4.0-alpha11 → 24.4.0-alpha13

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/menu-bar",
3
- "version": "24.4.0-alpha11",
3
+ "version": "24.4.0-alpha13",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -37,20 +37,20 @@
37
37
  "dependencies": {
38
38
  "@open-wc/dedupe-mixin": "^1.3.0",
39
39
  "@polymer/polymer": "^3.0.0",
40
- "@vaadin/a11y-base": "24.4.0-alpha11",
41
- "@vaadin/button": "24.4.0-alpha11",
42
- "@vaadin/component-base": "24.4.0-alpha11",
43
- "@vaadin/context-menu": "24.4.0-alpha11",
44
- "@vaadin/item": "24.4.0-alpha11",
45
- "@vaadin/list-box": "24.4.0-alpha11",
46
- "@vaadin/overlay": "24.4.0-alpha11",
47
- "@vaadin/vaadin-lumo-styles": "24.4.0-alpha11",
48
- "@vaadin/vaadin-material-styles": "24.4.0-alpha11",
49
- "@vaadin/vaadin-themable-mixin": "24.4.0-alpha11"
40
+ "@vaadin/a11y-base": "24.4.0-alpha13",
41
+ "@vaadin/button": "24.4.0-alpha13",
42
+ "@vaadin/component-base": "24.4.0-alpha13",
43
+ "@vaadin/context-menu": "24.4.0-alpha13",
44
+ "@vaadin/item": "24.4.0-alpha13",
45
+ "@vaadin/list-box": "24.4.0-alpha13",
46
+ "@vaadin/overlay": "24.4.0-alpha13",
47
+ "@vaadin/vaadin-lumo-styles": "24.4.0-alpha13",
48
+ "@vaadin/vaadin-material-styles": "24.4.0-alpha13",
49
+ "@vaadin/vaadin-themable-mixin": "24.4.0-alpha13"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@esm-bundle/chai": "^4.3.4",
53
- "@vaadin/icon": "24.4.0-alpha11",
53
+ "@vaadin/icon": "24.4.0-alpha13",
54
54
  "@vaadin/testing-helpers": "^0.6.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": "09c2f31d69cd611714169e0cd035688f54b2da37"
61
+ "gitHead": "97246b0703cd04a4b0ea5dcd49e2581d45cf6367"
62
62
  }
@@ -138,6 +138,13 @@ export declare class MenuBarMixinClass {
138
138
  */
139
139
  openOnHover: boolean | null | undefined;
140
140
 
141
+ /**
142
+ * If true, the buttons will be collapsed into the overflow menu
143
+ * starting from the "start" end of the bar instead of the "end".
144
+ * @attr {boolean} reverse-collapse
145
+ */
146
+ reverseCollapse: boolean | null | undefined;
147
+
141
148
  /**
142
149
  * Closes the current submenu.
143
150
  */
@@ -135,6 +135,15 @@ export const MenuBarMixin = (superClass) =>
135
135
  type: Boolean,
136
136
  },
137
137
 
138
+ /**
139
+ * If true, the buttons will be collapsed into the overflow menu
140
+ * starting from the "start" end of the bar instead of the "end".
141
+ * @attr {boolean} reverse-collapse
142
+ */
143
+ reverseCollapse: {
144
+ type: Boolean,
145
+ },
146
+
138
147
  /**
139
148
  * @type {boolean}
140
149
  * @protected
@@ -162,6 +171,7 @@ export const MenuBarMixin = (superClass) =>
162
171
  '__hasOverflowChanged(_hasOverflow, _overflow)',
163
172
  '__i18nChanged(i18n, _overflow)',
164
173
  '_menuItemsChanged(items, _overflow, _container)',
174
+ '_reverseCollapseChanged(reverseCollapse, _overflow, _container)',
165
175
  ];
166
176
  }
167
177
 
@@ -320,6 +330,18 @@ export const MenuBarMixin = (superClass) =>
320
330
  }
321
331
  }
322
332
 
333
+ /**
334
+ * A callback for the 'reverseCollapse' property observer.
335
+ *
336
+ * @param {boolean | null} _reverseCollapse
337
+ * @private
338
+ */
339
+ _reverseCollapseChanged(_reverseCollapse, overflow, container) {
340
+ if (overflow && container) {
341
+ this.__detectOverflow();
342
+ }
343
+ }
344
+
323
345
  /** @private */
324
346
  __hasOverflowChanged(hasOverflow, overflow) {
325
347
  if (overflow) {
@@ -410,34 +432,35 @@ export const MenuBarMixin = (superClass) =>
410
432
  const isRTL = this.__isRTL;
411
433
  const containerLeft = container.getBoundingClientRect().left;
412
434
 
413
- let i;
414
- for (i = buttons.length; i > 0; i--) {
415
- const btn = buttons[i - 1];
416
- const btnStyle = getComputedStyle(btn);
417
- const btnLeft = btn.getBoundingClientRect().left - containerLeft;
435
+ const remaining = [...buttons];
436
+ while (remaining.length) {
437
+ const lastButton = remaining[remaining.length - 1];
438
+ const btnLeft = lastButton.getBoundingClientRect().left - containerLeft;
418
439
 
419
440
  // If this button isn't overflowing, then the rest aren't either
420
441
  if (
421
- (!isRTL && btnLeft + btn.offsetWidth < container.offsetWidth - overflow.offsetWidth) ||
442
+ (!isRTL && btnLeft + lastButton.offsetWidth < container.offsetWidth - overflow.offsetWidth) ||
422
443
  (isRTL && btnLeft >= overflow.offsetWidth)
423
444
  ) {
424
445
  break;
425
446
  }
426
447
 
448
+ const btn = this.reverseCollapse ? remaining.shift() : remaining.pop();
449
+
450
+ // Save width for buttons with component
451
+ btn.style.width = getComputedStyle(btn).width;
427
452
  btn.disabled = true;
428
453
  btn.style.visibility = 'hidden';
429
454
  btn.style.position = 'absolute';
430
- // Save width for buttons with component
431
- btn.style.width = btnStyle.width;
432
455
  }
433
- const items = buttons.filter((_, idx) => idx >= i).map((b) => b.item);
456
+
457
+ const items = buttons.filter((b) => !remaining.includes(b)).map((b) => b.item);
434
458
  this.__updateOverflow(items);
435
459
 
436
- const remaining = buttons.slice(0, i);
437
460
  // Ensure there is at least one button with tabindex set to 0
438
461
  // so that menu-bar is not skipped when navigating with Tab
439
- if (i > 0 && !remaining.some((btn) => btn.getAttribute('tabindex') === '0')) {
440
- this._setTabindex(remaining[i - 1], true);
462
+ if (remaining.length && !remaining.some((btn) => btn.getAttribute('tabindex') === '0')) {
463
+ this._setTabindex(remaining[remaining.length - 1], true);
441
464
  }
442
465
  }
443
466
  }
@@ -461,6 +484,14 @@ export const MenuBarMixin = (superClass) =>
461
484
 
462
485
  const isSingleButton = newOverflowCount === buttons.length || (newOverflowCount === 0 && buttons.length === 1);
463
486
  this.toggleAttribute('has-single-button', isSingleButton);
487
+
488
+ // Apply first/last visible attributes to the visible buttons
489
+ buttons
490
+ .filter((btn) => btn.style.visibility !== 'hidden')
491
+ .forEach((btn, index, visibleButtons) => {
492
+ btn.toggleAttribute('first-visible', index === 0);
493
+ btn.toggleAttribute('last-visible', !this._hasOverflow && index === visibleButtons.length - 1);
494
+ });
464
495
  }
465
496
 
466
497
  /** @protected */
@@ -46,14 +46,14 @@ const menuBarButton = css`
46
46
  padding: 0;
47
47
  }
48
48
 
49
- :host(:first-of-type) {
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(:nth-last-of-type(2)),
56
+ :host([last-visible]),
57
57
  :host([slot='overflow']) {
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']:first-of-type) {
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']:nth-last-of-type(2)),
94
+ :host([dir='rtl'][last-visible]),
95
95
  :host([dir='rtl'][slot='overflow']) {
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']) ::slotted(vaadin-menu-bar-button:first-of-type),
11
+ :host([theme~='end-aligned']) ::slotted(vaadin-menu-bar-button[first-visible]),
12
12
  :host([theme~='end-aligned'][has-single-button]) ::slotted(vaadin-menu-bar-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(:first-of-type) {
52
+ :host([first-visible]) {
53
53
  border-radius: 4px 0 0 4px;
54
54
  }
55
55
 
56
- :host(:nth-last-of-type(2)),
56
+ :host([last-visible]),
57
57
  :host([slot='overflow']) {
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']):nth-last-of-type(2)),
75
+ :host([theme~='outlined']:not([dir='rtl'])[last-visible]),
76
76
  :host([theme~='outlined']:not([dir='rtl'])[slot='overflow']) {
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']:first-of-type) {
86
+ :host([dir='rtl'][first-visible]) {
87
87
  border-radius: 0 4px 4px 0;
88
88
  }
89
89
 
90
- :host([dir='rtl']:nth-last-of-type(2)),
90
+ :host([dir='rtl'][last-visible]),
91
91
  :host([dir='rtl'][slot='overflow']) {
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']:nth-last-of-type(2)),
103
+ :host([theme~='outlined'][dir='rtl'][last-visible]),
104
104
  :host([theme~='outlined'][dir='rtl'][slot='overflow']) {
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']) ::slotted(vaadin-menu-bar-button:first-of-type),
15
+ :host([theme~='end-aligned']) ::slotted(vaadin-menu-bar-button[first-visible]),
16
16
  :host([theme~='end-aligned'][has-single-button]) ::slotted(vaadin-menu-bar-button) {
17
17
  margin-inline-start: auto;
18
18
  }
package/web-types.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/menu-bar",
4
- "version": "24.4.0-alpha11",
4
+ "version": "24.4.0-alpha13",
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/24.4.0-alpha11/#/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\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/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/24.4.0-alpha11/#/elements/vaadin-button).\n- `<vaadin-menu-bar-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.4.0-alpha11/#/elements/vaadin-item).\n- `<vaadin-menu-bar-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/24.4.0-alpha11/#/elements/vaadin-list-box).\n- `<vaadin-menu-bar-overlay>` - has the same API as [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.4.0-alpha11/#/elements/vaadin-overlay).",
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/24.4.0-alpha13/#/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\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/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/24.4.0-alpha13/#/elements/vaadin-button).\n- `<vaadin-menu-bar-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.4.0-alpha13/#/elements/vaadin-item).\n- `<vaadin-menu-bar-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/24.4.0-alpha13/#/elements/vaadin-list-box).\n- `<vaadin-menu-bar-overlay>` - has the same API as [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.4.0-alpha13/#/elements/vaadin-overlay).",
12
12
  "attributes": [
13
13
  {
14
14
  "name": "disabled",
@@ -43,6 +43,17 @@
43
43
  ]
44
44
  }
45
45
  },
46
+ {
47
+ "name": "reverse-collapse",
48
+ "description": "If true, the buttons will be collapsed into the overflow menu\nstarting from the \"start\" end of the bar instead of the \"end\".",
49
+ "value": {
50
+ "type": [
51
+ "boolean",
52
+ "null",
53
+ "undefined"
54
+ ]
55
+ }
56
+ },
46
57
  {
47
58
  "name": "theme",
48
59
  "description": "The theme variants to apply to the component.",
@@ -107,6 +118,17 @@
107
118
  "undefined"
108
119
  ]
109
120
  }
121
+ },
122
+ {
123
+ "name": "reverseCollapse",
124
+ "description": "If true, the buttons will be collapsed into the overflow menu\nstarting from the \"start\" end of the bar instead of the \"end\".",
125
+ "value": {
126
+ "type": [
127
+ "boolean",
128
+ "null",
129
+ "undefined"
130
+ ]
131
+ }
110
132
  }
111
133
  ],
112
134
  "events": [
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/menu-bar",
4
- "version": "24.4.0-alpha11",
4
+ "version": "24.4.0-alpha13",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {
@@ -16,7 +16,7 @@
16
16
  "elements": [
17
17
  {
18
18
  "name": "vaadin-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/24.4.0-alpha11/#/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\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/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/24.4.0-alpha11/#/elements/vaadin-button).\n- `<vaadin-menu-bar-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.4.0-alpha11/#/elements/vaadin-item).\n- `<vaadin-menu-bar-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/24.4.0-alpha11/#/elements/vaadin-list-box).\n- `<vaadin-menu-bar-overlay>` - has the same API as [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.4.0-alpha11/#/elements/vaadin-overlay).",
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/24.4.0-alpha13/#/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\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/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/24.4.0-alpha13/#/elements/vaadin-button).\n- `<vaadin-menu-bar-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.4.0-alpha13/#/elements/vaadin-item).\n- `<vaadin-menu-bar-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/24.4.0-alpha13/#/elements/vaadin-list-box).\n- `<vaadin-menu-bar-overlay>` - has the same API as [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.4.0-alpha13/#/elements/vaadin-overlay).",
20
20
  "extension": true,
21
21
  "attributes": [
22
22
  {
@@ -33,6 +33,13 @@
33
33
  "kind": "expression"
34
34
  }
35
35
  },
36
+ {
37
+ "name": "?reverseCollapse",
38
+ "description": "If true, the buttons will be collapsed into the overflow menu\nstarting from the \"start\" end of the bar instead of the \"end\".",
39
+ "value": {
40
+ "kind": "expression"
41
+ }
42
+ },
36
43
  {
37
44
  "name": ".items",
38
45
  "description": "Defines a hierarchical structure, where root level items represent menu bar buttons,\nand `children` property configures a submenu with items to be opened below\nthe button on click, Enter, Space, Up and Down arrow keys.\n\n#### Example\n\n```js\nmenubar.items = [\n {\n text: 'File',\n className: 'file',\n children: [\n {text: 'Open', className: 'file open'}\n {text: 'Auto Save', checked: true},\n ]\n },\n {component: 'hr'},\n {\n text: 'Edit',\n children: [\n {text: 'Undo', disabled: true},\n {text: 'Redo'}\n ]\n },\n {text: 'Help'}\n];\n```",