@vaadin/list-box 23.3.3 → 24.0.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/list-box",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "24.0.0-alpha10",
|
|
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": "
|
|
40
|
-
"@vaadin/item": "
|
|
41
|
-
"@vaadin/vaadin-
|
|
42
|
-
"@vaadin/vaadin-
|
|
43
|
-
"@vaadin/vaadin-
|
|
44
|
-
"@vaadin/vaadin-themable-mixin": "~23.3.3"
|
|
39
|
+
"@vaadin/component-base": "24.0.0-alpha10",
|
|
40
|
+
"@vaadin/item": "24.0.0-alpha10",
|
|
41
|
+
"@vaadin/vaadin-lumo-styles": "24.0.0-alpha10",
|
|
42
|
+
"@vaadin/vaadin-material-styles": "24.0.0-alpha10",
|
|
43
|
+
"@vaadin/vaadin-themable-mixin": "24.0.0-alpha10"
|
|
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": "
|
|
54
|
+
"gitHead": "2e04534d8b47bcd216f89b5f849bafef1a73b174"
|
|
56
55
|
}
|
package/src/vaadin-list-box.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2017 -
|
|
3
|
+
* Copyright (c) 2017 - 2023 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
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.
|
package/src/vaadin-list-box.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2017 -
|
|
3
|
+
* Copyright (c) 2017 - 2023 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
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.
|
|
@@ -95,6 +95,15 @@ class ListBox extends ElementMixin(MultiSelectListMixin(ThemableMixin(Controller
|
|
|
95
95
|
this.focused;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
/**
|
|
99
|
+
* @return {!HTMLElement}
|
|
100
|
+
* @protected
|
|
101
|
+
* @override
|
|
102
|
+
*/
|
|
103
|
+
get _scrollerElement() {
|
|
104
|
+
return this.shadowRoot.querySelector('[part="items"]');
|
|
105
|
+
}
|
|
106
|
+
|
|
98
107
|
/** @protected */
|
|
99
108
|
ready() {
|
|
100
109
|
super.ready();
|
|
@@ -106,14 +115,6 @@ class ListBox extends ElementMixin(MultiSelectListMixin(ThemableMixin(Controller
|
|
|
106
115
|
this.addController(this._tooltipController);
|
|
107
116
|
}
|
|
108
117
|
|
|
109
|
-
/**
|
|
110
|
-
* @return {!HTMLElement}
|
|
111
|
-
* @protected
|
|
112
|
-
*/
|
|
113
|
-
get _scrollerElement() {
|
|
114
|
-
return this.shadowRoot.querySelector('[part="items"]');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
118
|
/** @private */
|
|
118
119
|
_checkImport() {
|
|
119
120
|
const item = this.querySelector('vaadin-item');
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2017 - 2023 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 - 2023 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