@vaadin/combo-box 25.0.0-alpha1 → 25.0.0-alpha11

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.
Files changed (30) hide show
  1. package/package.json +14 -15
  2. package/src/styles/vaadin-combo-box-base-styles.d.ts +8 -0
  3. package/src/styles/vaadin-combo-box-base-styles.js +17 -0
  4. package/src/styles/vaadin-combo-box-overlay-base-styles.js +46 -0
  5. package/src/styles/vaadin-combo-box-scroller-base-styles.js +29 -0
  6. package/src/vaadin-combo-box-base-mixin.d.ts +56 -0
  7. package/src/vaadin-combo-box-base-mixin.js +776 -0
  8. package/src/vaadin-combo-box-data-provider-mixin.js +17 -32
  9. package/src/vaadin-combo-box-item-mixin.js +6 -1
  10. package/src/vaadin-combo-box-item.js +7 -11
  11. package/src/vaadin-combo-box-items-mixin.d.ts +53 -0
  12. package/src/vaadin-combo-box-items-mixin.js +275 -0
  13. package/src/vaadin-combo-box-mixin.d.ts +3 -72
  14. package/src/vaadin-combo-box-mixin.js +84 -898
  15. package/src/vaadin-combo-box-overlay-mixin.js +1 -22
  16. package/src/vaadin-combo-box-overlay.js +5 -16
  17. package/src/vaadin-combo-box-scroller.js +3 -24
  18. package/src/vaadin-combo-box.d.ts +10 -8
  19. package/src/vaadin-combo-box.js +44 -19
  20. package/vaadin-combo-box.js +1 -1
  21. package/web-types.json +51 -51
  22. package/web-types.lit.json +17 -17
  23. package/theme/lumo/vaadin-combo-box-item-styles.d.ts +0 -5
  24. package/theme/lumo/vaadin-combo-box-item-styles.js +0 -25
  25. package/theme/lumo/vaadin-combo-box-overlay-styles.d.ts +0 -6
  26. package/theme/lumo/vaadin-combo-box-overlay-styles.js +0 -60
  27. package/theme/lumo/vaadin-combo-box-styles.d.ts +0 -2
  28. package/theme/lumo/vaadin-combo-box-styles.js +0 -12
  29. package/theme/lumo/vaadin-combo-box.d.ts +0 -4
  30. package/theme/lumo/vaadin-combo-box.js +0 -4
@@ -54,31 +54,32 @@ export const ComboBoxDataProviderMixin = (superClass) =>
54
54
  observer: '_dataProviderChanged',
55
55
  sync: true,
56
56
  },
57
-
58
- /** @private */
59
- __dataProviderInitialized: {
60
- type: Boolean,
61
- value: false,
62
- },
63
-
64
- /** @private */
65
- __previousDataProviderFilter: {
66
- type: String,
67
- },
68
57
  };
69
58
  }
70
59
 
71
60
  static get observers() {
72
- return [
73
- '_dataProviderFilterChanged(filter)',
74
- '_warnDataProviderValue(dataProvider, value)',
75
- '_ensureFirstPage(opened)',
76
- ];
61
+ return ['_dataProviderFilterChanged(filter)', '_ensureFirstPage(opened)'];
77
62
  }
78
63
 
79
64
  constructor() {
80
65
  super();
81
66
 
67
+ /**
68
+ * Flag indicating that data provider has been initialized.
69
+ * Do not define in `properties` to avoid triggering updates.
70
+ * @type {boolean}
71
+ * @protected
72
+ */
73
+ this.__dataProviderInitialized = false;
74
+
75
+ /**
76
+ * Used to store the previous value of the data provider filter.
77
+ * Do not define in `properties` to avoid triggering updates.
78
+ * @type {string}
79
+ * @protected
80
+ */
81
+ this.__previousDataProviderFilter;
82
+
82
83
  /**
83
84
  * @type {DataProviderController}
84
85
  * @private
@@ -278,20 +279,4 @@ export const ComboBoxDataProviderMixin = (superClass) =>
278
279
  throw new Error('Using `items` and `dataProvider` together is not supported');
279
280
  }
280
281
  }
281
-
282
- /** @private */
283
- _warnDataProviderValue(dataProvider, value) {
284
- if (dataProvider && value !== '' && (this.selectedItem === undefined || this.selectedItem === null)) {
285
- const valueIndex = this.__getItemIndexByValue(this.filteredItems, value);
286
- if (valueIndex < 0 || !this._getItemLabel(this.filteredItems[valueIndex])) {
287
- console.warn(
288
- 'Warning: unable to determine the label for the provided `value`. ' +
289
- 'Nothing to display in the text field. This usually happens when ' +
290
- 'setting an initial `value` before any items are returned from ' +
291
- 'the `dataProvider` callback. Consider setting `selectedItem` ' +
292
- 'instead of `value`',
293
- );
294
- }
295
- }
296
- }
297
282
  };
@@ -84,12 +84,17 @@ export const ComboBoxItemMixin = (superClass) =>
84
84
 
85
85
  this._owner = this.parentNode.owner;
86
86
 
87
- const hostDir = this._owner.getAttribute('dir');
87
+ const hostDir = this._getHostDir();
88
88
  if (hostDir) {
89
89
  this.setAttribute('dir', hostDir);
90
90
  }
91
91
  }
92
92
 
93
+ /** @protected */
94
+ _getHostDir() {
95
+ return this._owner && this._owner.$.overlay.getAttribute('dir');
96
+ }
97
+
93
98
  /**
94
99
  * Requests an update for the content of the item.
95
100
  * While performing the update, it invokes the renderer passed in the `renderer` property.
@@ -3,10 +3,12 @@
3
3
  * Copyright (c) 2015 - 2025 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { css, html, LitElement } from 'lit';
6
+ import { html, LitElement } from 'lit';
7
7
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
8
8
  import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
9
9
  import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
10
+ import { itemStyles } from '@vaadin/item/src/styles/vaadin-item-base-styles.js';
11
+ import { LumoInjectionMixin } from '@vaadin/vaadin-themable-mixin/lumo-injection-mixin.js';
10
12
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
11
13
  import { ComboBoxItemMixin } from './vaadin-combo-box-item-mixin.js';
12
14
 
@@ -37,21 +39,15 @@ import { ComboBoxItemMixin } from './vaadin-combo-box-item-mixin.js';
37
39
  * @mixes DirMixin
38
40
  * @private
39
41
  */
40
- export class ComboBoxItem extends ComboBoxItemMixin(ThemableMixin(DirMixin(PolylitMixin(LitElement)))) {
42
+ export class ComboBoxItem extends ComboBoxItemMixin(
43
+ ThemableMixin(DirMixin(PolylitMixin(LumoInjectionMixin(LitElement)))),
44
+ ) {
41
45
  static get is() {
42
46
  return 'vaadin-combo-box-item';
43
47
  }
44
48
 
45
49
  static get styles() {
46
- return css`
47
- :host {
48
- display: block;
49
- }
50
-
51
- :host([hidden]) {
52
- display: none;
53
- }
54
- `;
50
+ return itemStyles;
55
51
  }
56
52
 
57
53
  /** @protected */
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2015 - 2025 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 { ComboBoxBaseMixinClass } from './vaadin-combo-box-base-mixin.js';
8
+
9
+ export declare function ComboBoxItemsMixin<TItem, T extends Constructor<HTMLElement>>(
10
+ base: T,
11
+ ): Constructor<ComboBoxBaseMixinClass> & Constructor<ComboBoxItemsMixinClass<TItem>> & T;
12
+
13
+ export declare class ComboBoxItemsMixinClass<TItem> {
14
+ /**
15
+ * A full set of items to filter the visible options from.
16
+ * The items can be of either `String` or `Object` type.
17
+ */
18
+ items: TItem[] | undefined;
19
+
20
+ /**
21
+ * A subset of items, filtered based on the user input. Filtered items
22
+ * can be assigned directly to omit the internal filtering functionality.
23
+ * The items can be of either `String` or `Object` type.
24
+ */
25
+ filteredItems: TItem[] | undefined;
26
+
27
+ /**
28
+ * Filtering string the user has typed into the input field.
29
+ */
30
+ filter: string;
31
+
32
+ /**
33
+ * Path for label of the item. If `items` is an array of objects, the
34
+ * `itemLabelPath` is used to fetch the displayed string label for each
35
+ * item.
36
+ *
37
+ * The item label is also used for matching items when processing user
38
+ * input, i.e., for filtering and selecting items.
39
+ * @attr {string} item-label-path
40
+ */
41
+ itemLabelPath: string;
42
+
43
+ /**
44
+ * Path for the value of the item. If `items` is an array of objects, the
45
+ * `itemValuePath:` is used to fetch the string value for the selected
46
+ * item.
47
+ *
48
+ * The item value is used in the `value` property of the combo box,
49
+ * to provide the form value.
50
+ * @attr {string} item-value-path
51
+ */
52
+ itemValuePath: string;
53
+ }
@@ -0,0 +1,275 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2015 - 2025 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { get } from '@vaadin/component-base/src/path-utils.js';
7
+ import { ComboBoxBaseMixin } from './vaadin-combo-box-base-mixin.js';
8
+ import { ComboBoxPlaceholder } from './vaadin-combo-box-placeholder.js';
9
+
10
+ /**
11
+ * Checks if the value is supported as an item value in this control.
12
+ *
13
+ * @param {unknown} value
14
+ * @return {boolean}
15
+ */
16
+ function isValidValue(value) {
17
+ return value !== undefined && value !== null;
18
+ }
19
+
20
+ /**
21
+ * Returns the index of the first item that satisfies the provided testing function
22
+ * ignoring placeholder items.
23
+ *
24
+ * @param {Array<ComboBoxItem | string>} items
25
+ * @param {Function} callback
26
+ * @return {number}
27
+ */
28
+ function findItemIndex(items, callback) {
29
+ return items.findIndex((item) => {
30
+ if (item instanceof ComboBoxPlaceholder) {
31
+ return false;
32
+ }
33
+
34
+ return callback(item);
35
+ });
36
+ }
37
+
38
+ /**
39
+ * @polymerMixin
40
+ * @mixes ComboBoxBaseMixin
41
+ */
42
+ export const ComboBoxItemsMixin = (superClass) =>
43
+ class ComboBoxItemsMixinClass extends ComboBoxBaseMixin(superClass) {
44
+ static get properties() {
45
+ return {
46
+ /**
47
+ * A full set of items to filter the visible options from.
48
+ * The items can be of either `String` or `Object` type.
49
+ * @type {!Array<!ComboBoxItem | string> | undefined}
50
+ */
51
+ items: {
52
+ type: Array,
53
+ sync: true,
54
+ observer: '_itemsChanged',
55
+ },
56
+
57
+ /**
58
+ * A subset of items, filtered based on the user input. Filtered items
59
+ * can be assigned directly to omit the internal filtering functionality.
60
+ * The items can be of either `String` or `Object` type.
61
+ * @type {!Array<!ComboBoxItem | string> | undefined}
62
+ */
63
+ filteredItems: {
64
+ type: Array,
65
+ observer: '_filteredItemsChanged',
66
+ sync: true,
67
+ },
68
+
69
+ /**
70
+ * Filtering string the user has typed into the input field.
71
+ * @type {string}
72
+ */
73
+ filter: {
74
+ type: String,
75
+ value: '',
76
+ notify: true,
77
+ sync: true,
78
+ },
79
+
80
+ /**
81
+ * Path for label of the item. If `items` is an array of objects, the
82
+ * `itemLabelPath` is used to fetch the displayed string label for each
83
+ * item.
84
+ *
85
+ * The item label is also used for matching items when processing user
86
+ * input, i.e., for filtering and selecting items.
87
+ * @attr {string} item-label-path
88
+ * @type {string}
89
+ */
90
+ itemLabelPath: {
91
+ type: String,
92
+ value: 'label',
93
+ observer: '_itemLabelPathChanged',
94
+ sync: true,
95
+ },
96
+
97
+ /**
98
+ * Path for the value of the item. If `items` is an array of objects, the
99
+ * `itemValuePath:` is used to fetch the string value for the selected
100
+ * item.
101
+ *
102
+ * The item value is used in the `value` property of the combo box,
103
+ * to provide the form value.
104
+ * @attr {string} item-value-path
105
+ * @type {string}
106
+ */
107
+ itemValuePath: {
108
+ type: String,
109
+ value: 'value',
110
+ sync: true,
111
+ },
112
+ };
113
+ }
114
+
115
+ /**
116
+ * @param {Object} props
117
+ * @protected
118
+ */
119
+ updated(props) {
120
+ super.updated(props);
121
+
122
+ if (props.has('filter')) {
123
+ this._filterChanged(this.filter);
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Override an event listener from `ComboBoxBaseMixin` to handle
129
+ * batched setting of both `opened` and `filter` properties.
130
+ * @param {!Event} event
131
+ * @protected
132
+ * @override
133
+ */
134
+ _onInput(event) {
135
+ const filter = this._inputElementValue;
136
+
137
+ // When opening dropdown on user input, both `opened` and `filter` properties are set.
138
+ // Perform a batched property update instead of relying on sync property observers.
139
+ // This is necessary to avoid an extra data-provider request for loading first page.
140
+ const props = {};
141
+
142
+ if (this.filter === filter) {
143
+ // Filter and input value might get out of sync, while keyboard navigating for example.
144
+ // Afterwards, input value might be changed to the same value as used in filtering.
145
+ // In situation like these, we need to make sure all the filter changes handlers are run.
146
+ this._filterChanged(this.filter);
147
+ } else {
148
+ props.filter = filter;
149
+ }
150
+
151
+ if (!this.opened && !this._isClearButton(event) && !this.autoOpenDisabled) {
152
+ props.opened = true;
153
+ }
154
+
155
+ this.setProperties(props);
156
+ }
157
+
158
+ /**
159
+ * Override method from `ComboBoxBaseMixin` to handle item label path.
160
+ * @protected
161
+ * @override
162
+ */
163
+ _getItemLabel(item) {
164
+ let label = item && this.itemLabelPath ? get(this.itemLabelPath, item) : undefined;
165
+ if (label === undefined || label === null) {
166
+ label = item ? item.toString() : '';
167
+ }
168
+ return label;
169
+ }
170
+
171
+ /** @protected */
172
+ _getItemValue(item) {
173
+ let value = item && this.itemValuePath ? get(this.itemValuePath, item) : undefined;
174
+ if (value === undefined) {
175
+ value = item ? item.toString() : '';
176
+ }
177
+ return value;
178
+ }
179
+
180
+ /** @private */
181
+ _itemLabelPathChanged(itemLabelPath) {
182
+ if (typeof itemLabelPath !== 'string') {
183
+ console.error('You should set itemLabelPath to a valid string');
184
+ }
185
+ }
186
+
187
+ /** @private */
188
+ _filterChanged(filter) {
189
+ // Scroll to the top of the list whenever the filter changes.
190
+ this._scrollIntoView(0);
191
+
192
+ this._focusedIndex = -1;
193
+
194
+ if (this.items) {
195
+ this.filteredItems = this._filterItems(this.items, filter);
196
+ } else {
197
+ // With certain use cases (e. g., external filtering), `items` are
198
+ // undefined. Filtering is unnecessary per se, but the filteredItems
199
+ // observer should still be invoked to update focused item.
200
+ this._filteredItemsChanged(this.filteredItems);
201
+ }
202
+ }
203
+
204
+ /** @private */
205
+ _itemsChanged(items, oldItems) {
206
+ this._ensureItemsOrDataProvider(() => {
207
+ this.items = oldItems;
208
+ });
209
+
210
+ if (items) {
211
+ this.filteredItems = items.slice(0);
212
+ } else if (oldItems) {
213
+ // Only clear filteredItems if the component had items previously but got cleared
214
+ this.filteredItems = null;
215
+ }
216
+ }
217
+
218
+ /** @private */
219
+ _filteredItemsChanged(filteredItems) {
220
+ this._setDropdownItems(filteredItems);
221
+ }
222
+
223
+ /**
224
+ * Provide items to be rendered in the dropdown.
225
+ * Override to provide actual implementation.
226
+ * @protected
227
+ */
228
+ _setDropdownItems() {
229
+ // To be implemented
230
+ }
231
+
232
+ /** @private */
233
+ _filterItems(arr, filter) {
234
+ if (!arr) {
235
+ return arr;
236
+ }
237
+
238
+ const filteredItems = arr.filter((item) => {
239
+ filter = filter ? filter.toString().toLowerCase() : '';
240
+ // Check if item contains input value.
241
+ return this._getItemLabel(item).toString().toLowerCase().indexOf(filter) > -1;
242
+ });
243
+
244
+ return filteredItems;
245
+ }
246
+
247
+ /**
248
+ * Returns the first item that matches the provided value.
249
+ * @protected
250
+ */
251
+ __getItemIndexByValue(items, value) {
252
+ if (!items || !isValidValue(value)) {
253
+ return -1;
254
+ }
255
+
256
+ return findItemIndex(items, (item) => {
257
+ return this._getItemValue(item) === value;
258
+ });
259
+ }
260
+
261
+ /**
262
+ * Returns the first item that matches the provided label.
263
+ * Labels are matched against each other case insensitively.
264
+ * @protected
265
+ */
266
+ __getItemIndexByLabel(items, label) {
267
+ if (!items || !label) {
268
+ return -1;
269
+ }
270
+
271
+ return findItemIndex(items, (item) => {
272
+ return this._getItemLabel(item).toString().toLowerCase() === label.toString().toLowerCase();
273
+ });
274
+ }
275
+ };
@@ -11,6 +11,7 @@ import type { OverlayClassMixinClass } from '@vaadin/component-base/src/overlay-
11
11
  import type { InputMixinClass } from '@vaadin/field-base/src/input-mixin.js';
12
12
  import type { ValidateMixinClass } from '@vaadin/field-base/src/validate-mixin.js';
13
13
  import type { ComboBox } from './vaadin-combo-box.js';
14
+ import type { ComboBoxBaseMixinClass } from './vaadin-combo-box-base-mixin.js';
14
15
  import type { ComboBoxDefaultItem, ComboBoxItemModel, ComboBoxItemRenderer } from './vaadin-combo-box-item-mixin.js';
15
16
 
16
17
  export type { ComboBoxDefaultItem, ComboBoxItemModel };
@@ -19,7 +20,8 @@ export type ComboBoxRenderer<TItem> = ComboBoxItemRenderer<TItem, ComboBox<TItem
19
20
 
20
21
  export declare function ComboBoxMixin<TItem, T extends Constructor<HTMLElement>>(
21
22
  base: T,
22
- ): Constructor<ComboBoxMixinClass<TItem>> &
23
+ ): Constructor<ComboBoxBaseMixinClass> &
24
+ Constructor<ComboBoxMixinClass<TItem>> &
23
25
  Constructor<DisabledMixinClass> &
24
26
  Constructor<FocusMixinClass> &
25
27
  Constructor<InputMixinClass> &
@@ -29,22 +31,6 @@ export declare function ComboBoxMixin<TItem, T extends Constructor<HTMLElement>>
29
31
  T;
30
32
 
31
33
  export declare class ComboBoxMixinClass<TItem> {
32
- /**
33
- * True if the dropdown is open, false otherwise.
34
- */
35
- opened: boolean;
36
-
37
- /**
38
- * Set true to prevent the overlay from opening automatically.
39
- * @attr {boolean} auto-open-disabled
40
- */
41
- autoOpenDisabled: boolean | null | undefined;
42
-
43
- /**
44
- * When present, it specifies that the field is read-only.
45
- */
46
- readonly: boolean;
47
-
48
34
  /**
49
35
  * Custom function for rendering the content of every item.
50
36
  * Receives three arguments:
@@ -58,12 +44,6 @@ export declare class ComboBoxMixinClass<TItem> {
58
44
  */
59
45
  renderer: ComboBoxRenderer<TItem> | null | undefined;
60
46
 
61
- /**
62
- * A full set of items to filter the visible options from.
63
- * The items can be of either `String` or `Object` type.
64
- */
65
- items: TItem[] | undefined;
66
-
67
47
  /**
68
48
  * A function used to generate CSS class names for dropdown
69
49
  * items based on the item. The return value should be the
@@ -81,13 +61,6 @@ export declare class ComboBoxMixinClass<TItem> {
81
61
  */
82
62
  allowCustomValue: boolean;
83
63
 
84
- /**
85
- * A subset of items, filtered based on the user input. Filtered items
86
- * can be assigned directly to omit the internal filtering functionality.
87
- * The items can be of either `String` or `Object` type.
88
- */
89
- filteredItems: TItem[] | undefined;
90
-
91
64
  /**
92
65
  * The `String` value for the selected item of the combo box.
93
66
  *
@@ -103,38 +76,11 @@ export declare class ComboBoxMixinClass<TItem> {
103
76
  */
104
77
  loading: boolean;
105
78
 
106
- /**
107
- * Filtering string the user has typed into the input field.
108
- */
109
- filter: string;
110
-
111
79
  /**
112
80
  * The selected item from the `items` array.
113
81
  */
114
82
  selectedItem: TItem | null | undefined;
115
83
 
116
- /**
117
- * Path for label of the item. If `items` is an array of objects, the
118
- * `itemLabelPath` is used to fetch the displayed string label for each
119
- * item.
120
- *
121
- * The item label is also used for matching items when processing user
122
- * input, i.e., for filtering and selecting items.
123
- * @attr {string} item-label-path
124
- */
125
- itemLabelPath: string;
126
-
127
- /**
128
- * Path for the value of the item. If `items` is an array of objects, the
129
- * `itemValuePath:` is used to fetch the string value for the selected
130
- * item.
131
- *
132
- * The item value is used in the `value` property of the combo box,
133
- * to provide the form value.
134
- * @attr {string} item-value-path
135
- */
136
- itemValuePath: string;
137
-
138
84
  /**
139
85
  * Path for the id of the item. If `items` is an array of objects,
140
86
  * the `itemIdPath` is used to compare and identify the same item
@@ -144,11 +90,6 @@ export declare class ComboBoxMixinClass<TItem> {
144
90
  */
145
91
  itemIdPath: string | null | undefined;
146
92
 
147
- /**
148
- * Tag name prefix used by scroller and items.
149
- */
150
- protected readonly _tagNamePrefix: string;
151
-
152
93
  /**
153
94
  * Requests an update for the content of items.
154
95
  * While performing the update, it invokes the renderer (passed in the `renderer` property) once an item.
@@ -156,14 +97,4 @@ export declare class ComboBoxMixinClass<TItem> {
156
97
  * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
157
98
  */
158
99
  requestContentUpdate(): void;
159
-
160
- /**
161
- * Opens the dropdown list.
162
- */
163
- open(): void;
164
-
165
- /**
166
- * Closes the dropdown list.
167
- */
168
- close(): void;
169
100
  }