@vaadin/menu-bar 24.5.0-alpha1 → 24.5.0-alpha11
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/README.md +1 -1
- package/package.json +16 -16
- package/src/vaadin-menu-bar-mixin.d.ts +7 -0
- package/src/vaadin-menu-bar-mixin.js +74 -13
- package/theme/lumo/vaadin-menu-bar-styles.js +4 -0
- package/web-types.json +24 -2
- package/web-types.lit.json +9 -2
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ import '@vaadin/menu-bar/src/vaadin-menu-bar.js';
|
|
|
63
63
|
|
|
64
64
|
## Contributing
|
|
65
65
|
|
|
66
|
-
Read the [contributing guide](https://vaadin.com/docs/latest/contributing
|
|
66
|
+
Read the [contributing guide](https://vaadin.com/docs/latest/contributing) to learn about our development process, how to propose bugfixes and improvements, and how to test your changes to Vaadin components.
|
|
67
67
|
|
|
68
68
|
## License
|
|
69
69
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/menu-bar",
|
|
3
|
-
"version": "24.5.0-
|
|
3
|
+
"version": "24.5.0-alpha11",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -39,27 +39,27 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
41
41
|
"@polymer/polymer": "^3.0.0",
|
|
42
|
-
"@vaadin/a11y-base": "24.5.0-
|
|
43
|
-
"@vaadin/button": "24.5.0-
|
|
44
|
-
"@vaadin/component-base": "24.5.0-
|
|
45
|
-
"@vaadin/context-menu": "24.5.0-
|
|
46
|
-
"@vaadin/item": "24.5.0-
|
|
47
|
-
"@vaadin/list-box": "24.5.0-
|
|
48
|
-
"@vaadin/overlay": "24.5.0-
|
|
49
|
-
"@vaadin/vaadin-lumo-styles": "24.5.0-
|
|
50
|
-
"@vaadin/vaadin-material-styles": "24.5.0-
|
|
51
|
-
"@vaadin/vaadin-themable-mixin": "24.5.0-
|
|
42
|
+
"@vaadin/a11y-base": "24.5.0-alpha11",
|
|
43
|
+
"@vaadin/button": "24.5.0-alpha11",
|
|
44
|
+
"@vaadin/component-base": "24.5.0-alpha11",
|
|
45
|
+
"@vaadin/context-menu": "24.5.0-alpha11",
|
|
46
|
+
"@vaadin/item": "24.5.0-alpha11",
|
|
47
|
+
"@vaadin/list-box": "24.5.0-alpha11",
|
|
48
|
+
"@vaadin/overlay": "24.5.0-alpha11",
|
|
49
|
+
"@vaadin/vaadin-lumo-styles": "24.5.0-alpha11",
|
|
50
|
+
"@vaadin/vaadin-material-styles": "24.5.0-alpha11",
|
|
51
|
+
"@vaadin/vaadin-themable-mixin": "24.5.0-alpha11",
|
|
52
52
|
"lit": "^3.0.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@
|
|
56
|
-
"@vaadin/icon": "24.5.0-
|
|
57
|
-
"@vaadin/testing-helpers": "^0.
|
|
58
|
-
"sinon": "^
|
|
55
|
+
"@vaadin/chai-plugins": "24.5.0-alpha11",
|
|
56
|
+
"@vaadin/icon": "24.5.0-alpha11",
|
|
57
|
+
"@vaadin/testing-helpers": "^1.0.0",
|
|
58
|
+
"sinon": "^18.0.0"
|
|
59
59
|
},
|
|
60
60
|
"web-types": [
|
|
61
61
|
"web-types.json",
|
|
62
62
|
"web-types.lit.json"
|
|
63
63
|
],
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "8426cea2803a10db518fc85752eeea4c5c755687"
|
|
65
65
|
}
|
|
@@ -145,6 +145,13 @@ export declare class MenuBarMixinClass {
|
|
|
145
145
|
*/
|
|
146
146
|
reverseCollapse: boolean | null | undefined;
|
|
147
147
|
|
|
148
|
+
/**
|
|
149
|
+
* If true, the top-level menu items is traversable by tab
|
|
150
|
+
* instead of arrow keys (i.e. disabling roving tabindex)
|
|
151
|
+
* @attr {boolean} tab-navigation
|
|
152
|
+
*/
|
|
153
|
+
tabNavigation: boolean | null | undefined;
|
|
154
|
+
|
|
148
155
|
/**
|
|
149
156
|
* Closes the current submenu.
|
|
150
157
|
*/
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { DisabledMixin } from '@vaadin/a11y-base/src/disabled-mixin.js';
|
|
7
7
|
import { FocusMixin } from '@vaadin/a11y-base/src/focus-mixin.js';
|
|
8
|
-
import { isElementFocused, isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
|
|
8
|
+
import { isElementFocused, isElementHidden, isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
|
|
9
9
|
import { KeyboardDirectionMixin } from '@vaadin/a11y-base/src/keyboard-direction-mixin.js';
|
|
10
10
|
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
|
|
11
11
|
import { ResizeMixin } from '@vaadin/component-base/src/resize-mixin.js';
|
|
@@ -144,6 +144,15 @@ export const MenuBarMixin = (superClass) =>
|
|
|
144
144
|
type: Boolean,
|
|
145
145
|
},
|
|
146
146
|
|
|
147
|
+
/**
|
|
148
|
+
* If true, the top-level menu items is traversable by tab
|
|
149
|
+
* instead of arrow keys (i.e. disabling roving tabindex)
|
|
150
|
+
* @attr {boolean} tab-navigation
|
|
151
|
+
*/
|
|
152
|
+
tabNavigation: {
|
|
153
|
+
type: Boolean,
|
|
154
|
+
},
|
|
155
|
+
|
|
147
156
|
/**
|
|
148
157
|
* @type {boolean}
|
|
149
158
|
* @protected
|
|
@@ -173,6 +182,7 @@ export const MenuBarMixin = (superClass) =>
|
|
|
173
182
|
'__i18nChanged(i18n, _overflow)',
|
|
174
183
|
'_menuItemsChanged(items, _overflow, _container)',
|
|
175
184
|
'_reverseCollapseChanged(reverseCollapse, _overflow, _container)',
|
|
185
|
+
'_tabNavigationChanged(tabNavigation, _overflow, _container)',
|
|
176
186
|
];
|
|
177
187
|
}
|
|
178
188
|
|
|
@@ -349,6 +359,22 @@ export const MenuBarMixin = (superClass) =>
|
|
|
349
359
|
}
|
|
350
360
|
}
|
|
351
361
|
|
|
362
|
+
/** @private */
|
|
363
|
+
_tabNavigationChanged(tabNavigation, overflow, container) {
|
|
364
|
+
if (overflow && container) {
|
|
365
|
+
const target = this.querySelector('[tabindex="0"]');
|
|
366
|
+
this._buttons.forEach((btn) => {
|
|
367
|
+
if (target) {
|
|
368
|
+
this._setTabindex(btn, btn === target);
|
|
369
|
+
} else {
|
|
370
|
+
this._setTabindex(btn, false);
|
|
371
|
+
}
|
|
372
|
+
btn.setAttribute('role', tabNavigation ? 'button' : 'menuitem');
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
this.setAttribute('role', tabNavigation ? 'group' : 'menubar');
|
|
376
|
+
}
|
|
377
|
+
|
|
352
378
|
/** @private */
|
|
353
379
|
__hasOverflowChanged(hasOverflow, overflow) {
|
|
354
380
|
if (overflow) {
|
|
@@ -540,7 +566,7 @@ export const MenuBarMixin = (superClass) =>
|
|
|
540
566
|
|
|
541
567
|
/** @protected */
|
|
542
568
|
_initButtonAttrs(button) {
|
|
543
|
-
button.setAttribute('role', 'menuitem');
|
|
569
|
+
button.setAttribute('role', this.tabNavigation ? 'button' : 'menuitem');
|
|
544
570
|
|
|
545
571
|
if (button === this._overflow || (button.item && button.item.children)) {
|
|
546
572
|
button.setAttribute('aria-haspopup', 'true');
|
|
@@ -667,7 +693,11 @@ export const MenuBarMixin = (superClass) =>
|
|
|
667
693
|
|
|
668
694
|
/** @protected */
|
|
669
695
|
_setTabindex(button, focused) {
|
|
670
|
-
|
|
696
|
+
if (this.tabNavigation && !button.disabled) {
|
|
697
|
+
button.setAttribute('tabindex', '0');
|
|
698
|
+
} else {
|
|
699
|
+
button.setAttribute('tabindex', focused ? '0' : '-1');
|
|
700
|
+
}
|
|
671
701
|
}
|
|
672
702
|
|
|
673
703
|
/**
|
|
@@ -715,7 +745,12 @@ export const MenuBarMixin = (superClass) =>
|
|
|
715
745
|
*/
|
|
716
746
|
_setFocused(focused) {
|
|
717
747
|
if (focused) {
|
|
718
|
-
|
|
748
|
+
let target = this.querySelector('[tabindex="0"]');
|
|
749
|
+
if (this.tabNavigation) {
|
|
750
|
+
// Switch submenu on menu button Tab / Shift Tab
|
|
751
|
+
target = this.querySelector('[focused]');
|
|
752
|
+
this.__switchSubMenu(target);
|
|
753
|
+
}
|
|
719
754
|
if (target) {
|
|
720
755
|
this._buttons.forEach((btn) => {
|
|
721
756
|
this._setTabindex(btn, btn === target);
|
|
@@ -839,6 +874,25 @@ export const MenuBarMixin = (superClass) =>
|
|
|
839
874
|
// Prevent ArrowLeft from being handled in context-menu
|
|
840
875
|
e.stopImmediatePropagation();
|
|
841
876
|
this._onKeyDown(e);
|
|
877
|
+
} else if (e.keyCode === 9 && this.tabNavigation) {
|
|
878
|
+
// Switch opened submenu on submenu item Tab / Shift Tab
|
|
879
|
+
const items = this._getItems() || [];
|
|
880
|
+
const currentIdx = items.indexOf(this.focused);
|
|
881
|
+
const increment = e.shiftKey ? -1 : 1;
|
|
882
|
+
let idx = currentIdx + increment;
|
|
883
|
+
idx = this._getAvailableIndex(items, idx, increment, (item) => !isElementHidden(item));
|
|
884
|
+
this.__switchSubMenu(items[idx]);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/** @private */
|
|
890
|
+
__switchSubMenu(target) {
|
|
891
|
+
const wasExpanded = this._expandedButton != null && this._expandedButton !== target;
|
|
892
|
+
if (wasExpanded) {
|
|
893
|
+
this._close();
|
|
894
|
+
if (target.item && target.item.children) {
|
|
895
|
+
this.__openSubMenu(target, true, { keepFocus: true });
|
|
842
896
|
}
|
|
843
897
|
}
|
|
844
898
|
}
|
|
@@ -878,14 +932,18 @@ export const MenuBarMixin = (superClass) =>
|
|
|
878
932
|
subMenu.items = items;
|
|
879
933
|
subMenu.listenOn = button;
|
|
880
934
|
const overlay = subMenu._overlayElement;
|
|
881
|
-
// Unset old positioning to prevent flashing.
|
|
882
|
-
overlay.removeAttribute('style');
|
|
883
|
-
overlay.positionTarget = undefined;
|
|
884
935
|
overlay.noVerticalOverlap = true;
|
|
885
936
|
|
|
886
937
|
this._expandedButton = button;
|
|
887
938
|
|
|
888
|
-
requestAnimationFrame(() => {
|
|
939
|
+
requestAnimationFrame(async () => {
|
|
940
|
+
// After changing items, buttons are recreated so the old button is
|
|
941
|
+
// no longer in the DOM. Reset position target to null to prevent
|
|
942
|
+
// overlay from closing due to target width / height equal to 0.
|
|
943
|
+
if (overlay.positionTarget && !overlay.positionTarget.isConnected) {
|
|
944
|
+
overlay.positionTarget = null;
|
|
945
|
+
}
|
|
946
|
+
|
|
889
947
|
button.dispatchEvent(
|
|
890
948
|
new CustomEvent('opensubmenu', {
|
|
891
949
|
detail: {
|
|
@@ -896,6 +954,14 @@ export const MenuBarMixin = (superClass) =>
|
|
|
896
954
|
this._hideTooltip(true);
|
|
897
955
|
|
|
898
956
|
this._setExpanded(button, true);
|
|
957
|
+
|
|
958
|
+
// Delay setting position target until overlay is rendered
|
|
959
|
+
// to correctly measure item content in Lit based version.
|
|
960
|
+
if (overlay.updateComplete) {
|
|
961
|
+
await overlay.updateComplete;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
overlay.positionTarget = button;
|
|
899
965
|
});
|
|
900
966
|
|
|
901
967
|
this.style.pointerEvents = 'auto';
|
|
@@ -915,11 +981,6 @@ export const MenuBarMixin = (superClass) =>
|
|
|
915
981
|
if (!keydown) {
|
|
916
982
|
overlay.$.overlay.focus();
|
|
917
983
|
}
|
|
918
|
-
|
|
919
|
-
// Delay setting position target until overlay is rendered
|
|
920
|
-
// to correctly measure item content in Lit based version.
|
|
921
|
-
overlay.positionTarget = button;
|
|
922
|
-
overlay._updatePosition();
|
|
923
984
|
},
|
|
924
985
|
{ once: true },
|
|
925
986
|
);
|
|
@@ -4,6 +4,10 @@ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themab
|
|
|
4
4
|
registerStyles(
|
|
5
5
|
'vaadin-menu-bar',
|
|
6
6
|
css`
|
|
7
|
+
:host {
|
|
8
|
+
min-width: var(--lumo-size-m);
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
:host([has-single-button]) ::slotted(vaadin-menu-bar-button) {
|
|
8
12
|
border-radius: var(--lumo-border-radius-m);
|
|
9
13
|
}
|
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.5.0-
|
|
4
|
+
"version": "24.5.0-alpha11",
|
|
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.5.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/24.5.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.5.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.5.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.5.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.5.0-alpha11/#/elements/vaadin-overlay).",
|
|
12
12
|
"attributes": [
|
|
13
13
|
{
|
|
14
14
|
"name": "disabled",
|
|
@@ -54,6 +54,17 @@
|
|
|
54
54
|
]
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
|
+
{
|
|
58
|
+
"name": "tab-navigation",
|
|
59
|
+
"description": "If true, the top-level menu items is traversable by tab\ninstead of arrow keys (i.e. disabling roving tabindex)",
|
|
60
|
+
"value": {
|
|
61
|
+
"type": [
|
|
62
|
+
"boolean",
|
|
63
|
+
"null",
|
|
64
|
+
"undefined"
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
},
|
|
57
68
|
{
|
|
58
69
|
"name": "theme",
|
|
59
70
|
"description": "The theme variants to apply to the component.",
|
|
@@ -129,6 +140,17 @@
|
|
|
129
140
|
"undefined"
|
|
130
141
|
]
|
|
131
142
|
}
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"name": "tabNavigation",
|
|
146
|
+
"description": "If true, the top-level menu items is traversable by tab\ninstead of arrow keys (i.e. disabling roving tabindex)",
|
|
147
|
+
"value": {
|
|
148
|
+
"type": [
|
|
149
|
+
"boolean",
|
|
150
|
+
"null",
|
|
151
|
+
"undefined"
|
|
152
|
+
]
|
|
153
|
+
}
|
|
132
154
|
}
|
|
133
155
|
],
|
|
134
156
|
"events": [
|
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": "24.5.0-
|
|
4
|
+
"version": "24.5.0-alpha11",
|
|
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.5.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/24.5.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.5.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.5.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.5.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.5.0-alpha11/#/elements/vaadin-overlay).",
|
|
20
20
|
"extension": true,
|
|
21
21
|
"attributes": [
|
|
22
22
|
{
|
|
@@ -40,6 +40,13 @@
|
|
|
40
40
|
"kind": "expression"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
+
{
|
|
44
|
+
"name": "?tabNavigation",
|
|
45
|
+
"description": "If true, the top-level menu items is traversable by tab\ninstead of arrow keys (i.e. disabling roving tabindex)",
|
|
46
|
+
"value": {
|
|
47
|
+
"kind": "expression"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
43
50
|
{
|
|
44
51
|
"name": ".items",
|
|
45
52
|
"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```",
|