@vaadin/multi-select-combo-box 23.1.0-rc3 → 23.1.0

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/multi-select-combo-box",
3
- "version": "23.1.0-rc3",
3
+ "version": "23.1.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -33,18 +33,18 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "@polymer/polymer": "^3.0.0",
36
- "@vaadin/combo-box": "23.1.0-rc3",
37
- "@vaadin/component-base": "23.1.0-rc3",
38
- "@vaadin/field-base": "23.1.0-rc3",
39
- "@vaadin/input-container": "23.1.0-rc3",
40
- "@vaadin/vaadin-lumo-styles": "23.1.0-rc3",
41
- "@vaadin/vaadin-material-styles": "23.1.0-rc3",
42
- "@vaadin/vaadin-themable-mixin": "23.1.0-rc3"
36
+ "@vaadin/combo-box": "^23.1.0",
37
+ "@vaadin/component-base": "^23.1.0",
38
+ "@vaadin/field-base": "^23.1.0",
39
+ "@vaadin/input-container": "^23.1.0",
40
+ "@vaadin/vaadin-lumo-styles": "^23.1.0",
41
+ "@vaadin/vaadin-material-styles": "^23.1.0",
42
+ "@vaadin/vaadin-themable-mixin": "^23.1.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@esm-bundle/chai": "^4.3.4",
46
46
  "@vaadin/testing-helpers": "^0.3.2",
47
47
  "sinon": "^13.0.2"
48
48
  },
49
- "gitHead": "49c312fbe0228adb559296d45655bbfd4eac6235"
49
+ "gitHead": "322bba42b83f908a78cd972b06acadc5da95a69d"
50
50
  }
@@ -33,6 +33,15 @@ class MultiSelectComboBoxDropdown extends ComboBoxDropdown {
33
33
  ></vaadin-multi-select-combo-box-overlay>
34
34
  `;
35
35
  }
36
+
37
+ /** @protected */
38
+ ready() {
39
+ super.ready();
40
+
41
+ // Set owner for using by item renderers
42
+ const comboBox = this.getRootNode().host;
43
+ this._scroller.comboBox = comboBox.getRootNode().host;
44
+ }
36
45
  }
37
46
 
38
47
  customElements.define(MultiSelectComboBoxDropdown.is, MultiSelectComboBoxDropdown);
@@ -50,6 +50,16 @@ class MultiSelectComboBoxInternal extends ComboBoxDataProviderMixin(ComboBoxMixi
50
50
 
51
51
  static get properties() {
52
52
  return {
53
+ /**
54
+ * When set to `true`, "loading" attribute is set
55
+ * on the host and the overlay element.
56
+ * @type {boolean}
57
+ */
58
+ loading: {
59
+ type: Boolean,
60
+ notify: true,
61
+ },
62
+
53
63
  /**
54
64
  * Total number of items.
55
65
  * @type {number | undefined}
@@ -59,12 +69,25 @@ class MultiSelectComboBoxInternal extends ComboBoxDataProviderMixin(ComboBoxMixi
59
69
  notify: true,
60
70
  },
61
71
 
72
+ /**
73
+ * Selected items to render in the dropdown
74
+ * when the component is read-only.
75
+ */
76
+ selectedItems: {
77
+ type: Array,
78
+ value: () => [],
79
+ },
80
+
62
81
  _target: {
63
82
  type: Object,
64
83
  },
65
84
  };
66
85
  }
67
86
 
87
+ static get observers() {
88
+ return ['_readonlyItemsChanged(readonly, selectedItems)'];
89
+ }
90
+
68
91
  /**
69
92
  * Reference to the clear button element.
70
93
  * @protected
@@ -80,7 +103,7 @@ class MultiSelectComboBoxInternal extends ComboBoxDataProviderMixin(ComboBoxMixi
80
103
  * @override
81
104
  */
82
105
  open() {
83
- if (!this.disabled && !(this.readonly && this._getOverlayItems().length === 0)) {
106
+ if (!this.disabled && !(this.readonly && this.selectedItems.length === 0)) {
84
107
  this.opened = true;
85
108
  }
86
109
  }
@@ -246,6 +269,50 @@ class MultiSelectComboBoxInternal extends ComboBoxDataProviderMixin(ComboBoxMixi
246
269
  );
247
270
  }
248
271
  }
272
+
273
+ /**
274
+ * Override method inherited from the combo-box
275
+ * to render only selected items when read-only,
276
+ * even if a different set of items is provided.
277
+ *
278
+ * @protected
279
+ * @override
280
+ */
281
+ _setOverlayItems(items) {
282
+ const effectiveItems = this.readonly ? this.selectedItems : items;
283
+ super._setOverlayItems(effectiveItems);
284
+ }
285
+
286
+ /**
287
+ * Override method inherited from the combo-box
288
+ * to not request data provider when read-only.
289
+ *
290
+ * @param {number}
291
+ * @return {boolean}
292
+ * @protected
293
+ * @override
294
+ */
295
+ _shouldLoadPage(page) {
296
+ if (this.readonly) {
297
+ return false;
298
+ }
299
+
300
+ return super._shouldLoadPage(page);
301
+ }
302
+
303
+ /** @private */
304
+ _readonlyItemsChanged(readonly, selectedItems) {
305
+ if (readonly && selectedItems) {
306
+ this.__savedItems = this._getOverlayItems();
307
+ this._setOverlayItems(selectedItems);
308
+ }
309
+
310
+ // Restore the original dropdown items
311
+ if (readonly === false && this.__savedItems) {
312
+ this._setOverlayItems(this.__savedItems);
313
+ this.__savedItems = null;
314
+ }
315
+ }
249
316
  }
250
317
 
251
318
  customElements.define(MultiSelectComboBoxInternal.is, MultiSelectComboBoxInternal);
@@ -40,8 +40,7 @@ class MultiSelectComboBoxScroller extends ComboBoxScroller {
40
40
  return false;
41
41
  }
42
42
 
43
- const host = this.comboBox.getRootNode().host;
44
- return host._findIndex(item, host.selectedItems, itemIdPath) > -1;
43
+ return this.comboBox._findIndex(item, this.comboBox.selectedItems, itemIdPath) > -1;
45
44
  }
46
45
 
47
46
  /** @private */
@@ -3,7 +3,11 @@
3
3
  * Copyright (c) 2021 - 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 { ComboBoxDataProvider, ComboBoxDefaultItem, ComboBoxRenderer } from '@vaadin/combo-box/src/vaadin-combo-box.js';
6
+ import {
7
+ ComboBoxDataProvider,
8
+ ComboBoxDefaultItem,
9
+ ComboBoxItemModel,
10
+ } from '@vaadin/combo-box/src/vaadin-combo-box.js';
7
11
  import { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
12
  import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
9
13
  import { ElementMixinClass } from '@vaadin/component-base/src/element-mixin.js';
@@ -20,6 +24,12 @@ import { LabelMixinClass } from '@vaadin/field-base/src/label-mixin.js';
20
24
  import { ValidateMixinClass } from '@vaadin/field-base/src/validate-mixin.js';
21
25
  import { ThemableMixinClass } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
22
26
 
27
+ export type MultiSelectComboBoxRenderer<TItem> = (
28
+ root: HTMLElement,
29
+ comboBox: MultiSelectComboBox<TItem>,
30
+ model: ComboBoxItemModel<TItem>,
31
+ ) => void;
32
+
23
33
  export interface MultiSelectComboBoxI18n {
24
34
  cleared: string;
25
35
  focused: string;
@@ -112,6 +122,7 @@ export interface MultiSelectComboBoxEventMap<TItem> extends HTMLElementEventMap
112
122
  * `invalid` | Set when the element is invalid
113
123
  * `focused` | Set when the element is focused
114
124
  * `focus-ring` | Set when the element is keyboard focused
125
+ * `loading` | Set when loading items from the data provider
115
126
  * `opened` | Set when the dropdown is open
116
127
  * `readonly` | Set to a readonly element
117
128
  *
@@ -231,6 +242,11 @@ declare class MultiSelectComboBox<TItem = ComboBoxDefaultItem> extends HTMLEleme
231
242
  */
232
243
  i18n: MultiSelectComboBoxI18n;
233
244
 
245
+ /**
246
+ * True when loading items from the data provider, false otherwise.
247
+ */
248
+ loading: boolean;
249
+
234
250
  /**
235
251
  * True if the dropdown is open, false otherwise.
236
252
  */
@@ -254,13 +270,13 @@ declare class MultiSelectComboBox<TItem = ComboBoxDefaultItem> extends HTMLEleme
254
270
  * Receives three arguments:
255
271
  *
256
272
  * - `root` The `<vaadin-multi-select-combo-box-item>` internal container DOM element.
257
- * - `comboBox` The reference to the `<vaadin-combo-box>` element.
273
+ * - `comboBox` The reference to the `<vaadin-multi-select-combo-box>` element.
258
274
  * - `model` The object with the properties related with the rendered
259
275
  * item, contains:
260
276
  * - `model.index` The index of the rendered item.
261
277
  * - `model.item` The item.
262
278
  */
263
- renderer: ComboBoxRenderer<TItem> | null | undefined;
279
+ renderer: MultiSelectComboBoxRenderer<TItem> | null | undefined;
264
280
 
265
281
  /**
266
282
  * The list of selected items.
@@ -278,6 +294,14 @@ declare class MultiSelectComboBox<TItem = ComboBoxDefaultItem> extends HTMLEleme
278
294
  */
279
295
  clearCache(): void;
280
296
 
297
+ /**
298
+ * Requests an update for the content of items.
299
+ * While performing the update, it invokes the renderer (passed in the `renderer` property) once an item.
300
+ *
301
+ * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
302
+ */
303
+ requestContentUpdate(): void;
304
+
281
305
  addEventListener<K extends keyof MultiSelectComboBoxEventMap<TItem>>(
282
306
  type: K,
283
307
  listener: (this: MultiSelectComboBox<TItem>, ev: MultiSelectComboBoxEventMap<TItem>[K]) => void,
@@ -100,6 +100,7 @@ registerStyles('vaadin-multi-select-combo-box', [inputFieldShared, multiSelectCo
100
100
  * `invalid` | Set when the element is invalid
101
101
  * `focused` | Set when the element is focused
102
102
  * `focus-ring` | Set when the element is keyboard focused
103
+ * `loading` | Set when loading items from the data provider
103
104
  * `opened` | Set when the dropdown is open
104
105
  * `readonly` | Set to a readonly element
105
106
  *
@@ -162,8 +163,10 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
162
163
  allow-custom-value="[[allowCustomValue]]"
163
164
  data-provider="[[dataProvider]]"
164
165
  filter="{{filter}}"
166
+ loading="{{loading}}"
165
167
  size="{{size}}"
166
168
  filtered-items="[[filteredItems]]"
169
+ selected-items="[[selectedItems]]"
167
170
  opened="{{opened}}"
168
171
  renderer="[[renderer]]"
169
172
  theme$="[[_theme]]"
@@ -298,6 +301,15 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
298
301
  },
299
302
  },
300
303
 
304
+ /**
305
+ * True when loading items from the data provider, false otherwise.
306
+ */
307
+ loading: {
308
+ type: Boolean,
309
+ value: false,
310
+ reflectToAttribute: true,
311
+ },
312
+
301
313
  /**
302
314
  * When present, it specifies that the field is read-only.
303
315
  */
@@ -359,7 +371,6 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
359
371
  */
360
372
  dataProvider: {
361
373
  type: Object,
362
- observer: '_dataProviderChanged',
363
374
  },
364
375
 
365
376
  /**
@@ -387,7 +398,7 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
387
398
  * Receives three arguments:
388
399
  *
389
400
  * - `root` The `<vaadin-multi-select-combo-box-item>` internal container DOM element.
390
- * - `comboBox` The reference to the `<vaadin-combo-box>` element.
401
+ * - `comboBox` The reference to the `<vaadin-multi-select-combo-box>` element.
391
402
  * - `model` The object with the properties related with the rendered
392
403
  * item, contains:
393
404
  * - `model.index` The index of the rendered item.
@@ -487,6 +498,18 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
487
498
  }
488
499
  }
489
500
 
501
+ /**
502
+ * Requests an update for the content of items.
503
+ * While performing the update, it invokes the renderer (passed in the `renderer` property) once an item.
504
+ *
505
+ * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
506
+ */
507
+ requestContentUpdate() {
508
+ if (this.$ && this.$.comboBox) {
509
+ this.$.comboBox.requestContentUpdate();
510
+ }
511
+ }
512
+
490
513
  /**
491
514
  * Override method inherited from `DisabledMixin` to forward disabled to chips.
492
515
  * @protected
@@ -584,13 +607,7 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
584
607
 
585
608
  /** @private */
586
609
  _readonlyChanged(readonly, oldReadonly) {
587
- if (readonly) {
588
- this.__savedItems = this.$.comboBox._getOverlayItems();
589
- this.$.comboBox._setOverlayItems(Array.from(this.selectedItems));
590
- this.__updateChips();
591
- } else if (oldReadonly) {
592
- this.$.comboBox._setOverlayItems(this.__savedItems);
593
- this.__savedItems = null;
610
+ if (readonly || oldReadonly) {
594
611
  this.__updateChips();
595
612
  }
596
613
  }
@@ -637,12 +654,8 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
637
654
  // Re-render chips
638
655
  this.__updateChips();
639
656
 
640
- if (this.readonly) {
641
- this.$.comboBox._setOverlayItems(selectedItems);
642
- }
643
-
644
657
  // Update selected for dropdown items
645
- this.$.comboBox.requestContentUpdate();
658
+ this.requestContentUpdate();
646
659
  }
647
660
 
648
661
  /** @private */