@vaadin/menu-bar 24.4.6 → 24.5.0-alpha10

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 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/overview) to learn about our development process, how to propose bugfixes and improvements, and how to test your changes to Vaadin components.
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.4.6",
3
+ "version": "24.5.0-alpha10",
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.4.6",
43
- "@vaadin/button": "~24.4.6",
44
- "@vaadin/component-base": "~24.4.6",
45
- "@vaadin/context-menu": "~24.4.6",
46
- "@vaadin/item": "~24.4.6",
47
- "@vaadin/list-box": "~24.4.6",
48
- "@vaadin/overlay": "~24.4.6",
49
- "@vaadin/vaadin-lumo-styles": "~24.4.6",
50
- "@vaadin/vaadin-material-styles": "~24.4.6",
51
- "@vaadin/vaadin-themable-mixin": "~24.4.6",
42
+ "@vaadin/a11y-base": "24.5.0-alpha10",
43
+ "@vaadin/button": "24.5.0-alpha10",
44
+ "@vaadin/component-base": "24.5.0-alpha10",
45
+ "@vaadin/context-menu": "24.5.0-alpha10",
46
+ "@vaadin/item": "24.5.0-alpha10",
47
+ "@vaadin/list-box": "24.5.0-alpha10",
48
+ "@vaadin/overlay": "24.5.0-alpha10",
49
+ "@vaadin/vaadin-lumo-styles": "24.5.0-alpha10",
50
+ "@vaadin/vaadin-material-styles": "24.5.0-alpha10",
51
+ "@vaadin/vaadin-themable-mixin": "24.5.0-alpha10",
52
52
  "lit": "^3.0.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@esm-bundle/chai": "^4.3.4",
56
- "@vaadin/icon": "~24.4.6",
57
- "@vaadin/testing-helpers": "^0.6.0",
58
- "sinon": "^13.0.2"
55
+ "@vaadin/chai-plugins": "24.5.0-alpha10",
56
+ "@vaadin/icon": "24.5.0-alpha10",
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": "46d3cdb72eb99d544c7bb86c3de95043b9e5857f"
64
+ "gitHead": "6f9c37308031af872a98017bfab4de89aeacda51"
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
- button.setAttribute('tabindex', focused ? '0' : '-1');
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
- const target = this.querySelector('[tabindex="0"]');
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
  }
@@ -79,6 +79,32 @@ const menuBarButton = css`
79
79
  margin-right: 0;
80
80
  }
81
81
 
82
+ :host([theme~='dropdown-indicators']:not([slot='overflow']):not([theme~='icon'])[aria-haspopup]) [part='suffix'] {
83
+ margin-inline-start: 0;
84
+ width: 1em;
85
+ height: 1em;
86
+ line-height: 1;
87
+ font-size: var(--lumo-icon-size-s);
88
+ position: relative;
89
+ inset-inline-start: 0.15em;
90
+ }
91
+
92
+ /* prettier-ignore */
93
+ :host([theme~='dropdown-indicators']:not([slot='overflow']):not([theme~='icon'])[aria-haspopup]) [part='suffix']::after {
94
+ font-family: lumo-icons;
95
+ content: var(--lumo-icons-dropdown);
96
+ }
97
+
98
+ /* prettier-ignore */
99
+ :host([theme~='dropdown-indicators']:not([slot='overflow']):not([theme~='icon'])[theme~='tertiary'][aria-haspopup]) [part='suffix'] {
100
+ inset-inline-start: 0.05em;
101
+ }
102
+
103
+ /* prettier-ignore */
104
+ :host([theme~='dropdown-indicators']:not([slot='overflow']):not([theme~='icon'])[theme~='tertiary-inline'][aria-haspopup]) [part='suffix'] {
105
+ inset-inline-start: 0;
106
+ }
107
+
82
108
  /* RTL styles */
83
109
  :host([dir='rtl']) {
84
110
  margin-left: calc(var(--lumo-space-xs) / 2);
@@ -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.4.6",
4
+ "version": "24.5.0-alpha10",
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.6/#/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.6/#/elements/vaadin-button).\n- `<vaadin-menu-bar-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/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.6/#/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.6/#/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.5.0-alpha10/#/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-alpha10/#/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-alpha10/#/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-alpha10/#/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-alpha10/#/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": [
@@ -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.6",
4
+ "version": "24.5.0-alpha10",
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.6/#/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.6/#/elements/vaadin-button).\n- `<vaadin-menu-bar-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/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.6/#/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.6/#/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.5.0-alpha10/#/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-alpha10/#/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-alpha10/#/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-alpha10/#/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-alpha10/#/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```",