@vaadin/list-box 24.0.0-alpha4 → 24.0.0-alpha6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/list-box",
3
- "version": "24.0.0-alpha4",
3
+ "version": "24.0.0-alpha6",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,12 +36,11 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "@polymer/polymer": "^3.0.0",
39
- "@vaadin/component-base": "24.0.0-alpha4",
40
- "@vaadin/item": "24.0.0-alpha4",
41
- "@vaadin/vaadin-list-mixin": "24.0.0-alpha4",
42
- "@vaadin/vaadin-lumo-styles": "24.0.0-alpha4",
43
- "@vaadin/vaadin-material-styles": "24.0.0-alpha4",
44
- "@vaadin/vaadin-themable-mixin": "24.0.0-alpha4"
39
+ "@vaadin/component-base": "24.0.0-alpha6",
40
+ "@vaadin/item": "24.0.0-alpha6",
41
+ "@vaadin/vaadin-lumo-styles": "24.0.0-alpha6",
42
+ "@vaadin/vaadin-material-styles": "24.0.0-alpha6",
43
+ "@vaadin/vaadin-themable-mixin": "24.0.0-alpha6"
45
44
  },
46
45
  "devDependencies": {
47
46
  "@esm-bundle/chai": "^4.3.4",
@@ -52,5 +51,5 @@
52
51
  "web-types.json",
53
52
  "web-types.lit.json"
54
53
  ],
55
- "gitHead": "66be46e82c4d0a673859fbc9bdb1581dd89f360c"
54
+ "gitHead": "0004ac92b6e5f415b5fa949e0582d1d11e527b1f"
56
55
  }
@@ -5,8 +5,8 @@
5
5
  */
6
6
  import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
7
7
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
8
- import { MultiSelectListMixin } from '@vaadin/vaadin-list-mixin/vaadin-multi-select-list-mixin.js';
9
8
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
9
+ import { MultiSelectListMixin } from './vaadin-multi-select-list-mixin.js';
10
10
 
11
11
  /**
12
12
  * Fired when the `items` property changes.
@@ -7,8 +7,8 @@ import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
7
  import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
8
8
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
9
9
  import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js';
10
- import { MultiSelectListMixin } from '@vaadin/vaadin-list-mixin/vaadin-multi-select-list-mixin.js';
11
10
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
11
+ import { MultiSelectListMixin } from './vaadin-multi-select-list-mixin.js';
12
12
 
13
13
  /**
14
14
  * `<vaadin-list-box>` is a Web Component for creating menus.
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { ListMixinClass } from '@vaadin/component-base/src/list-mixin.js';
8
+
9
+ /**
10
+ * A mixin for `nav` elements, facilitating multiple selection of childNodes.
11
+ */
12
+ export declare function MultiSelectListMixin<T extends Constructor<HTMLElement>>(
13
+ base: T,
14
+ ): Constructor<ListMixinClass> & Constructor<MultiSelectListMixinClass> & T;
15
+
16
+ export declare class MultiSelectListMixinClass {
17
+ /**
18
+ * Specifies that multiple options can be selected at once.
19
+ */
20
+ multiple: boolean | null | undefined;
21
+
22
+ /**
23
+ * Array of indexes of the items selected in the items array
24
+ * Note: Not updated when used in single selection mode.
25
+ */
26
+ selectedValues: number[] | null | undefined;
27
+ }
@@ -0,0 +1,121 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { ListMixin } from '@vaadin/component-base/src/list-mixin.js';
7
+
8
+ /**
9
+ * A mixin for `nav` elements, facilitating multiple selection of childNodes.
10
+ *
11
+ * @polymerMixin
12
+ * @mixes ListMixin
13
+ */
14
+ export const MultiSelectListMixin = (superClass) =>
15
+ class VaadinMultiSelectListMixin extends ListMixin(superClass) {
16
+ static get properties() {
17
+ return {
18
+ /**
19
+ * Specifies that multiple options can be selected at once.
20
+ */
21
+ multiple: {
22
+ type: Boolean,
23
+ value: false,
24
+ reflectToAttribute: true,
25
+ observer: '_multipleChanged',
26
+ },
27
+
28
+ /**
29
+ * Array of indexes of the items selected in the items array
30
+ * Note: Not updated when used in single selection mode.
31
+ * @type {number[] | null | undefined}
32
+ */
33
+ selectedValues: {
34
+ type: Array,
35
+ notify: true,
36
+ value: () => [],
37
+ },
38
+ };
39
+ }
40
+
41
+ static get observers() {
42
+ return [`_enhanceMultipleItems(items, multiple, selected, selectedValues, selectedValues.*)`];
43
+ }
44
+
45
+ /** @protected */
46
+ ready() {
47
+ // Should be attached before click listener in list-mixin
48
+ this.addEventListener('click', (e) => this._onMultipleClick(e));
49
+
50
+ super.ready();
51
+ }
52
+
53
+ /** @private */
54
+ _enhanceMultipleItems(items, multiple, selected, selectedValues) {
55
+ if (!items || !multiple) {
56
+ return;
57
+ }
58
+
59
+ if (selectedValues) {
60
+ const selectedItems = selectedValues.map((selectedId) => items[selectedId]);
61
+ items.forEach((item) => {
62
+ item.selected = selectedItems.includes(item);
63
+ });
64
+ }
65
+
66
+ this._scrollToLastSelectedItem();
67
+ }
68
+
69
+ /** @private */
70
+ _scrollToLastSelectedItem() {
71
+ const lastSelectedItem = this.selectedValues.slice(-1)[0];
72
+ if (lastSelectedItem && !lastSelectedItem.disabled) {
73
+ this._scrollToItem(lastSelectedItem);
74
+ }
75
+ }
76
+
77
+ /**
78
+ * @param {!MouseEvent} event
79
+ * @protected
80
+ */
81
+ _onMultipleClick(event) {
82
+ const item = this._filterItems(event.composedPath())[0];
83
+ const idx = item && !item.disabled ? this.items.indexOf(item) : -1;
84
+ if (idx < 0 || !this.multiple) {
85
+ return;
86
+ }
87
+
88
+ event.preventDefault();
89
+ if (this.selectedValues.includes(idx)) {
90
+ this.selectedValues = this.selectedValues.filter((v) => v !== idx);
91
+ } else {
92
+ this.selectedValues = this.selectedValues.concat(idx);
93
+ }
94
+ }
95
+
96
+ /** @private */
97
+ _multipleChanged(value, oldValue) {
98
+ // Changing from multiple to single selection, clear selection.
99
+ if (!value && oldValue) {
100
+ this.selectedValues = [];
101
+ this.items.forEach((item) => {
102
+ item.selected = false;
103
+ });
104
+ }
105
+
106
+ // Changing from single to multiple selection, add selected to selectedValues.
107
+ if (value && !oldValue && this.selected !== undefined) {
108
+ this.selectedValues = [...this.selectedValues, this.selected];
109
+ this.selected = undefined;
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Fired when the selection is changed.
115
+ * Not fired in single selection mode.
116
+ *
117
+ * @event selected-values-changed
118
+ * @param {Object} detail
119
+ * @param {Object} detail.value the array of indexes of the items selected in the items array.
120
+ */
121
+ };
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/list-box",
4
- "version": "24.0.0-alpha4",
4
+ "version": "24.0.0-alpha6",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/list-box",
4
- "version": "24.0.0-alpha4",
4
+ "version": "24.0.0-alpha6",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {