@vaadin/menu-bar 23.2.0-dev.8a7678b70 → 23.3.0-alpha1

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  A web component for creating a horizontal button bar with hierarchical drop-down menus.
4
4
 
5
- [Documentation + Live Demo ↗](https://vaadin.com/docs/latest/ds/components/menu-bar)
5
+ [Documentation + Live Demo ↗](https://vaadin.com/docs/latest/components/menu-bar)
6
6
 
7
7
  [![npm version](https://badgen.net/npm/v/@vaadin/menu-bar)](https://www.npmjs.com/package/@vaadin/menu-bar)
8
8
  [![Discord](https://img.shields.io/discord/732335336448852018?label=discord)](https://discord.gg/PHmkCKC)
@@ -23,7 +23,7 @@ A web component for creating a horizontal button bar with hierarchical drop-down
23
23
  </script>
24
24
  ```
25
25
 
26
- [<img src="https://raw.githubusercontent.com/vaadin/web-components/master/packages/menu-bar/screenshot.png" width="345" alt="Screenshot of vaadin-menu-bar">](https://vaadin.com/docs/latest/ds/components/menu-bar)
26
+ [<img src="https://raw.githubusercontent.com/vaadin/web-components/master/packages/menu-bar/screenshot.png" width="345" alt="Screenshot of vaadin-menu-bar">](https://vaadin.com/docs/latest/components/menu-bar)
27
27
 
28
28
  ## Installation
29
29
 
@@ -41,7 +41,7 @@ import '@vaadin/menu-bar';
41
41
 
42
42
  ## Themes
43
43
 
44
- Vaadin components come with two built-in [themes](https://vaadin.com/docs/latest/ds/customization/using-themes), Lumo and Material.
44
+ Vaadin components come with two built-in [themes](https://vaadin.com/docs/latest/styling), Lumo and Material.
45
45
  The [main entrypoint](https://github.com/vaadin/web-components/blob/master/packages/menu-bar/vaadin-menu-bar.js) of the package uses the Lumo theme.
46
46
 
47
47
  To use the Material theme, import the component from the `theme/material` folder:
@@ -64,7 +64,7 @@ import '@vaadin/menu-bar/src/vaadin-menu-bar.js';
64
64
 
65
65
  ## Contributing
66
66
 
67
- Read the [contributing guide](https://vaadin.com/docs/latest/guide/contributing/overview) to learn about our development process, how to propose bugfixes and improvements, and how to test your changes to Vaadin components.
67
+ 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.
68
68
 
69
69
  ## License
70
70
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/menu-bar",
3
- "version": "23.2.0-dev.8a7678b70",
3
+ "version": "23.3.0-alpha1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -23,7 +23,9 @@
23
23
  "src",
24
24
  "theme",
25
25
  "vaadin-*.d.ts",
26
- "vaadin-*.js"
26
+ "vaadin-*.js",
27
+ "web-types.json",
28
+ "web-types.lit.json"
27
29
  ],
28
30
  "keywords": [
29
31
  "Vaadin",
@@ -35,18 +37,22 @@
35
37
  "dependencies": {
36
38
  "@open-wc/dedupe-mixin": "^1.3.0",
37
39
  "@polymer/polymer": "^3.0.0",
38
- "@vaadin/button": "23.2.0-dev.8a7678b70",
39
- "@vaadin/component-base": "23.2.0-dev.8a7678b70",
40
- "@vaadin/vaadin-context-menu": "23.2.0-dev.8a7678b70",
41
- "@vaadin/vaadin-lumo-styles": "23.2.0-dev.8a7678b70",
42
- "@vaadin/vaadin-material-styles": "23.2.0-dev.8a7678b70",
43
- "@vaadin/vaadin-themable-mixin": "23.2.0-dev.8a7678b70"
40
+ "@vaadin/button": "23.3.0-alpha1",
41
+ "@vaadin/component-base": "23.3.0-alpha1",
42
+ "@vaadin/context-menu": "23.3.0-alpha1",
43
+ "@vaadin/vaadin-lumo-styles": "23.3.0-alpha1",
44
+ "@vaadin/vaadin-material-styles": "23.3.0-alpha1",
45
+ "@vaadin/vaadin-themable-mixin": "23.3.0-alpha1"
44
46
  },
45
47
  "devDependencies": {
46
48
  "@esm-bundle/chai": "^4.3.4",
47
- "@vaadin/icon": "23.2.0-dev.8a7678b70",
49
+ "@vaadin/icon": "23.3.0-alpha1",
48
50
  "@vaadin/testing-helpers": "^0.3.2",
49
51
  "sinon": "^13.0.2"
50
52
  },
51
- "gitHead": "85b403f96d8282f262322b56c0ff4289f843d02a"
53
+ "web-types": [
54
+ "web-types.json",
55
+ "web-types.lit.json"
56
+ ],
57
+ "gitHead": "beabc527d4b1274eb798ff701d406fed45cfe638"
52
58
  }
@@ -3,12 +3,12 @@
3
3
  * Copyright (c) 2019 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { Constructor } from '@open-wc/dedupe-mixin';
7
- import { ResizeMixinClass } from '@vaadin/component-base/src/resize-mixin.js';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { ResizeMixinClass } from '@vaadin/component-base/src/resize-mixin.js';
8
8
 
9
9
  export declare function ButtonsMixin<T extends Constructor<HTMLElement>>(
10
10
  base: T,
11
- ): T & Constructor<ButtonsMixinClass> & Constructor<ResizeMixinClass>;
11
+ ): Constructor<ButtonsMixinClass> & Constructor<ResizeMixinClass> & T;
12
12
 
13
13
  export declare class ButtonsMixinClass {
14
14
  protected readonly _buttons: HTMLElement[];
@@ -163,6 +163,9 @@ export const ButtonsMixin = (superClass) =>
163
163
  if (oldOverflowCount !== newOverflowCount && this._subMenu.opened) {
164
164
  this._subMenu.close();
165
165
  }
166
+
167
+ const isSingleButton = newOverflowCount === buttons.length || (newOverflowCount === 0 && buttons.length === 1);
168
+ this.toggleAttribute('has-single-button', isSingleButton);
166
169
  }
167
170
 
168
171
  /** @protected */
@@ -3,11 +3,18 @@
3
3
  * Copyright (c) 2019 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { Constructor } from '@open-wc/dedupe-mixin';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
8
+ import type { KeyboardDirectionMixinClass } from '@vaadin/component-base/src/keyboard-direction-mixin.js';
9
+ import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
7
10
 
8
11
  export declare function InteractionsMixin<T extends Constructor<HTMLElement>>(
9
12
  base: T,
10
- ): T & Constructor<InteractionsMixinClass>;
13
+ ): Constructor<FocusMixinClass> &
14
+ Constructor<InteractionsMixinClass> &
15
+ Constructor<KeyboardDirectionMixinClass> &
16
+ Constructor<KeyboardMixinClass> &
17
+ T;
11
18
 
12
19
  export declare class InteractionsMixinClass {
13
20
  /**
@@ -3,12 +3,17 @@
3
3
  * Copyright (c) 2019 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js';
7
+ import { isKeyboardActive } from '@vaadin/component-base/src/focus-utils.js';
8
+ import { KeyboardDirectionMixin } from '@vaadin/component-base/src/keyboard-direction-mixin.js';
6
9
 
7
10
  /**
8
11
  * @polymerMixin
12
+ * @mixes FocusMixin
13
+ * @mixes KeyboardDirectionMixinClass
9
14
  */
10
15
  export const InteractionsMixin = (superClass) =>
11
- class InteractionsMixin extends superClass {
16
+ class InteractionsMixin extends KeyboardDirectionMixin(FocusMixin(superClass)) {
12
17
  static get properties() {
13
18
  return {
14
19
  /**
@@ -34,8 +39,8 @@ export const InteractionsMixin = (superClass) =>
34
39
  ready() {
35
40
  super.ready();
36
41
 
37
- this.addEventListener('keydown', (e) => this._onKeydown(e));
38
- this.addEventListener('focusin', (e) => this._onFocusin(e));
42
+ this.addEventListener('mousedown', () => this._hideTooltip());
43
+ this.addEventListener('mouseleave', () => this._hideTooltip());
39
44
 
40
45
  this._subMenu.addEventListener('item-selected', this.__onItemSelected.bind(this));
41
46
  this._subMenu.addEventListener('close-all-menus', this.__onEscapeClose.bind(this));
@@ -49,11 +54,71 @@ export const InteractionsMixin = (superClass) =>
49
54
  container.addEventListener('mouseover', (e) => this._onMouseOver(e));
50
55
  }
51
56
 
57
+ /**
58
+ * Override getter from `KeyboardDirectionMixin`
59
+ * to look for activeElement in shadow root, or
60
+ * use the expanded button as a fallback.
61
+ *
62
+ * @return {Element | null}
63
+ * @protected
64
+ * @override
65
+ */
66
+ get focused() {
67
+ return this.shadowRoot.activeElement || this._expandedButton;
68
+ }
69
+
70
+ /**
71
+ * Override getter from `KeyboardDirectionMixin`.
72
+ *
73
+ * @return {boolean}
74
+ * @protected
75
+ * @override
76
+ */
77
+ get _vertical() {
78
+ return false;
79
+ }
80
+
81
+ /**
82
+ * Override method inherited from `KeyboardDirectionMixin`
83
+ * to use the list of menu-bar buttons as items.
84
+ *
85
+ * @return {Element[]}
86
+ * @protected
87
+ * @override
88
+ */
89
+ _getItems() {
90
+ return this._buttons;
91
+ }
92
+
52
93
  /** @private */
53
94
  get __isRTL() {
54
95
  return this.getAttribute('dir') === 'rtl';
55
96
  }
56
97
 
98
+ /** @protected */
99
+ disconnectedCallback() {
100
+ super.disconnectedCallback();
101
+ this._hideTooltip();
102
+ }
103
+
104
+ /**
105
+ * @param {HTMLElement} button
106
+ * @protected
107
+ */
108
+ _showTooltip(button) {
109
+ // Check if there is a slotted vaadin-tooltip element.
110
+ if (this._tooltipController.node && this._tooltipController.node.isConnected && !this._subMenu.opened) {
111
+ this._tooltipController.setTarget(button);
112
+ this._tooltipController.setContext({ item: button.item });
113
+ this._tooltipController.setOpened(true);
114
+ }
115
+ }
116
+
117
+ /** @protected */
118
+ _hideTooltip() {
119
+ this._tooltipController.setOpened(false);
120
+ }
121
+
57
122
  /** @protected */
58
123
  _setExpanded(button, expanded) {
59
124
  button.toggleAttribute('expanded', expanded);
@@ -66,135 +131,135 @@ export const InteractionsMixin = (superClass) =>
66
131
  button.setAttribute('tabindex', focused ? '0' : '-1');
67
132
  }
68
133
 
69
- /** @private */
70
- _focusButton(button) {
71
- button.focus();
72
- button.setAttribute('focus-ring', '');
134
+ /**
135
+ * Override method inherited from `KeyboardDirectionMixin`
136
+ * to close the submenu for the previously focused button
137
+ * and open another one for the newly focused button.
138
+ *
139
+ * @param {Element} item
140
+ * @param {boolean} navigating
141
+ * @protected
142
+ * @override
143
+ */
144
+ _focusItem(item, navigating) {
145
+ const wasExpanded = navigating && this.focused === this._expandedButton;
146
+ if (wasExpanded) {
147
+ this._close();
148
+ }
149
+
150
+ super._focusItem(item, navigating);
151
+
73
152
  this._buttons.forEach((btn) => {
74
- this._setTabindex(btn, btn === button);
153
+ this._setTabindex(btn, btn === item);
75
154
  });
76
- }
77
155
 
78
- /** @private */
79
- _getButtonFromEvent(e) {
80
- return Array.from(e.composedPath()).filter((el) => el.localName === 'vaadin-menu-bar-button')[0];
156
+ if (wasExpanded && item.item && item.item.children) {
157
+ this.__openSubMenu(item, true, { keepFocus: true });
158
+ } else if (item === this._overflow) {
159
+ this._hideTooltip();
160
+ } else {
161
+ this._showTooltip(item);
162
+ }
81
163
  }
82
164
 
83
165
  /** @private */
84
- _getCurrentButton() {
85
- return this.shadowRoot.activeElement || this._expandedButton;
166
+ _getButtonFromEvent(e) {
167
+ return Array.from(e.composedPath()).find((el) => el.localName === 'vaadin-menu-bar-button');
86
168
  }
87
169
 
88
170
  /**
89
- * @param {!FocusEvent} event
171
+ * Override method inherited from `FocusMixin`
172
+ *
173
+ * @param {boolean} focused
174
+ * @override
90
175
  * @protected
91
176
  */
92
- _onFocusin() {
93
- const target = this.shadowRoot.querySelector('[part$="button"][tabindex="0"]');
94
- if (target) {
95
- this._buttons.forEach((btn) => {
96
- this._setTabindex(btn, btn === target);
97
- });
177
+ _setFocused(focused) {
178
+ if (focused) {
179
+ const target = this.shadowRoot.querySelector('[part$="button"][tabindex="0"]');
180
+ if (target) {
181
+ this._buttons.forEach((btn) => {
182
+ this._setTabindex(btn, btn === target);
183
+ if (btn === target && btn !== this._overflow && isKeyboardActive()) {
184
+ this._showTooltip(btn);
185
+ }
186
+ });
187
+ }
188
+ } else {
189
+ this._hideTooltip();
98
190
  }
99
191
  }
100
192
 
101
193
  /**
102
194
  * @param {!KeyboardEvent} event
103
- * @protected
195
+ * @private
104
196
  */
105
- _onKeydown(event) {
197
+ _onArrowDown(event) {
198
+ // Prevent page scroll.
199
+ event.preventDefault();
200
+
106
201
  const button = this._getButtonFromEvent(event);
107
- if (button) {
108
- if (event.keyCode === 40) {
109
- // ArrowDown, prevent page scroll
110
- event.preventDefault();
111
- if (button === this._expandedButton) {
112
- // Menu opened previously, focus first item
113
- this._focusFirstItem();
114
- } else {
115
- this.__openSubMenu(button, event);
116
- }
117
- } else if (event.keyCode === 38) {
118
- // ArrowUp, prevent page scroll
119
- event.preventDefault();
120
- if (button === this._expandedButton) {
121
- // Menu opened previously, focus last item
122
- this._focusLastItem();
123
- } else {
124
- this.__openSubMenu(button, event, { focusLast: true });
125
- }
126
- } else if (event.keyCode === 27 && button === this._expandedButton) {
127
- this._close(true);
128
- } else {
129
- this._navigateByKey(event);
130
- }
202
+ if (button === this._expandedButton) {
203
+ // Menu opened previously, focus first item
204
+ this._focusFirstItem();
205
+ } else {
206
+ this.__openSubMenu(button, true);
131
207
  }
132
208
  }
133
209
 
134
- /** @private */
135
- _navigateByKey(event) {
136
- // IE names for arrows do not include the Arrow prefix
137
- const key = event.key.replace(/^Arrow/, '');
138
- const buttons = this._buttons;
139
- const currentBtn = this._getCurrentButton();
140
- const currentIdx = buttons.indexOf(currentBtn);
141
- let idx;
142
- let increment;
143
- const dirIncrement = this.__isRTL ? -1 : 1;
144
-
145
- switch (key) {
146
- case 'Left':
147
- increment = -dirIncrement;
148
- idx = currentIdx - dirIncrement;
149
- break;
150
- case 'Right':
151
- increment = dirIncrement;
152
- idx = currentIdx + dirIncrement;
153
- break;
154
- case 'Home':
155
- increment = 1;
156
- idx = 0;
157
- break;
158
- case 'End':
159
- increment = -1;
160
- idx = buttons.length - 1;
161
- break;
162
- default:
163
- // Do nothing.
164
- }
210
+ /**
211
+ * @param {!KeyboardEvent} event
212
+ * @private
213
+ */
214
+ _onArrowUp(event) {
215
+ // Prevent page scroll.
216
+ event.preventDefault();
165
217
 
166
- idx = this._getAvailableIndex(idx, increment, buttons);
167
- if (idx >= 0) {
168
- event.preventDefault();
169
- const btn = buttons[idx];
170
- const wasExpanded = currentBtn === this._expandedButton;
171
- if (wasExpanded) {
172
- this._close();
173
- }
174
- this._focusButton(btn);
175
- if (wasExpanded && btn.item && btn.item.children) {
176
- this.__openSubMenu(btn, event, { keepFocus: true });
177
- }
218
+ const button = this._getButtonFromEvent(event);
219
+ if (button === this._expandedButton) {
220
+ // Menu opened previously, focus last item
221
+ this._focusLastItem();
222
+ } else {
223
+ this.__openSubMenu(button, true, { focusLast: true });
178
224
  }
179
225
  }
180
226
 
181
- /** @private */
182
- _getAvailableIndex(index, increment, buttons) {
183
- const totalItems = buttons.length;
184
- let idx = index;
185
- for (let i = 0; typeof idx === 'number' && i < totalItems; i++, idx += increment || 1) {
186
- if (idx < 0) {
187
- idx = totalItems - 1;
188
- } else if (idx >= totalItems) {
189
- idx = 0;
190
- }
227
+ /**
228
+ * Override an event listener from `KeyboardMixin`:
229
+ * - to close the sub-menu for expanded button,
230
+ * - to close a tooltip for collapsed button.
231
+ *
232
+ * @param {!KeyboardEvent} event
233
+ * @protected
234
+ * @override
235
+ */
236
+ _onEscape(event) {
237
+ if (event.composedPath().includes(this._expandedButton)) {
238
+ this._close(true);
239
+ }
191
240
 
192
- const btn = buttons[idx];
193
- if (!btn.disabled && !btn.hasAttribute('hidden')) {
194
- return idx;
195
- }
241
+ this._hideTooltip();
242
+ }
243
+
244
+ /**
245
+ * Override an event listener from `KeyboardMixin`.
246
+ *
247
+ * @param {!KeyboardEvent} event
248
+ * @protected
249
+ * @override
250
+ */
251
+ _onKeyDown(event) {
252
+ switch (event.key) {
253
+ case 'ArrowDown':
254
+ this._onArrowDown(event);
255
+ break;
256
+ case 'ArrowUp':
257
+ this._onArrowUp(event);
258
+ break;
259
+ default:
260
+ super._onKeyDown(event);
261
+ break;
196
262
  }
197
- return -1;
198
263
  }
199
264
 
200
265
  /** @private */
@@ -243,16 +308,22 @@ export const InteractionsMixin = (superClass) =>
243
308
  if (button && button !== this._expandedButton) {
244
309
  const isOpened = this._subMenu.opened;
245
310
  if (button.item.children && (this.openOnHover || isOpened)) {
246
- this.__openSubMenu(button, e);
311
+ this.__openSubMenu(button, false);
247
312
  } else if (isOpened) {
248
313
  this._close();
249
314
  }
315
+
316
+ if (button === this._overflow || (this.openOnHover && button.item.children)) {
317
+ this._hideTooltip();
318
+ } else {
319
+ this._showTooltip(button);
320
+ }
250
321
  }
251
322
  }
252
323
 
253
324
  /** @private */
254
325
  __onContextMenuKeydown(e) {
255
- const item = Array.from(e.composedPath()).filter((el) => el._item)[0];
326
+ const item = Array.from(e.composedPath()).find((el) => el._item);
256
327
  if (item) {
257
328
  const list = item.parentNode;
258
329
  if (e.keyCode === 38 && item === list.items[0]) {
@@ -262,11 +333,7 @@ export const InteractionsMixin = (superClass) =>
262
333
  if (e.keyCode === 37 || (e.keyCode === 39 && !item._item.children)) {
263
334
  // Prevent ArrowLeft from being handled in context-menu
264
335
  e.stopImmediatePropagation();
265
- this._navigateByKey(e);
266
- const button = this.shadowRoot.activeElement;
267
- if (button && button.item && button.item.children) {
268
- this.__openSubMenu(button, e, { keepFocus: true });
269
- }
336
+ this._onKeyDown(e);
270
337
  }
271
338
  }
272
339
  }
@@ -281,12 +348,12 @@ export const InteractionsMixin = (superClass) =>
281
348
  e.stopPropagation();
282
349
  const button = this._getButtonFromEvent(e);
283
350
  if (button) {
284
- this.__openSubMenu(button, e);
351
+ this.__openSubMenu(button, false);
285
352
  }
286
353
  }
287
354
 
288
355
  /** @private */
289
- __openSubMenu(button, event, options = {}) {
356
+ __openSubMenu(button, keydown, options = {}) {
290
357
  const subMenu = this._subMenu;
291
358
  const item = button.item;
292
359
 
@@ -319,27 +386,33 @@ export const InteractionsMixin = (superClass) =>
319
386
  },
320
387
  }),
321
388
  );
389
+ this._hideTooltip();
322
390
 
323
391
  this._setExpanded(button, true);
324
392
  });
325
393
 
326
- if (options.focusLast) {
327
- this.__onceOpened(() => this._focusLastItem());
328
- }
394
+ this.style.pointerEvents = 'auto';
329
395
 
330
- if (options.keepFocus) {
331
- this.__onceOpened(() => {
332
- this._focusButton(this._expandedButton);
333
- });
334
- }
396
+ overlay.addEventListener(
397
+ 'vaadin-overlay-open',
398
+ () => {
399
+ if (options.focusLast) {
400
+ this._focusLastItem();
401
+ }
335
402
 
336
- this.__onceOpened(() => {
337
- // Do not focus item when open not from keyboard
338
- if (event.type !== 'keydown') {
339
- subMenu.$.overlay.$.overlay.focus();
340
- }
341
- overlay._updatePosition();
342
- });
403
+ if (options.keepFocus) {
404
+ this._focusItem(this._expandedButton, false);
405
+ }
406
+
407
+ // Do not focus item when open not from keyboard
408
+ if (!keydown) {
409
+ overlay.$.overlay.focus();
410
+ }
411
+
412
+ overlay._updatePosition();
413
+ },
414
+ { once: true },
415
+ );
343
416
  }
344
417
 
345
418
  /** @private */
@@ -357,17 +430,6 @@ export const InteractionsMixin = (superClass) =>
357
430
  }
358
431
  }
359
432
 
360
- /** @private */
361
- __onceOpened(cb) {
362
- this.style.pointerEvents = 'auto';
363
- const overlay = this._subMenu.$.overlay;
364
- const listener = () => {
365
- cb();
366
- overlay.removeEventListener('vaadin-overlay-open', listener);
367
- };
368
- overlay.addEventListener('vaadin-overlay-open', listener);
369
- }
370
-
371
433
  /** @private */
372
434
  __onItemSelected(e) {
373
435
  e.stopPropagation();
@@ -386,7 +448,7 @@ export const InteractionsMixin = (superClass) =>
386
448
  if (button && button.hasAttribute('expanded')) {
387
449
  this._setExpanded(button, false);
388
450
  if (restoreFocus) {
389
- this._focusButton(button);
451
+ this._focusItem(button, false);
390
452
  }
391
453
  this._expandedButton = null;
392
454
  }
@@ -3,7 +3,7 @@
3
3
  * Copyright (c) 2019 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { ContextMenu } from '@vaadin/vaadin-context-menu/src/vaadin-context-menu.js';
6
+ import { ContextMenu } from '@vaadin/context-menu/src/vaadin-context-menu.js';
7
7
 
8
8
  /**
9
9
  * An element used internally by `<vaadin-menu-bar>`. Not intended to be used separately.
@@ -3,6 +3,7 @@
3
3
  * Copyright (c) 2019 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
6
7
  import { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js';
7
8
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
8
9
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
@@ -11,17 +12,17 @@ import { InteractionsMixin } from './vaadin-menu-bar-interactions-mixin.js';
11
12
 
12
13
  export interface MenuBarItem {
13
14
  text?: string;
14
- component?: string | HTMLElement;
15
+ component?: HTMLElement | string;
15
16
  disabled?: boolean;
16
- theme?: string | string[];
17
+ theme?: string[] | string;
17
18
  children?: SubMenuItem[];
18
19
  }
19
20
 
20
21
  export interface SubMenuItem {
21
22
  text?: string;
22
- component?: string | HTMLElement;
23
+ component?: HTMLElement | string;
23
24
  disabled?: boolean;
24
- theme?: string | string[];
25
+ theme?: string[] | string;
25
26
  checked?: boolean;
26
27
  children?: SubMenuItem[];
27
28
  }
@@ -68,7 +69,14 @@ export interface MenuBarEventMap extends HTMLElementEventMap, MenuBarCustomEvent
68
69
  * `menu-bar-button` | The menu bar button.
69
70
  * `overflow-button` | The "overflow" button appearing when menu bar width is not enough to fit all the buttons.
70
71
  *
71
- * See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
72
+ * The following state attributes are available for styling:
73
+ *
74
+ * Attribute | Description
75
+ * --------------------|----------------------------------
76
+ * `disabled` | Set when the menu bar is disabled
77
+ * `has-single-button` | Set when there is only one button visible
78
+ *
79
+ * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
72
80
  *
73
81
  * ### Internal components
74
82
  *
@@ -82,7 +90,9 @@ export interface MenuBarEventMap extends HTMLElementEventMap, MenuBarCustomEvent
82
90
  *
83
91
  * @fires {CustomEvent} item-selected - Fired when a submenu item or menu bar button without children is clicked.
84
92
  */
85
- declare class MenuBar extends ButtonsMixin(DisabledMixin(InteractionsMixin(ElementMixin(ThemableMixin(HTMLElement))))) {
93
+ declare class MenuBar extends ButtonsMixin(
94
+ DisabledMixin(InteractionsMixin(ElementMixin(ThemableMixin(ControllerMixin(HTMLElement))))),
95
+ ) {
86
96
  /**
87
97
  * Defines a hierarchical structure, where root level items represent menu bar buttons,
88
98
  * and `children` property configures a submenu with items to be opened below
@@ -138,13 +148,13 @@ declare class MenuBar extends ButtonsMixin(DisabledMixin(InteractionsMixin(Eleme
138
148
  addEventListener<K extends keyof MenuBarEventMap>(
139
149
  type: K,
140
150
  listener: (this: MenuBar, ev: MenuBarEventMap[K]) => void,
141
- options?: boolean | AddEventListenerOptions,
151
+ options?: AddEventListenerOptions | boolean,
142
152
  ): void;
143
153
 
144
154
  removeEventListener<K extends keyof MenuBarEventMap>(
145
155
  type: K,
146
156
  listener: (this: MenuBar, ev: MenuBarEventMap[K]) => void,
147
- options?: boolean | EventListenerOptions,
157
+ options?: EventListenerOptions | boolean,
148
158
  ): void;
149
159
 
150
160
  /**
@@ -6,8 +6,10 @@
6
6
  import './vaadin-menu-bar-submenu.js';
7
7
  import './vaadin-menu-bar-button.js';
8
8
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
9
+ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
9
10
  import { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js';
10
11
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
12
+ import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js';
11
13
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
12
14
  import { ButtonsMixin } from './vaadin-menu-bar-buttons-mixin.js';
13
15
  import { InteractionsMixin } from './vaadin-menu-bar-interactions-mixin.js';
@@ -39,7 +41,14 @@ import { InteractionsMixin } from './vaadin-menu-bar-interactions-mixin.js';
39
41
  * `menu-bar-button` | The menu bar button.
40
42
  * `overflow-button` | The "overflow" button appearing when menu bar width is not enough to fit all the buttons.
41
43
  *
42
- * See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
44
+ * The following state attributes are available for styling:
45
+ *
46
+ * Attribute | Description
47
+ * --------------------|----------------------------------
48
+ * `disabled` | Set when the menu bar is disabled
49
+ * `has-single-button` | Set when there is only one button visible
50
+ *
51
+ * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
43
52
  *
44
53
  * ### Internal components
45
54
  *
@@ -54,12 +63,16 @@ import { InteractionsMixin } from './vaadin-menu-bar-interactions-mixin.js';
54
63
  * @fires {CustomEvent<boolean>} item-selected - Fired when a submenu item or menu bar button without children is clicked.
55
64
  *
56
65
  * @extends HTMLElement
66
+ * @mixes ControllerMixin
57
67
  * @mixes ButtonsMixin
58
68
  * @mixes InteractionsMixin
69
+ * @mixes DisabledMixin
59
70
  * @mixes ElementMixin
60
71
  * @mixes ThemableMixin
61
72
  */
62
- class MenuBar extends ButtonsMixin(DisabledMixin(InteractionsMixin(ElementMixin(ThemableMixin(PolymerElement))))) {
73
+ class MenuBar extends ButtonsMixin(
74
+ DisabledMixin(InteractionsMixin(ElementMixin(ThemableMixin(ControllerMixin(PolymerElement))))),
75
+ ) {
63
76
  static get template() {
64
77
  return html`
65
78
  <style>
@@ -101,6 +114,8 @@ class MenuBar extends ButtonsMixin(DisabledMixin(InteractionsMixin(ElementMixin(
101
114
  </vaadin-menu-bar-button>
102
115
  </div>
103
116
  <vaadin-menu-bar-submenu is-root=""></vaadin-menu-bar-submenu>
117
+
118
+ <slot name="tooltip"></slot>
104
119
  `;
105
120
  }
106
121
 
@@ -205,6 +220,15 @@ class MenuBar extends ButtonsMixin(DisabledMixin(InteractionsMixin(ElementMixin(
205
220
  return ['_themeChanged(_theme)'];
206
221
  }
207
222
 
223
+ /** @protected */
224
+ ready() {
225
+ super.ready();
226
+
227
+ this._tooltipController = new TooltipController(this);
228
+ this._tooltipController.setManual(true);
229
+ this.addController(this._tooltipController);
230
+ }
231
+
208
232
  /**
209
233
  * Override method inherited from `DisabledMixin`
210
234
  * to update the `disabled` property for the buttons
@@ -0,0 +1,17 @@
1
+ import '@vaadin/vaadin-lumo-styles/style.js';
2
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
3
+
4
+ registerStyles(
5
+ 'vaadin-menu-bar',
6
+ css`
7
+ :host([has-single-button]) [part$='button'] {
8
+ border-radius: var(--lumo-border-radius-m);
9
+ }
10
+
11
+ :host([theme~='end-aligned']) [part$='button']:first-child,
12
+ :host([theme~='end-aligned'][has-single-button]) [part$='button'] {
13
+ margin-inline-start: auto;
14
+ }
15
+ `,
16
+ { moduleId: 'lumo-menu-bar' },
17
+ );
@@ -1,5 +1,6 @@
1
1
  import './vaadin-menu-bar-button.js';
2
2
  import './vaadin-menu-bar-item-styles.js';
3
3
  import './vaadin-menu-bar-overlay-styles.js';
4
- import '@vaadin/vaadin-context-menu/theme/lumo/vaadin-context-menu.js';
4
+ import './vaadin-menu-bar-styles.js';
5
+ import '@vaadin/context-menu/theme/lumo/vaadin-context-menu.js';
5
6
  import '../../src/vaadin-menu-bar.js';
@@ -14,8 +14,8 @@ const menuBarButton = css`
14
14
  justify-content: center;
15
15
  }
16
16
 
17
- :host([theme='outlined']),
18
- :host([theme='contained']) {
17
+ :host([theme~='outlined']),
18
+ :host([theme~='contained']) {
19
19
  border-radius: 0;
20
20
  }
21
21
 
@@ -36,7 +36,7 @@ const menuBarButton = css`
36
36
  transition: 0s;
37
37
  }
38
38
 
39
- :host([theme='contained'][expanded]) {
39
+ :host([theme~='contained'][expanded]) {
40
40
  box-shadow: var(--material-shadow-elevation-8dp);
41
41
  }
42
42
 
@@ -45,7 +45,7 @@ const menuBarButton = css`
45
45
  opacity: 0;
46
46
  }
47
47
 
48
- :host([theme='contained']:not([dir='rtl'])) {
48
+ :host([theme~='contained']:not([dir='rtl'])) {
49
49
  margin-right: 1px;
50
50
  }
51
51
 
@@ -68,16 +68,16 @@ const menuBarButton = css`
68
68
  font-size: 24px;
69
69
  }
70
70
 
71
- :host([theme='outlined']:not([dir='rtl'])) {
71
+ :host([theme~='outlined']:not([dir='rtl'])) {
72
72
  margin-right: -1px;
73
73
  }
74
74
 
75
- :host([theme='outlined']:not([dir='rtl']):nth-last-of-type(2)),
76
- :host([theme='outlined']:not([dir='rtl'])[part~='overflow-button']) {
75
+ :host([theme~='outlined']:not([dir='rtl']):nth-last-of-type(2)),
76
+ :host([theme~='outlined']:not([dir='rtl'])[part~='overflow-button']) {
77
77
  margin-right: 0;
78
78
  }
79
79
 
80
- :host([theme='text']),
80
+ :host([theme~='text']),
81
81
  :host(:not([theme])) {
82
82
  border-radius: 4px;
83
83
  }
@@ -92,16 +92,16 @@ const menuBarButton = css`
92
92
  border-radius: 4px 0 0 4px;
93
93
  }
94
94
 
95
- :host([dir='rtl'][theme='contained']) {
95
+ :host([dir='rtl'][theme~='contained']) {
96
96
  margin-left: 1px;
97
97
  }
98
98
 
99
- :host([dir='rtl'][theme='outlined']) {
99
+ :host([dir='rtl'][theme~='outlined']) {
100
100
  margin-left: -1px;
101
101
  }
102
102
 
103
- :host([theme='outlined'][dir='rtl']:nth-last-of-type(2)),
104
- :host([theme='outlined'][dir='rtl'][part~='overflow-button']) {
103
+ :host([theme~='outlined'][dir='rtl']:nth-last-of-type(2)),
104
+ :host([theme~='outlined'][dir='rtl'][part~='overflow-button']) {
105
105
  margin-left: 0;
106
106
  }
107
107
  `;
@@ -7,6 +7,15 @@ registerStyles(
7
7
  /* To retain the box-shadow */
8
8
  padding-bottom: 5px;
9
9
  }
10
+
11
+ :host([has-single-button]) [part$='button'] {
12
+ border-radius: 4px;
13
+ }
14
+
15
+ :host([theme~='end-aligned']) [part$='button']:first-child,
16
+ :host([theme~='end-aligned'][has-single-button]) [part$='button'] {
17
+ margin-inline-start: auto;
18
+ }
10
19
  `,
11
20
  { moduleId: 'material-menu-bar' },
12
21
  );
@@ -2,5 +2,5 @@ import './vaadin-menu-bar-button.js';
2
2
  import './vaadin-menu-bar-item-styles.js';
3
3
  import './vaadin-menu-bar-styles.js';
4
4
  import './vaadin-menu-bar-overlay-styles.js';
5
- import '@vaadin/vaadin-context-menu/theme/material/vaadin-context-menu.js';
5
+ import '@vaadin/context-menu/theme/material/vaadin-context-menu.js';
6
6
  import '../../src/vaadin-menu-bar.js';
package/web-types.json ADDED
@@ -0,0 +1,101 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/web-types",
3
+ "name": "@vaadin/menu-bar",
4
+ "version": "23.3.0-alpha1",
5
+ "description-markup": "markdown",
6
+ "contributions": {
7
+ "html": {
8
+ "elements": [
9
+ {
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.3.0-alpha1/#/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.3.0-alpha1/#/elements/vaadin-button).\n- `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha1/#/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.3.0-alpha1/#/elements/vaadin-list-box).\n- `<vaadin-context-menu-overlay>` - has the same API as [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha1/#/elements/vaadin-overlay).",
12
+ "attributes": [
13
+ {
14
+ "name": "open-on-hover",
15
+ "description": "If true, the submenu will open on hover (mouseover) instead of click.",
16
+ "value": {
17
+ "type": [
18
+ "boolean",
19
+ "null",
20
+ "undefined"
21
+ ]
22
+ }
23
+ },
24
+ {
25
+ "name": "disabled",
26
+ "description": "If true, the user cannot interact with this element.",
27
+ "value": {
28
+ "type": [
29
+ "boolean",
30
+ "null",
31
+ "undefined"
32
+ ]
33
+ }
34
+ },
35
+ {
36
+ "name": "theme",
37
+ "description": "The theme variants to apply to the component.",
38
+ "value": {
39
+ "type": [
40
+ "string",
41
+ "null",
42
+ "undefined"
43
+ ]
44
+ }
45
+ }
46
+ ],
47
+ "js": {
48
+ "properties": [
49
+ {
50
+ "name": "openOnHover",
51
+ "description": "If true, the submenu will open on hover (mouseover) instead of click.",
52
+ "value": {
53
+ "type": [
54
+ "boolean",
55
+ "null",
56
+ "undefined"
57
+ ]
58
+ }
59
+ },
60
+ {
61
+ "name": "disabled",
62
+ "description": "If true, the user cannot interact with this element.",
63
+ "value": {
64
+ "type": [
65
+ "boolean",
66
+ "null",
67
+ "undefined"
68
+ ]
69
+ }
70
+ },
71
+ {
72
+ "name": "items",
73
+ "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 children: [\n {text: '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```",
74
+ "value": {
75
+ "type": [
76
+ "Array.<MenuBarItem>"
77
+ ]
78
+ }
79
+ },
80
+ {
81
+ "name": "i18n",
82
+ "description": "The object used to localize this component.\nTo change the default localization, replace the entire\n`i18n` object with a custom one.\n\nTo update individual properties, extend the existing i18n object like so:\n```\nmenuBar.i18n = {\n ...menuBar.i18n,\n moreOptions: 'More options'\n}\n```\n\nThe object has the following JSON structure and default values:\n```\n{\n moreOptions: 'More options'\n}\n```",
83
+ "value": {
84
+ "type": [
85
+ "MenuBarI18n"
86
+ ]
87
+ }
88
+ }
89
+ ],
90
+ "events": [
91
+ {
92
+ "name": "item-selected",
93
+ "description": "Fired when either a submenu item or menu bar button without nested children is clicked."
94
+ }
95
+ ]
96
+ }
97
+ }
98
+ ]
99
+ }
100
+ }
101
+ }
@@ -0,0 +1,62 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/web-types",
3
+ "name": "@vaadin/menu-bar",
4
+ "version": "23.3.0-alpha1",
5
+ "description-markup": "markdown",
6
+ "framework": "lit",
7
+ "framework-config": {
8
+ "enable-when": {
9
+ "node-packages": [
10
+ "lit"
11
+ ]
12
+ }
13
+ },
14
+ "contributions": {
15
+ "html": {
16
+ "elements": [
17
+ {
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.3.0-alpha1/#/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.3.0-alpha1/#/elements/vaadin-button).\n- `<vaadin-context-menu-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha1/#/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.3.0-alpha1/#/elements/vaadin-list-box).\n- `<vaadin-context-menu-overlay>` - has the same API as [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha1/#/elements/vaadin-overlay).",
20
+ "extension": true,
21
+ "attributes": [
22
+ {
23
+ "name": "?openOnHover",
24
+ "description": "If true, the submenu will open on hover (mouseover) instead of click.",
25
+ "value": {
26
+ "kind": "expression"
27
+ }
28
+ },
29
+ {
30
+ "name": "?disabled",
31
+ "description": "If true, the user cannot interact with this element.",
32
+ "value": {
33
+ "kind": "expression"
34
+ }
35
+ },
36
+ {
37
+ "name": ".items",
38
+ "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 children: [\n {text: '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```",
39
+ "value": {
40
+ "kind": "expression"
41
+ }
42
+ },
43
+ {
44
+ "name": ".i18n",
45
+ "description": "The object used to localize this component.\nTo change the default localization, replace the entire\n`i18n` object with a custom one.\n\nTo update individual properties, extend the existing i18n object like so:\n```\nmenuBar.i18n = {\n ...menuBar.i18n,\n moreOptions: 'More options'\n}\n```\n\nThe object has the following JSON structure and default values:\n```\n{\n moreOptions: 'More options'\n}\n```",
46
+ "value": {
47
+ "kind": "expression"
48
+ }
49
+ },
50
+ {
51
+ "name": "@item-selected",
52
+ "description": "Fired when either a submenu item or menu bar button without nested children is clicked.",
53
+ "value": {
54
+ "kind": "expression"
55
+ }
56
+ }
57
+ ]
58
+ }
59
+ ]
60
+ }
61
+ }
62
+ }