@vaadin/combo-box 24.4.6 → 24.5.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/README.md CHANGED
@@ -64,7 +64,7 @@ import '@vaadin/combo-box/src/vaadin-combo-box.js';
64
64
 
65
65
  ## Contributing
66
66
 
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.
67
+ Read the [contributing guide](https://vaadin.com/docs/latest/contributing) 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/combo-box",
3
- "version": "24.4.6",
3
+ "version": "24.5.0-alpha10",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -40,27 +40,27 @@
40
40
  "dependencies": {
41
41
  "@open-wc/dedupe-mixin": "^1.3.0",
42
42
  "@polymer/polymer": "^3.0.0",
43
- "@vaadin/a11y-base": "~24.4.6",
44
- "@vaadin/component-base": "~24.4.6",
45
- "@vaadin/field-base": "~24.4.6",
46
- "@vaadin/input-container": "~24.4.6",
47
- "@vaadin/item": "~24.4.6",
48
- "@vaadin/lit-renderer": "~24.4.6",
49
- "@vaadin/overlay": "~24.4.6",
50
- "@vaadin/vaadin-lumo-styles": "~24.4.6",
51
- "@vaadin/vaadin-material-styles": "~24.4.6",
52
- "@vaadin/vaadin-themable-mixin": "~24.4.6"
43
+ "@vaadin/a11y-base": "24.5.0-alpha10",
44
+ "@vaadin/component-base": "24.5.0-alpha10",
45
+ "@vaadin/field-base": "24.5.0-alpha10",
46
+ "@vaadin/input-container": "24.5.0-alpha10",
47
+ "@vaadin/item": "24.5.0-alpha10",
48
+ "@vaadin/lit-renderer": "24.5.0-alpha10",
49
+ "@vaadin/overlay": "24.5.0-alpha10",
50
+ "@vaadin/vaadin-lumo-styles": "24.5.0-alpha10",
51
+ "@vaadin/vaadin-material-styles": "24.5.0-alpha10",
52
+ "@vaadin/vaadin-themable-mixin": "24.5.0-alpha10"
53
53
  },
54
54
  "devDependencies": {
55
- "@esm-bundle/chai": "^4.3.4",
56
- "@vaadin/testing-helpers": "^0.6.0",
57
- "@vaadin/text-field": "~24.4.6",
55
+ "@vaadin/chai-plugins": "24.5.0-alpha10",
56
+ "@vaadin/testing-helpers": "^1.0.0",
57
+ "@vaadin/text-field": "24.5.0-alpha10",
58
58
  "lit": "^3.0.0",
59
- "sinon": "^13.0.2"
59
+ "sinon": "^18.0.0"
60
60
  },
61
61
  "web-types": [
62
62
  "web-types.json",
63
63
  "web-types.lit.json"
64
64
  ],
65
- "gitHead": "46d3cdb72eb99d544c7bb86c3de95043b9e5857f"
65
+ "gitHead": "6f9c37308031af872a98017bfab4de89aeacda51"
66
66
  }
@@ -3,6 +3,7 @@
3
3
  * Copyright (c) 2015 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { DataProviderController } from '@vaadin/component-base/src/data-provider-controller/data-provider-controller.js';
6
7
  import { ComboBoxPlaceholder } from './vaadin-combo-box-placeholder.js';
7
8
 
8
9
  /**
@@ -55,15 +56,9 @@ export const ComboBoxDataProviderMixin = (superClass) =>
55
56
  },
56
57
 
57
58
  /** @private */
58
- _pendingRequests: {
59
- value: () => {
60
- return {};
61
- },
62
- },
63
-
64
- /** @private */
65
- __placeHolder: {
66
- value: new ComboBoxPlaceholder(),
59
+ __dataProviderInitialized: {
60
+ type: Boolean,
61
+ value: false,
67
62
  },
68
63
 
69
64
  /** @private */
@@ -81,6 +76,23 @@ export const ComboBoxDataProviderMixin = (superClass) =>
81
76
  ];
82
77
  }
83
78
 
79
+ constructor() {
80
+ super();
81
+
82
+ /**
83
+ * @type {DataProviderController}
84
+ * @private
85
+ */
86
+ this.__dataProviderController = new DataProviderController(this, {
87
+ placeholder: new ComboBoxPlaceholder(),
88
+ isPlaceholder: (item) => item instanceof ComboBoxPlaceholder,
89
+ dataProviderParams: () => ({ filter: this.filter }),
90
+ });
91
+
92
+ this.__dataProviderController.addEventListener('page-requested', this.__onDataProviderPageRequested.bind(this));
93
+ this.__dataProviderController.addEventListener('page-loaded', this.__onDataProviderPageLoaded.bind(this));
94
+ }
95
+
84
96
  /** @protected */
85
97
  ready() {
86
98
  super.ready();
@@ -91,12 +103,15 @@ export const ComboBoxDataProviderMixin = (superClass) =>
91
103
 
92
104
  const index = e.detail.index;
93
105
  if (index !== undefined) {
94
- const page = this._getPageForIndex(index);
95
- if (this._shouldLoadPage(page)) {
96
- this._loadPage(page);
97
- }
106
+ this.__dataProviderController.ensureFlatIndexLoaded(index);
98
107
  }
99
108
  });
109
+
110
+ this.__dataProviderInitialized = true;
111
+
112
+ if (this.dataProvider) {
113
+ this.requestContentUpdate();
114
+ }
100
115
  }
101
116
 
102
117
  /** @private */
@@ -110,7 +125,6 @@ export const ComboBoxDataProviderMixin = (superClass) =>
110
125
  this.__previousDataProviderFilter = filter;
111
126
 
112
127
  this.__keepOverlayOpened = true;
113
- this._pendingRequests = {};
114
128
  this.size = undefined;
115
129
  this.clearCache();
116
130
  this.__keepOverlayOpened = false;
@@ -128,78 +142,35 @@ export const ComboBoxDataProviderMixin = (superClass) =>
128
142
 
129
143
  /** @private */
130
144
  _ensureFirstPage(opened) {
131
- if (!this._shouldFetchData()) {
145
+ if (!this._shouldFetchData() || !opened) {
132
146
  return;
133
147
  }
134
148
 
135
- if (opened && this._shouldLoadPage(0)) {
136
- this._loadPage(0);
137
- }
138
- }
139
-
140
- /** @private */
141
- _shouldLoadPage(page) {
142
- if (this._forceNextRequest) {
149
+ if (this._forceNextRequest || this.size === undefined) {
143
150
  this._forceNextRequest = false;
144
- return true;
145
- }
146
-
147
- const loadedItem = this.filteredItems[page * this.pageSize];
148
- if (loadedItem !== undefined) {
149
- return loadedItem instanceof ComboBoxPlaceholder;
151
+ this.__dataProviderController.loadFirstPage();
152
+ } else if (this.size > 0) {
153
+ this.__dataProviderController.ensureFlatIndexLoaded(0);
150
154
  }
151
- return this.size === undefined;
152
155
  }
153
156
 
154
157
  /** @private */
155
- _loadPage(page) {
156
- // Make sure same page isn't requested multiple times.
157
- if (this._pendingRequests[page] || !this.dataProvider) {
158
- return;
159
- }
160
-
161
- const params = {
162
- page,
163
- pageSize: this.pageSize,
164
- filter: this.filter,
165
- };
166
-
167
- const callback = (items, size) => {
168
- if (this._pendingRequests[page] !== callback) {
169
- return;
170
- }
171
-
172
- const filteredItems = this.filteredItems ? [...this.filteredItems] : [];
173
- filteredItems.splice(params.page * params.pageSize, items.length, ...items);
174
- this.filteredItems = filteredItems;
175
-
176
- if (!this.opened && !this._isInputFocused()) {
177
- this._commitValue();
178
- }
179
-
180
- if (size !== undefined) {
181
- this.size = size;
182
- }
183
-
184
- delete this._pendingRequests[page];
185
-
186
- if (Object.keys(this._pendingRequests).length === 0) {
187
- this.loading = false;
188
- }
189
- };
190
-
191
- this._pendingRequests[page] = callback;
192
- // Set the `loading` flag only after marking the request as pending
193
- // to prevent the same page from getting requested multiple times
194
- // as a result of `__loadingChanged` in the scroller which requests
195
- // a virtualizer update which in turn may trigger a data provider page request.
158
+ __onDataProviderPageRequested() {
196
159
  this.loading = true;
197
- this.dataProvider(params, callback);
198
160
  }
199
161
 
200
162
  /** @private */
201
- _getPageForIndex(index) {
202
- return Math.floor(index / this.pageSize);
163
+ __onDataProviderPageLoaded() {
164
+ // The controller adds new items to the cache through mutation,
165
+ // so we need to create a new array to trigger filteredItems observers.
166
+ const { rootCache } = this.__dataProviderController;
167
+ rootCache.items = [...rootCache.items];
168
+
169
+ this.requestContentUpdate();
170
+
171
+ if (!this.opened && !this._isInputFocused()) {
172
+ this._commitValue();
173
+ }
203
174
  }
204
175
 
205
176
  /**
@@ -210,32 +181,75 @@ export const ComboBoxDataProviderMixin = (superClass) =>
210
181
  return;
211
182
  }
212
183
 
213
- this._pendingRequests = {};
214
- const filteredItems = [];
215
- for (let i = 0; i < (this.size || 0); i++) {
216
- filteredItems.push(this.__placeHolder);
217
- }
218
- this.filteredItems = filteredItems;
184
+ this.__dataProviderController.clearCache();
185
+
186
+ this.requestContentUpdate();
219
187
 
220
188
  if (this._shouldFetchData()) {
221
189
  this._forceNextRequest = false;
222
- this._loadPage(0);
190
+ this.__dataProviderController.loadFirstPage();
223
191
  } else {
224
192
  this._forceNextRequest = true;
225
193
  }
226
194
  }
227
195
 
228
- /** @private */
229
- _sizeChanged(size = 0) {
230
- const filteredItems = (this.filteredItems || []).slice(0, size);
231
- for (let i = 0; i < size; i++) {
232
- filteredItems[i] = filteredItems[i] !== undefined ? filteredItems[i] : this.__placeHolder;
196
+ /**
197
+ * When the size change originates externally, synchronizes the new size with
198
+ * the controller and request a content update to re-render the scroller.
199
+ *
200
+ * @private
201
+ */
202
+ _sizeChanged(size) {
203
+ const { rootCache } = this.__dataProviderController;
204
+ if (rootCache.size !== size) {
205
+ rootCache.size = size;
206
+ // The controller adds new placeholders to the cache through mutation,
207
+ // so we need to create a new array to trigger filteredItems observers.
208
+ rootCache.items = [...rootCache.items];
209
+ this.requestContentUpdate();
210
+ }
211
+ }
212
+
213
+ /**
214
+ * When the items change originates externally, synchronizes the new items with
215
+ * the controller and requests a content update to re-render the scroller.
216
+ *
217
+ * @private
218
+ * @override
219
+ */
220
+ _filteredItemsChanged(items) {
221
+ super._filteredItemsChanged(items);
222
+
223
+ if (this.dataProvider && items) {
224
+ const { rootCache } = this.__dataProviderController;
225
+ if (rootCache.items !== items) {
226
+ rootCache.items = items;
227
+ this.requestContentUpdate();
228
+ }
229
+ }
230
+ }
231
+
232
+ /**
233
+ * Synchronizes the controller's state with the component, which can be
234
+ * out of sync after the controller receives new data from the data provider
235
+ * or if the state in the controller is directly manupulated.
236
+ *
237
+ * @override
238
+ */
239
+ requestContentUpdate() {
240
+ // When the data provider isn't initialized, it means the content update was requested
241
+ // by an observer before the `ready()` callback. In such cases, some properties
242
+ // in the data provider controller might still be uninitialized, so it's not safe
243
+ // to use them to update the component's properties yet. Another content update
244
+ // will be requested in the `ready()` callback.
245
+ if (this.__dataProviderInitialized && this.dataProvider) {
246
+ const { rootCache } = this.__dataProviderController;
247
+ this.size = rootCache.size;
248
+ this.filteredItems = rootCache.items;
249
+ this.loading = this.__dataProviderController.isLoading();
233
250
  }
234
- this.filteredItems = filteredItems;
235
251
 
236
- // Cleans up the redundant pending requests for pages > size
237
- // Refers to https://github.com/vaadin/vaadin-flow-components/issues/229
238
- this._flushPendingRequests(size);
252
+ super.requestContentUpdate();
239
253
  }
240
254
 
241
255
  /** @private */
@@ -244,6 +258,8 @@ export const ComboBoxDataProviderMixin = (superClass) =>
244
258
  this.pageSize = oldPageSize;
245
259
  throw new Error('`pageSize` value must be an integer > 0');
246
260
  }
261
+
262
+ this.__dataProviderController.setPageSize(pageSize);
247
263
  this.clearCache();
248
264
  }
249
265
 
@@ -253,6 +269,7 @@ export const ComboBoxDataProviderMixin = (superClass) =>
253
269
  this.dataProvider = oldDataProvider;
254
270
  });
255
271
 
272
+ this.__dataProviderController.setDataProvider(dataProvider);
256
273
  this.clearCache();
257
274
  }
258
275
 
@@ -261,8 +278,6 @@ export const ComboBoxDataProviderMixin = (superClass) =>
261
278
  if (this.items !== undefined && this.dataProvider !== undefined) {
262
279
  restoreOldValueCallback();
263
280
  throw new Error('Using `items` and `dataProvider` together is not supported');
264
- } else if (this.dataProvider && !this.filteredItems) {
265
- this.filteredItems = [];
266
281
  }
267
282
  }
268
283
 
@@ -281,28 +296,4 @@ export const ComboBoxDataProviderMixin = (superClass) =>
281
296
  }
282
297
  }
283
298
  }
284
-
285
- /**
286
- * This method cleans up the page callbacks which refers to the
287
- * non-existing pages, i.e. which item indexes are greater than the
288
- * changed size.
289
- * This case is basically happens when:
290
- * 1. Users scroll fast to the bottom and combo box generates the
291
- * redundant page request/callback
292
- * 2. Server side uses undefined size lazy loading and suddenly reaches
293
- * the exact size which is on the range edge
294
- * (for default page size = 50, it will be 100, 200, 300, ...).
295
- * @param size the new size of items
296
- * @private
297
- */
298
- _flushPendingRequests(size) {
299
- if (this._pendingRequests) {
300
- const lastPage = Math.ceil(size / this.pageSize);
301
- Object.entries(this._pendingRequests).forEach(([page, callback]) => {
302
- if (parseInt(page) >= lastPage) {
303
- callback([], size);
304
- }
305
- });
306
- }
307
- }
308
299
  };
@@ -64,6 +64,14 @@ export declare class ComboBoxMixinClass<TItem> {
64
64
  */
65
65
  items: TItem[] | undefined;
66
66
 
67
+ /**
68
+ * A function used to generate CSS class names for dropdown
69
+ * items based on the item. The return value should be the
70
+ * generated class name as a string, or multiple class names
71
+ * separated by whitespace characters.
72
+ */
73
+ itemClassNameGenerator: (item: TItem) => string;
74
+
67
75
  /**
68
76
  * If `true`, the user can input a value that is not present in the items list.
69
77
  * `value` property will be set to the input value in this case.
@@ -196,6 +196,16 @@ export const ComboBoxMixin = (subclass) =>
196
196
  sync: true,
197
197
  },
198
198
 
199
+ /**
200
+ * A function used to generate CSS class names for dropdown
201
+ * items based on the item. The return value should be the
202
+ * generated class name as a string, or multiple class names
203
+ * separated by whitespace characters.
204
+ */
205
+ itemClassNameGenerator: {
206
+ type: Object,
207
+ },
208
+
199
209
  /**
200
210
  * Path for label of the item. If `items` is an array of objects, the
201
211
  * `itemLabelPath` is used to fetch the displayed string label for each
@@ -287,7 +297,7 @@ export const ComboBoxMixin = (subclass) =>
287
297
  return [
288
298
  '_selectedItemChanged(selectedItem, itemValuePath, itemLabelPath)',
289
299
  '_openedOrItemsChanged(opened, _dropdownItems, loading, __keepOverlayOpened)',
290
- '_updateScroller(_scroller, _dropdownItems, opened, loading, selectedItem, itemIdPath, _focusedIndex, renderer, _theme)',
300
+ '_updateScroller(_scroller, _dropdownItems, opened, loading, selectedItem, itemIdPath, _focusedIndex, renderer, _theme, itemClassNameGenerator)',
291
301
  ];
292
302
  }
293
303
 
@@ -502,8 +512,19 @@ export const ComboBoxMixin = (subclass) =>
502
512
  }
503
513
 
504
514
  /** @private */
505
- // eslint-disable-next-line max-params
506
- _updateScroller(scroller, items, opened, loading, selectedItem, itemIdPath, focusedIndex, renderer, theme) {
515
+ // eslint-disable-next-line @typescript-eslint/max-params
516
+ _updateScroller(
517
+ scroller,
518
+ items,
519
+ opened,
520
+ loading,
521
+ selectedItem,
522
+ itemIdPath,
523
+ focusedIndex,
524
+ renderer,
525
+ theme,
526
+ itemClassNameGenerator,
527
+ ) {
507
528
  if (scroller) {
508
529
  if (opened) {
509
530
  scroller.style.maxHeight =
@@ -519,6 +540,7 @@ export const ComboBoxMixin = (subclass) =>
519
540
  focusedIndex,
520
541
  renderer,
521
542
  theme,
543
+ itemClassNameGenerator,
522
544
  });
523
545
 
524
546
  // NOTE: in PolylitMixin, setProperties() waits for `hasUpdated` to be set.
@@ -63,6 +63,17 @@ export const ComboBoxScrollerMixin = (superClass) =>
63
63
  observer: '__selectedItemChanged',
64
64
  },
65
65
 
66
+ /**
67
+ * A function used to generate CSS class names for dropdown
68
+ * items based on the item. The return value should be the
69
+ * generated class name as a string, or multiple class names
70
+ * separated by whitespace characters.
71
+ */
72
+ itemClassNameGenerator: {
73
+ type: Object,
74
+ observer: '__itemClassNameGeneratorChanged',
75
+ },
76
+
66
77
  /**
67
78
  * Path for the id of the item, used to detect whether the item is selected.
68
79
  */
@@ -254,6 +265,13 @@ export const ComboBoxScrollerMixin = (superClass) =>
254
265
  this.requestContentUpdate();
255
266
  }
256
267
 
268
+ /** @private */
269
+ __itemClassNameGeneratorChanged(generator, oldGenerator) {
270
+ if (generator || oldGenerator) {
271
+ this.requestContentUpdate();
272
+ }
273
+ }
274
+
257
275
  /** @private */
258
276
  __focusedIndexChanged(index, oldIndex) {
259
277
  if (index !== oldIndex) {
@@ -305,6 +323,12 @@ export const ComboBoxScrollerMixin = (superClass) =>
305
323
  focused: !this.loading && focusedIndex === index,
306
324
  });
307
325
 
326
+ if (typeof this.itemClassNameGenerator === 'function') {
327
+ el.className = this.itemClassNameGenerator(item);
328
+ } else if (el.className !== '') {
329
+ el.className = '';
330
+ }
331
+
308
332
  // NOTE: in PolylitMixin, setProperties() waits for `hasUpdated` to be set.
309
333
  // However, this causes issues with virtualizer. So we enforce sync update.
310
334
  if (el.performUpdate && !el.hasUpdated) {
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/combo-box",
4
- "version": "24.4.6",
4
+ "version": "24.5.0-alpha10",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -375,6 +375,17 @@
375
375
  ]
376
376
  }
377
377
  },
378
+ {
379
+ "name": "itemClassNameGenerator",
380
+ "description": "A function used to generate CSS class names for dropdown\nitems based on the item. The return value should be the\ngenerated class name as a string, or multiple class names\nseparated by whitespace characters.",
381
+ "value": {
382
+ "type": [
383
+ "Object",
384
+ "null",
385
+ "undefined"
386
+ ]
387
+ }
388
+ },
378
389
  {
379
390
  "name": "itemLabelPath",
380
391
  "description": "Path for label of the item. If `items` is an array of objects, the\n`itemLabelPath` is used to fetch the displayed string label for each\nitem.\n\nThe item label is also used for matching items when processing user\ninput, i.e., for filtering and selecting items.",
@@ -460,7 +471,7 @@
460
471
  },
461
472
  {
462
473
  "name": "vaadin-combo-box",
463
- "description": "`<vaadin-combo-box>` is a web component for choosing a value from a filterable list of options\npresented in a dropdown overlay. The options can be provided as a list of strings or objects\nby setting [`items`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-combo-box#property-items) property on the element.\n\n```html\n<vaadin-combo-box id=\"combo-box\"></vaadin-combo-box>\n```\n```js\ndocument.querySelector('#combo-box').items = ['apple', 'orange', 'banana'];\n```\n\nWhen the selected `value` is changed, a `value-changed` event is triggered.\n\n### Item rendering\n\nTo customize the content of the `<vaadin-combo-box-item>` elements placed in the dropdown, use\n[`renderer`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-combo-box#property-renderer) property which accepts a function.\nThe renderer function is called with `root`, `comboBox`, and `model` as arguments.\n\nGenerate DOM content by using `model` object properties if needed, and append it to the `root`\nelement. The `comboBox` reference is provided to access the combo-box element state. Do not\nset combo-box properties in a `renderer` function.\n\n```js\nconst comboBox = document.querySelector('#combo-box');\ncomboBox.items = [{'label': 'Hydrogen', 'value': 'H'}];\ncomboBox.renderer = (root, comboBox, model) => {\n const item = model.item;\n root.innerHTML = `${model.index}: ${item.label} <b>${item.value}</b>`;\n};\n```\n\nRenderer is called on the opening of the combo-box and each time the related model is updated.\nBefore creating new content, it is recommended to check if there is already an existing DOM\nelement in `root` from a previous renderer call for reusing it. Even though combo-box uses\ninfinite scrolling, reducing DOM operations might improve performance.\n\nThe following properties are available in the `model` argument:\n\nProperty | Type | Description\n-----------|------------------|-------------\n`index` | Number | Index of the item in the `items` array\n`item` | String or Object | The item reference\n`selected` | Boolean | True when item is selected\n`focused` | Boolean | True when item is focused\n\n### Lazy Loading with Function Data Provider\n\nIn addition to assigning an array to the items property, you can alternatively use the\n[`dataProvider`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-combo-box#property-dataProvider) function property.\nThe `<vaadin-combo-box>` calls this function lazily, only when it needs more data\nto be displayed.\n\n__Note that when using function data providers, the total number of items\nneeds to be set manually. The total number of items can be returned\nin the second argument of the data provider callback:__\n\n```js\ncomboBox.dataProvider = async (params, callback) => {\n const API = 'https://demo.vaadin.com/demo-data/1.0/filtered-countries';\n const { filter, page, pageSize } = params;\n const index = page * pageSize;\n\n const res = await fetch(`${API}?index=${index}&count=${pageSize}&filter=${filter}`);\n if (res.ok) {\n const { result, size } = await res.json();\n callback(result, size);\n }\n};\n```\n\n### Styling\n\nThe following custom properties are available for styling:\n\nCustom property | Description | Default\n----------------------------------------|----------------------------|---------\n`--vaadin-field-default-width` | Default width of the field | `12em`\n`--vaadin-combo-box-overlay-width` | Width of the overlay | `auto`\n`--vaadin-combo-box-overlay-max-height` | Max height of the overlay | `65vh`\n\n`<vaadin-combo-box>` provides the same set of shadow DOM parts and state attributes as `<vaadin-text-field>`.\nSee [`<vaadin-text-field>`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-text-field) for the styling documentation.\n\nIn addition to `<vaadin-text-field>` parts, the following parts are available for theming:\n\nPart name | Description\n----------------|----------------\n`toggle-button` | The toggle button\n\nIn addition to `<vaadin-text-field>` state attributes, the following state attributes are available for theming:\n\nAttribute | Description | Part name\n----------|-------------|------------\n`opened` | Set when the combo box dropdown is open | :host\n`loading` | Set when new items are expected | :host\n\nIf you want to replace the default `<input>` and its container with a custom implementation to get full control\nover the input field, consider using the [`<vaadin-combo-box-light>`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-combo-box-light) element.\n\n### Internal components\n\nIn addition to `<vaadin-combo-box>` itself, the following internal\ncomponents are themable:\n\n- `<vaadin-combo-box-overlay>` - has the same API as [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-overlay).\n- `<vaadin-combo-box-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-item).\n- [`<vaadin-input-container>`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-input-container) - an internal element wrapping the input.\n\nNote: the `theme` attribute value set on `<vaadin-combo-box>` is\npropagated to the internal components listed above.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.",
474
+ "description": "`<vaadin-combo-box>` is a web component for choosing a value from a filterable list of options\npresented in a dropdown overlay. The options can be provided as a list of strings or objects\nby setting [`items`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-combo-box#property-items) property on the element.\n\n```html\n<vaadin-combo-box id=\"combo-box\"></vaadin-combo-box>\n```\n```js\ndocument.querySelector('#combo-box').items = ['apple', 'orange', 'banana'];\n```\n\nWhen the selected `value` is changed, a `value-changed` event is triggered.\n\n### Item rendering\n\nTo customize the content of the `<vaadin-combo-box-item>` elements placed in the dropdown, use\n[`renderer`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-combo-box#property-renderer) property which accepts a function.\nThe renderer function is called with `root`, `comboBox`, and `model` as arguments.\n\nGenerate DOM content by using `model` object properties if needed, and append it to the `root`\nelement. The `comboBox` reference is provided to access the combo-box element state. Do not\nset combo-box properties in a `renderer` function.\n\n```js\nconst comboBox = document.querySelector('#combo-box');\ncomboBox.items = [{'label': 'Hydrogen', 'value': 'H'}];\ncomboBox.renderer = (root, comboBox, model) => {\n const item = model.item;\n root.innerHTML = `${model.index}: ${item.label} <b>${item.value}</b>`;\n};\n```\n\nRenderer is called on the opening of the combo-box and each time the related model is updated.\nBefore creating new content, it is recommended to check if there is already an existing DOM\nelement in `root` from a previous renderer call for reusing it. Even though combo-box uses\ninfinite scrolling, reducing DOM operations might improve performance.\n\nThe following properties are available in the `model` argument:\n\nProperty | Type | Description\n-----------|------------------|-------------\n`index` | Number | Index of the item in the `items` array\n`item` | String or Object | The item reference\n`selected` | Boolean | True when item is selected\n`focused` | Boolean | True when item is focused\n\n### Lazy Loading with Function Data Provider\n\nIn addition to assigning an array to the items property, you can alternatively use the\n[`dataProvider`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-combo-box#property-dataProvider) function property.\nThe `<vaadin-combo-box>` calls this function lazily, only when it needs more data\nto be displayed.\n\n__Note that when using function data providers, the total number of items\nneeds to be set manually. The total number of items can be returned\nin the second argument of the data provider callback:__\n\n```js\ncomboBox.dataProvider = async (params, callback) => {\n const API = 'https://demo.vaadin.com/demo-data/1.0/filtered-countries';\n const { filter, page, pageSize } = params;\n const index = page * pageSize;\n\n const res = await fetch(`${API}?index=${index}&count=${pageSize}&filter=${filter}`);\n if (res.ok) {\n const { result, size } = await res.json();\n callback(result, size);\n }\n};\n```\n\n### Styling\n\nThe following custom properties are available for styling:\n\nCustom property | Description | Default\n----------------------------------------|----------------------------|---------\n`--vaadin-field-default-width` | Default width of the field | `12em`\n`--vaadin-combo-box-overlay-width` | Width of the overlay | `auto`\n`--vaadin-combo-box-overlay-max-height` | Max height of the overlay | `65vh`\n\n`<vaadin-combo-box>` provides the same set of shadow DOM parts and state attributes as `<vaadin-text-field>`.\nSee [`<vaadin-text-field>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-text-field) for the styling documentation.\n\nIn addition to `<vaadin-text-field>` parts, the following parts are available for theming:\n\nPart name | Description\n----------------|----------------\n`toggle-button` | The toggle button\n\nIn addition to `<vaadin-text-field>` state attributes, the following state attributes are available for theming:\n\nAttribute | Description | Part name\n----------|-------------|------------\n`opened` | Set when the combo box dropdown is open | :host\n`loading` | Set when new items are expected | :host\n\nIf you want to replace the default `<input>` and its container with a custom implementation to get full control\nover the input field, consider using the [`<vaadin-combo-box-light>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-combo-box-light) element.\n\n### Internal components\n\nIn addition to `<vaadin-combo-box>` itself, the following internal\ncomponents are themable:\n\n- `<vaadin-combo-box-overlay>` - has the same API as [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-overlay).\n- `<vaadin-combo-box-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-item).\n- [`<vaadin-input-container>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-input-container) - an internal element wrapping the input.\n\nNote: the `theme` attribute value set on `<vaadin-combo-box>` is\npropagated to the internal components listed above.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.",
464
475
  "attributes": [
465
476
  {
466
477
  "name": "disabled",
@@ -1104,6 +1115,17 @@
1104
1115
  ]
1105
1116
  }
1106
1117
  },
1118
+ {
1119
+ "name": "itemClassNameGenerator",
1120
+ "description": "A function used to generate CSS class names for dropdown\nitems based on the item. The return value should be the\ngenerated class name as a string, or multiple class names\nseparated by whitespace characters.",
1121
+ "value": {
1122
+ "type": [
1123
+ "Object",
1124
+ "null",
1125
+ "undefined"
1126
+ ]
1127
+ }
1128
+ },
1107
1129
  {
1108
1130
  "name": "itemLabelPath",
1109
1131
  "description": "Path for label of the item. If `items` is an array of objects, the\n`itemLabelPath` is used to fetch the displayed string label for each\nitem.\n\nThe item label is also used for matching items when processing user\ninput, i.e., for filtering and selecting items.",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/combo-box",
4
- "version": "24.4.6",
4
+ "version": "24.5.0-alpha10",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {
@@ -145,6 +145,13 @@
145
145
  "kind": "expression"
146
146
  }
147
147
  },
148
+ {
149
+ "name": ".itemClassNameGenerator",
150
+ "description": "A function used to generate CSS class names for dropdown\nitems based on the item. The return value should be the\ngenerated class name as a string, or multiple class names\nseparated by whitespace characters.",
151
+ "value": {
152
+ "kind": "expression"
153
+ }
154
+ },
148
155
  {
149
156
  "name": ".itemLabelPath",
150
157
  "description": "Path for label of the item. If `items` is an array of objects, the\n`itemLabelPath` is used to fetch the displayed string label for each\nitem.\n\nThe item label is also used for matching items when processing user\ninput, i.e., for filtering and selecting items.",
@@ -247,7 +254,7 @@
247
254
  },
248
255
  {
249
256
  "name": "vaadin-combo-box",
250
- "description": "`<vaadin-combo-box>` is a web component for choosing a value from a filterable list of options\npresented in a dropdown overlay. The options can be provided as a list of strings or objects\nby setting [`items`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-combo-box#property-items) property on the element.\n\n```html\n<vaadin-combo-box id=\"combo-box\"></vaadin-combo-box>\n```\n```js\ndocument.querySelector('#combo-box').items = ['apple', 'orange', 'banana'];\n```\n\nWhen the selected `value` is changed, a `value-changed` event is triggered.\n\n### Item rendering\n\nTo customize the content of the `<vaadin-combo-box-item>` elements placed in the dropdown, use\n[`renderer`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-combo-box#property-renderer) property which accepts a function.\nThe renderer function is called with `root`, `comboBox`, and `model` as arguments.\n\nGenerate DOM content by using `model` object properties if needed, and append it to the `root`\nelement. The `comboBox` reference is provided to access the combo-box element state. Do not\nset combo-box properties in a `renderer` function.\n\n```js\nconst comboBox = document.querySelector('#combo-box');\ncomboBox.items = [{'label': 'Hydrogen', 'value': 'H'}];\ncomboBox.renderer = (root, comboBox, model) => {\n const item = model.item;\n root.innerHTML = `${model.index}: ${item.label} <b>${item.value}</b>`;\n};\n```\n\nRenderer is called on the opening of the combo-box and each time the related model is updated.\nBefore creating new content, it is recommended to check if there is already an existing DOM\nelement in `root` from a previous renderer call for reusing it. Even though combo-box uses\ninfinite scrolling, reducing DOM operations might improve performance.\n\nThe following properties are available in the `model` argument:\n\nProperty | Type | Description\n-----------|------------------|-------------\n`index` | Number | Index of the item in the `items` array\n`item` | String or Object | The item reference\n`selected` | Boolean | True when item is selected\n`focused` | Boolean | True when item is focused\n\n### Lazy Loading with Function Data Provider\n\nIn addition to assigning an array to the items property, you can alternatively use the\n[`dataProvider`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-combo-box#property-dataProvider) function property.\nThe `<vaadin-combo-box>` calls this function lazily, only when it needs more data\nto be displayed.\n\n__Note that when using function data providers, the total number of items\nneeds to be set manually. The total number of items can be returned\nin the second argument of the data provider callback:__\n\n```js\ncomboBox.dataProvider = async (params, callback) => {\n const API = 'https://demo.vaadin.com/demo-data/1.0/filtered-countries';\n const { filter, page, pageSize } = params;\n const index = page * pageSize;\n\n const res = await fetch(`${API}?index=${index}&count=${pageSize}&filter=${filter}`);\n if (res.ok) {\n const { result, size } = await res.json();\n callback(result, size);\n }\n};\n```\n\n### Styling\n\nThe following custom properties are available for styling:\n\nCustom property | Description | Default\n----------------------------------------|----------------------------|---------\n`--vaadin-field-default-width` | Default width of the field | `12em`\n`--vaadin-combo-box-overlay-width` | Width of the overlay | `auto`\n`--vaadin-combo-box-overlay-max-height` | Max height of the overlay | `65vh`\n\n`<vaadin-combo-box>` provides the same set of shadow DOM parts and state attributes as `<vaadin-text-field>`.\nSee [`<vaadin-text-field>`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-text-field) for the styling documentation.\n\nIn addition to `<vaadin-text-field>` parts, the following parts are available for theming:\n\nPart name | Description\n----------------|----------------\n`toggle-button` | The toggle button\n\nIn addition to `<vaadin-text-field>` state attributes, the following state attributes are available for theming:\n\nAttribute | Description | Part name\n----------|-------------|------------\n`opened` | Set when the combo box dropdown is open | :host\n`loading` | Set when new items are expected | :host\n\nIf you want to replace the default `<input>` and its container with a custom implementation to get full control\nover the input field, consider using the [`<vaadin-combo-box-light>`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-combo-box-light) element.\n\n### Internal components\n\nIn addition to `<vaadin-combo-box>` itself, the following internal\ncomponents are themable:\n\n- `<vaadin-combo-box-overlay>` - has the same API as [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-overlay).\n- `<vaadin-combo-box-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-item).\n- [`<vaadin-input-container>`](https://cdn.vaadin.com/vaadin-web-components/24.4.6/#/elements/vaadin-input-container) - an internal element wrapping the input.\n\nNote: the `theme` attribute value set on `<vaadin-combo-box>` is\npropagated to the internal components listed above.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.",
257
+ "description": "`<vaadin-combo-box>` is a web component for choosing a value from a filterable list of options\npresented in a dropdown overlay. The options can be provided as a list of strings or objects\nby setting [`items`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-combo-box#property-items) property on the element.\n\n```html\n<vaadin-combo-box id=\"combo-box\"></vaadin-combo-box>\n```\n```js\ndocument.querySelector('#combo-box').items = ['apple', 'orange', 'banana'];\n```\n\nWhen the selected `value` is changed, a `value-changed` event is triggered.\n\n### Item rendering\n\nTo customize the content of the `<vaadin-combo-box-item>` elements placed in the dropdown, use\n[`renderer`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-combo-box#property-renderer) property which accepts a function.\nThe renderer function is called with `root`, `comboBox`, and `model` as arguments.\n\nGenerate DOM content by using `model` object properties if needed, and append it to the `root`\nelement. The `comboBox` reference is provided to access the combo-box element state. Do not\nset combo-box properties in a `renderer` function.\n\n```js\nconst comboBox = document.querySelector('#combo-box');\ncomboBox.items = [{'label': 'Hydrogen', 'value': 'H'}];\ncomboBox.renderer = (root, comboBox, model) => {\n const item = model.item;\n root.innerHTML = `${model.index}: ${item.label} <b>${item.value}</b>`;\n};\n```\n\nRenderer is called on the opening of the combo-box and each time the related model is updated.\nBefore creating new content, it is recommended to check if there is already an existing DOM\nelement in `root` from a previous renderer call for reusing it. Even though combo-box uses\ninfinite scrolling, reducing DOM operations might improve performance.\n\nThe following properties are available in the `model` argument:\n\nProperty | Type | Description\n-----------|------------------|-------------\n`index` | Number | Index of the item in the `items` array\n`item` | String or Object | The item reference\n`selected` | Boolean | True when item is selected\n`focused` | Boolean | True when item is focused\n\n### Lazy Loading with Function Data Provider\n\nIn addition to assigning an array to the items property, you can alternatively use the\n[`dataProvider`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-combo-box#property-dataProvider) function property.\nThe `<vaadin-combo-box>` calls this function lazily, only when it needs more data\nto be displayed.\n\n__Note that when using function data providers, the total number of items\nneeds to be set manually. The total number of items can be returned\nin the second argument of the data provider callback:__\n\n```js\ncomboBox.dataProvider = async (params, callback) => {\n const API = 'https://demo.vaadin.com/demo-data/1.0/filtered-countries';\n const { filter, page, pageSize } = params;\n const index = page * pageSize;\n\n const res = await fetch(`${API}?index=${index}&count=${pageSize}&filter=${filter}`);\n if (res.ok) {\n const { result, size } = await res.json();\n callback(result, size);\n }\n};\n```\n\n### Styling\n\nThe following custom properties are available for styling:\n\nCustom property | Description | Default\n----------------------------------------|----------------------------|---------\n`--vaadin-field-default-width` | Default width of the field | `12em`\n`--vaadin-combo-box-overlay-width` | Width of the overlay | `auto`\n`--vaadin-combo-box-overlay-max-height` | Max height of the overlay | `65vh`\n\n`<vaadin-combo-box>` provides the same set of shadow DOM parts and state attributes as `<vaadin-text-field>`.\nSee [`<vaadin-text-field>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-text-field) for the styling documentation.\n\nIn addition to `<vaadin-text-field>` parts, the following parts are available for theming:\n\nPart name | Description\n----------------|----------------\n`toggle-button` | The toggle button\n\nIn addition to `<vaadin-text-field>` state attributes, the following state attributes are available for theming:\n\nAttribute | Description | Part name\n----------|-------------|------------\n`opened` | Set when the combo box dropdown is open | :host\n`loading` | Set when new items are expected | :host\n\nIf you want to replace the default `<input>` and its container with a custom implementation to get full control\nover the input field, consider using the [`<vaadin-combo-box-light>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-combo-box-light) element.\n\n### Internal components\n\nIn addition to `<vaadin-combo-box>` itself, the following internal\ncomponents are themable:\n\n- `<vaadin-combo-box-overlay>` - has the same API as [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-overlay).\n- `<vaadin-combo-box-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-item).\n- [`<vaadin-input-container>`](https://cdn.vaadin.com/vaadin-web-components/24.5.0-alpha10/#/elements/vaadin-input-container) - an internal element wrapping the input.\n\nNote: the `theme` attribute value set on `<vaadin-combo-box>` is\npropagated to the internal components listed above.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.",
251
258
  "extension": true,
252
259
  "attributes": [
253
260
  {
@@ -467,6 +474,13 @@
467
474
  "kind": "expression"
468
475
  }
469
476
  },
477
+ {
478
+ "name": ".itemClassNameGenerator",
479
+ "description": "A function used to generate CSS class names for dropdown\nitems based on the item. The return value should be the\ngenerated class name as a string, or multiple class names\nseparated by whitespace characters.",
480
+ "value": {
481
+ "kind": "expression"
482
+ }
483
+ },
470
484
  {
471
485
  "name": ".itemLabelPath",
472
486
  "description": "Path for label of the item. If `items` is an array of objects, the\n`itemLabelPath` is used to fetch the displayed string label for each\nitem.\n\nThe item label is also used for matching items when processing user\ninput, i.e., for filtering and selecting items.",