@vaadin/menu-bar 25.2.12 → 25.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +15 -15
- package/src/vaadin-menu-bar-mixin.js +96 -32
- package/web-types.json +2 -2
- package/web-types.lit.json +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/menu-bar",
|
|
3
|
-
"version": "25.2.
|
|
3
|
+
"version": "25.2.13",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -35,23 +35,23 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
38
|
-
"@vaadin/a11y-base": "~25.2.
|
|
39
|
-
"@vaadin/button": "~25.2.
|
|
40
|
-
"@vaadin/component-base": "~25.2.
|
|
41
|
-
"@vaadin/context-menu": "~25.2.
|
|
42
|
-
"@vaadin/item": "~25.2.
|
|
43
|
-
"@vaadin/list-box": "~25.2.
|
|
44
|
-
"@vaadin/overlay": "~25.2.
|
|
45
|
-
"@vaadin/vaadin-themable-mixin": "~25.2.
|
|
38
|
+
"@vaadin/a11y-base": "~25.2.13",
|
|
39
|
+
"@vaadin/button": "~25.2.13",
|
|
40
|
+
"@vaadin/component-base": "~25.2.13",
|
|
41
|
+
"@vaadin/context-menu": "~25.2.13",
|
|
42
|
+
"@vaadin/item": "~25.2.13",
|
|
43
|
+
"@vaadin/list-box": "~25.2.13",
|
|
44
|
+
"@vaadin/overlay": "~25.2.13",
|
|
45
|
+
"@vaadin/vaadin-themable-mixin": "~25.2.13",
|
|
46
46
|
"lit": "^3.0.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@vaadin/aura": "~25.2.
|
|
50
|
-
"@vaadin/chai-plugins": "~25.2.
|
|
51
|
-
"@vaadin/icon": "~25.2.
|
|
52
|
-
"@vaadin/test-runner-commands": "~25.2.
|
|
49
|
+
"@vaadin/aura": "~25.2.13",
|
|
50
|
+
"@vaadin/chai-plugins": "~25.2.13",
|
|
51
|
+
"@vaadin/icon": "~25.2.13",
|
|
52
|
+
"@vaadin/test-runner-commands": "~25.2.13",
|
|
53
53
|
"@vaadin/testing-helpers": "^2.0.0",
|
|
54
|
-
"@vaadin/vaadin-lumo-styles": "~25.2.
|
|
54
|
+
"@vaadin/vaadin-lumo-styles": "~25.2.13",
|
|
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": "601112f027fb53668eed85f9593fa6fe5222fa00"
|
|
63
63
|
}
|
|
@@ -56,6 +56,9 @@ const DEFAULT_I18N = {
|
|
|
56
56
|
moreOptions: 'More options',
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
// Two client rects of the same edge can differ by float noise, a few 1e-5 px under browser zoom
|
|
60
|
+
const OVERFLOW_TOLERANCE = 0.1;
|
|
61
|
+
|
|
59
62
|
export const MenuBarMixin = (superClass) =>
|
|
60
63
|
class MenuBarMixinClass extends I18nMixin(
|
|
61
64
|
KeyboardDirectionMixin(ResizeMixin(FocusMixin(DisabledMixin(superClass)))),
|
|
@@ -498,49 +501,110 @@ export const MenuBarMixin = (superClass) =>
|
|
|
498
501
|
this._hasOverflow = items.length > 0;
|
|
499
502
|
}
|
|
500
503
|
|
|
501
|
-
/**
|
|
502
|
-
|
|
503
|
-
|
|
504
|
+
/**
|
|
505
|
+
* Inline end edge of the element, mirrored in RTL. Unlike `offsetWidth` and `scrollWidth`,
|
|
506
|
+
* the rect keeps the fraction that browser zoom leaves on the width.
|
|
507
|
+
*
|
|
508
|
+
* @param {!HTMLElement} el
|
|
509
|
+
* @return {number}
|
|
510
|
+
* @private
|
|
511
|
+
*/
|
|
512
|
+
__getInlineEnd(el) {
|
|
513
|
+
const { left, right } = el.getBoundingClientRect();
|
|
514
|
+
return this.__isRTL ? -left : right;
|
|
515
|
+
}
|
|
504
516
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
517
|
+
/**
|
|
518
|
+
* Positions of the buttons, read in one batch before any of them is hidden.
|
|
519
|
+
* Mirrored in RTL so that a larger value is always further along the inline axis.
|
|
520
|
+
*
|
|
521
|
+
* @typedef {object} MenuBarOverflowLayout
|
|
522
|
+
* @property {number[]} starts Inline start of each button
|
|
523
|
+
* @property {number[]} ends Inline end of each button
|
|
524
|
+
* @property {number[]} margins Inline start margin of each button
|
|
525
|
+
* @property {number} overflowExtent Space the overflow button adds after the last button
|
|
526
|
+
*/
|
|
511
527
|
|
|
512
|
-
|
|
513
|
-
|
|
528
|
+
/**
|
|
529
|
+
* @param {!Array<!HTMLElement>} buttons
|
|
530
|
+
* @param {!HTMLElement} overflow
|
|
531
|
+
* @return {!MenuBarOverflowLayout}
|
|
532
|
+
* @private
|
|
533
|
+
*/
|
|
534
|
+
__measureButtons(buttons, overflow) {
|
|
535
|
+
const isRTL = this.__isRTL;
|
|
536
|
+
const rects = buttons.map((btn) => btn.getBoundingClientRect());
|
|
537
|
+
const ends = rects.map(({ left, right }) => (isRTL ? -left : right));
|
|
538
|
+
|
|
539
|
+
return {
|
|
540
|
+
starts: rects.map(({ left, right }) => (isRTL ? -right : left)),
|
|
541
|
+
ends,
|
|
542
|
+
// `auto` resolves to 0 while the content overflows.
|
|
543
|
+
margins: buttons.map((btn) => parseFloat(getComputedStyle(btn).marginInlineStart) || 0),
|
|
544
|
+
overflowExtent: this.__getInlineEnd(overflow) - ends.at(-1),
|
|
545
|
+
};
|
|
546
|
+
}
|
|
514
547
|
|
|
515
|
-
|
|
516
|
-
|
|
548
|
+
/**
|
|
549
|
+
* Picks the buttons to collapse so that the rest plus the overflow button end inside
|
|
550
|
+
* the container. Hiding a button only shifts the buttons after it, so the end of any
|
|
551
|
+
* kept range follows from one measurement.
|
|
552
|
+
*
|
|
553
|
+
* @param {!Array<!HTMLElement>} buttons
|
|
554
|
+
* @param {!MenuBarOverflowLayout} layout
|
|
555
|
+
* @param {number} containerWidth
|
|
556
|
+
* @return {!Array<!HTMLElement>} buttons to collapse, in DOM order
|
|
557
|
+
* @private
|
|
558
|
+
*/
|
|
559
|
+
__getCollapsedButtons(buttons, { starts, ends, margins, overflowExtent }, containerWidth) {
|
|
560
|
+
let lo = 0;
|
|
561
|
+
let hi = buttons.length - 1;
|
|
562
|
+
|
|
563
|
+
// The first kept button keeps its own start margin in front of the range.
|
|
564
|
+
while (lo <= hi && margins[lo] + ends[hi] - starts[lo] + overflowExtent > containerWidth + OVERFLOW_TOLERANCE) {
|
|
565
|
+
if (this.reverseCollapse) {
|
|
566
|
+
lo += 1;
|
|
567
|
+
} else {
|
|
568
|
+
hi -= 1;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
517
571
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
const lastButton = remaining[remaining.length - 1];
|
|
521
|
-
const btnLeft = lastButton.offsetLeft - containerLeft;
|
|
572
|
+
return buttons.filter((_, i) => i < lo || i > hi);
|
|
573
|
+
}
|
|
522
574
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
575
|
+
/** @private */
|
|
576
|
+
__setOverflowItems(buttons, overflow) {
|
|
577
|
+
const container = this._container;
|
|
578
|
+
// Read before any write, so a menu bar that fits forces no layout
|
|
579
|
+
const width = container.offsetWidth;
|
|
580
|
+
const lastButton = buttons.at(-1);
|
|
581
|
+
|
|
582
|
+
if (lastButton && this.__getInlineEnd(lastButton) > this.__getInlineEnd(container) + OVERFLOW_TOLERANCE) {
|
|
583
|
+
// Prevent the container from shrinking while buttons are being hidden.
|
|
584
|
+
// The host has min-width: 0 so it can shrink inside flex/grid layouts.
|
|
585
|
+
// Without this lock, hiding a button reduces the host width, which
|
|
586
|
+
// shrinks the container (width: 100%), shifting all button positions
|
|
587
|
+
// and causing a cascading collapse where every button appears to overflow.
|
|
588
|
+
container.style.minWidth = `${width}px`;
|
|
589
|
+
this._hasOverflow = true;
|
|
530
590
|
|
|
531
|
-
|
|
591
|
+
// Read the layout once the overflow button is in flow
|
|
592
|
+
const layout = this.__measureButtons(buttons, overflow);
|
|
593
|
+
const containerWidth = container.getBoundingClientRect().width;
|
|
594
|
+
const collapsed = this.__getCollapsedButtons(buttons, layout, containerWidth);
|
|
595
|
+
// Read button widths once outside of the loop to avoid repetitive layout
|
|
596
|
+
const widths = collapsed.map((btn) => getComputedStyle(btn).width);
|
|
532
597
|
|
|
533
|
-
|
|
534
|
-
|
|
598
|
+
// Write the DOM state
|
|
599
|
+
collapsed.forEach((btn, i) => {
|
|
600
|
+
btn.style.width = widths[i];
|
|
535
601
|
btn.style.visibility = 'hidden';
|
|
536
602
|
btn.style.position = 'absolute';
|
|
537
|
-
}
|
|
603
|
+
});
|
|
604
|
+
this.__updateOverflow(collapsed.map((btn) => btn.item));
|
|
538
605
|
|
|
539
|
-
|
|
540
|
-
this.__updateOverflow(items);
|
|
606
|
+
container.style.minWidth = '';
|
|
541
607
|
}
|
|
542
|
-
|
|
543
|
-
container.style.minWidth = '';
|
|
544
608
|
}
|
|
545
609
|
|
|
546
610
|
/** @private */
|
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": "25.2.
|
|
4
|
+
"version": "25.2.13",
|
|
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```html\n<vaadin-menu-bar></vaadin-menu-bar>\n```\n\nAnd then use [`items`](https://cdn.vaadin.com/vaadin-web-components/25.2.
|
|
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```html\n<vaadin-menu-bar></vaadin-menu-bar>\n```\n\nAnd then use [`items`](https://cdn.vaadin.com/vaadin-web-components/25.2.13/#/elements/vaadin-menu-bar#property-items) property to initialize the structure:\n\n```js\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\nThe following custom CSS properties are available for styling:\n\nCustom CSS property |\n:---------------------------|\n| `--vaadin-menu-bar-gap` |\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/25.2.13/#/elements/vaadin-button).\n- `<vaadin-menu-bar-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/25.2.13/#/elements/vaadin-item).\n- `<vaadin-menu-bar-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/25.2.13/#/elements/vaadin-list-box).\n- `<vaadin-menu-bar-submenu>` - has the same API as [`<vaadin-context-menu>`](https://cdn.vaadin.com/vaadin-web-components/25.2.13/#/elements/vaadin-context-menu).\n\nThe `<vaadin-menu-bar-item>` sub-menu elements have the following additional state attributes\non top of the built-in `<vaadin-item>` state attributes:\n\nAttribute | Description\n---------- |-------------\n`expanded` | Expanded parent item.",
|
|
12
12
|
"attributes": [
|
|
13
13
|
{
|
|
14
14
|
"name": "disabled",
|
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": "25.2.
|
|
4
|
+
"version": "25.2.13",
|
|
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```html\n<vaadin-menu-bar></vaadin-menu-bar>\n```\n\nAnd then use [`items`](https://cdn.vaadin.com/vaadin-web-components/25.2.
|
|
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```html\n<vaadin-menu-bar></vaadin-menu-bar>\n```\n\nAnd then use [`items`](https://cdn.vaadin.com/vaadin-web-components/25.2.13/#/elements/vaadin-menu-bar#property-items) property to initialize the structure:\n\n```js\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\nThe following custom CSS properties are available for styling:\n\nCustom CSS property |\n:---------------------------|\n| `--vaadin-menu-bar-gap` |\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/25.2.13/#/elements/vaadin-button).\n- `<vaadin-menu-bar-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/25.2.13/#/elements/vaadin-item).\n- `<vaadin-menu-bar-list-box>` - has the same API as [`<vaadin-list-box>`](https://cdn.vaadin.com/vaadin-web-components/25.2.13/#/elements/vaadin-list-box).\n- `<vaadin-menu-bar-submenu>` - has the same API as [`<vaadin-context-menu>`](https://cdn.vaadin.com/vaadin-web-components/25.2.13/#/elements/vaadin-context-menu).\n\nThe `<vaadin-menu-bar-item>` sub-menu elements have the following additional state attributes\non top of the built-in `<vaadin-item>` state attributes:\n\nAttribute | Description\n---------- |-------------\n`expanded` | Expanded parent item.",
|
|
20
20
|
"extension": true,
|
|
21
21
|
"attributes": [
|
|
22
22
|
{
|