@vaadin/combo-box 23.1.2 → 23.2.0-alpha3

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/combo-box",
3
- "version": "23.1.2",
3
+ "version": "23.2.0-alpha3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -19,10 +19,10 @@
19
19
  "main": "vaadin-combo-box.js",
20
20
  "type": "module",
21
21
  "files": [
22
+ "lit.d.ts",
23
+ "lit.js",
22
24
  "src",
23
25
  "theme",
24
- "lit.js",
25
- "lit.d.ts",
26
26
  "vaadin-*.d.ts",
27
27
  "vaadin-*.js"
28
28
  ],
@@ -36,23 +36,23 @@
36
36
  "dependencies": {
37
37
  "@open-wc/dedupe-mixin": "^1.3.0",
38
38
  "@polymer/polymer": "^3.0.0",
39
- "@vaadin/component-base": "^23.1.2",
40
- "@vaadin/field-base": "^23.1.2",
41
- "@vaadin/input-container": "^23.1.2",
42
- "@vaadin/item": "^23.1.2",
43
- "@vaadin/lit-renderer": "^23.1.2",
44
- "@vaadin/vaadin-lumo-styles": "^23.1.2",
45
- "@vaadin/vaadin-material-styles": "^23.1.2",
46
- "@vaadin/vaadin-overlay": "^23.1.2",
47
- "@vaadin/vaadin-themable-mixin": "^23.1.2"
39
+ "@vaadin/component-base": "23.2.0-alpha3",
40
+ "@vaadin/field-base": "23.2.0-alpha3",
41
+ "@vaadin/input-container": "23.2.0-alpha3",
42
+ "@vaadin/item": "23.2.0-alpha3",
43
+ "@vaadin/lit-renderer": "23.2.0-alpha3",
44
+ "@vaadin/vaadin-lumo-styles": "23.2.0-alpha3",
45
+ "@vaadin/vaadin-material-styles": "23.2.0-alpha3",
46
+ "@vaadin/vaadin-overlay": "23.2.0-alpha3",
47
+ "@vaadin/vaadin-themable-mixin": "23.2.0-alpha3"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@esm-bundle/chai": "^4.3.4",
51
- "@vaadin/polymer-legacy-adapter": "^23.1.2",
51
+ "@vaadin/polymer-legacy-adapter": "23.2.0-alpha3",
52
52
  "@vaadin/testing-helpers": "^0.3.2",
53
- "@vaadin/text-field": "^23.1.2",
53
+ "@vaadin/text-field": "23.2.0-alpha3",
54
54
  "lit": "^2.0.0",
55
55
  "sinon": "^13.0.2"
56
56
  },
57
- "gitHead": "6fb205c6e9a761feadfb779dd5d7af96d3102e56"
57
+ "gitHead": "06e5875be93ca50da2846dafc65a8531010c0576"
58
58
  }
@@ -3,10 +3,10 @@
3
3
  * Copyright (c) 2017 - 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 { TemplateResult } from 'lit';
7
- import { DirectiveResult } from 'lit/directive.js';
6
+ import type { TemplateResult } from 'lit';
7
+ import type { DirectiveResult } from 'lit/directive.js';
8
8
  import { LitRendererDirective } from '@vaadin/lit-renderer';
9
- import { ComboBox, ComboBoxItemModel } from '../vaadin-combo-box.js';
9
+ import type { ComboBox, ComboBoxItemModel } from '../vaadin-combo-box.js';
10
10
 
11
11
  export type ComboBoxLitRenderer<TItem> = (
12
12
  item: TItem,
@@ -3,9 +3,9 @@
3
3
  * Copyright (c) 2015 - 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 { Constructor } from '@open-wc/dedupe-mixin';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
7
 
8
- export type ComboBoxDataProviderCallback<TItem> = (items: TItem[], size: number) => void;
8
+ export type ComboBoxDataProviderCallback<TItem> = (items: TItem[], size?: number) => void;
9
9
 
10
10
  export interface ComboBoxDataProviderParams {
11
11
  page: number;
@@ -81,7 +81,7 @@ export const ComboBoxDataProviderMixin = (superClass) =>
81
81
  /** @protected */
82
82
  ready() {
83
83
  super.ready();
84
- this.$.dropdown.addEventListener('index-requested', (e) => {
84
+ this._scroller.addEventListener('index-requested', (e) => {
85
85
  const index = e.detail.index;
86
86
  const currentScrollerPos = e.detail.currentScrollerPos;
87
87
  const allowedIndexRange = Math.floor(this.pageSize * 1.5);
@@ -167,44 +167,47 @@ export const ComboBoxDataProviderMixin = (superClass) =>
167
167
  /** @private */
168
168
  _loadPage(page) {
169
169
  // Make sure same page isn't requested multiple times.
170
- if (!this._pendingRequests[page] && this.dataProvider) {
171
- this.loading = true;
172
-
173
- const params = {
174
- page,
175
- pageSize: this.pageSize,
176
- filter: this.filter,
177
- };
178
-
179
- const callback = (items, size) => {
180
- if (this._pendingRequests[page] === callback) {
181
- const filteredItems = this.filteredItems ? [...this.filteredItems] : [];
182
- filteredItems.splice(params.page * params.pageSize, items.length, ...items);
183
- this.filteredItems = filteredItems;
184
-
185
- // Update selectedItem from filteredItems if value is set
186
- if (this._isValidValue(this.value) && this._getItemValue(this.selectedItem) !== this.value) {
187
- this._selectItemForValue(this.value);
188
- }
189
- if (!this.opened && !this.hasAttribute('focused')) {
190
- this._commitValue();
191
- }
192
- this.size = size;
193
-
194
- delete this._pendingRequests[page];
195
-
196
- if (Object.keys(this._pendingRequests).length === 0) {
197
- this.loading = false;
198
- }
199
- }
200
- };
170
+ if (this._pendingRequests[page] || !this.dataProvider) {
171
+ return;
172
+ }
173
+
174
+ const params = {
175
+ page,
176
+ pageSize: this.pageSize,
177
+ filter: this.filter,
178
+ };
201
179
 
202
- if (!this._pendingRequests[page]) {
203
- // Don't request page if it's already being requested
204
- this._pendingRequests[page] = callback;
205
- this.dataProvider(params, callback);
180
+ const callback = (items, size) => {
181
+ if (this._pendingRequests[page] !== callback) {
182
+ return;
206
183
  }
207
- }
184
+
185
+ const filteredItems = this.filteredItems ? [...this.filteredItems] : [];
186
+ filteredItems.splice(params.page * params.pageSize, items.length, ...items);
187
+ this.filteredItems = filteredItems;
188
+
189
+ if (!this.opened && !this.hasAttribute('focused')) {
190
+ this._commitValue();
191
+ }
192
+
193
+ if (size !== undefined) {
194
+ this.size = size;
195
+ }
196
+
197
+ delete this._pendingRequests[page];
198
+
199
+ if (Object.keys(this._pendingRequests).length === 0) {
200
+ this.loading = false;
201
+ }
202
+ };
203
+
204
+ this._pendingRequests[page] = callback;
205
+ // Set the `loading` flag only after marking the request as pending
206
+ // to prevent the same page from getting requested multiple times
207
+ // as a result of `__loadingChanged` in the scroller which requests
208
+ // a virtualizer update which in turn may trigger a data provider page request.
209
+ this.loading = true;
210
+ this.dataProvider(params, callback);
208
211
  }
209
212
 
210
213
  /** @private */
@@ -279,7 +282,7 @@ export const ComboBoxDataProviderMixin = (superClass) =>
279
282
  /** @private */
280
283
  _warnDataProviderValue(dataProvider, value) {
281
284
  if (dataProvider && value !== '' && (this.selectedItem === undefined || this.selectedItem === null)) {
282
- const valueIndex = this._indexOfValue(value, this.filteredItems);
285
+ const valueIndex = this.__getItemIndexByValue(this.filteredItems, value);
283
286
  if (valueIndex < 0 || !this._getItemLabel(this.filteredItems[valueIndex])) {
284
287
  console.warn(
285
288
  'Warning: unable to determine the label for the provided `value`. ' +
@@ -3,13 +3,13 @@
3
3
  * Copyright (c) 2015 - 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 { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
7
- import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
8
- import { InputMixinClass } from '@vaadin/field-base/src/input-mixin.js';
9
- import { ThemableMixinClass } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10
- import { ComboBoxDataProviderMixinClass } from './vaadin-combo-box-data-provider-mixin.js';
11
- import { ComboBoxMixinClass } from './vaadin-combo-box-mixin.js';
12
- import { ComboBoxDefaultItem } from './vaadin-combo-box-mixin.js';
6
+ import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
7
+ import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
8
+ import type { InputMixinClass } from '@vaadin/field-base/src/input-mixin.js';
9
+ import type { ValidateMixinClass } from '@vaadin/field-base/src/validate-mixin.js';
10
+ import type { ThemableMixinClass } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
11
+ import type { ComboBoxDataProviderMixinClass } from './vaadin-combo-box-data-provider-mixin.js';
12
+ import type { ComboBoxDefaultItem, ComboBoxMixinClass } from './vaadin-combo-box-mixin.js';
13
13
  export {
14
14
  ComboBoxDataProvider,
15
15
  ComboBoxDataProviderCallback,
@@ -54,6 +54,11 @@ export type ComboBoxLightFilterChangedEvent = CustomEvent<{ value: string }>;
54
54
  */
55
55
  export type ComboBoxLightSelectedItemChangedEvent<TItem> = CustomEvent<{ value: TItem | null | undefined }>;
56
56
 
57
+ /**
58
+ * Fired whenever the field is validated.
59
+ */
60
+ export type ComboBoxLightValidatedEvent = CustomEvent<{ valid: boolean }>;
61
+
57
62
  export interface ComboBoxLightEventMap<TItem> extends HTMLElementEventMap {
58
63
  change: ComboBoxLightChangeEvent<TItem>;
59
64
 
@@ -68,6 +73,8 @@ export interface ComboBoxLightEventMap<TItem> extends HTMLElementEventMap {
68
73
  'value-changed': ComboBoxLightValueChangedEvent;
69
74
 
70
75
  'selected-item-changed': ComboBoxLightSelectedItemChangedEvent<TItem>;
76
+
77
+ validated: ComboBoxLightValidatedEvent;
71
78
  }
72
79
 
73
80
  /**
@@ -114,6 +121,7 @@ export interface ComboBoxLightEventMap<TItem> extends HTMLElementEventMap {
114
121
  * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
115
122
  * @fires {CustomEvent} selected-item-changed - Fired when the `selectedItem` property changes.
116
123
  * @fires {CustomEvent} value-changed - Fired when the `value` property changes.
124
+ * @fires {CustomEvent} validated - Fired whenever the field is validated.
117
125
  */
118
126
  declare class ComboBoxLight<TItem = ComboBoxDefaultItem> extends HTMLElement {
119
127
  /**
@@ -142,7 +150,8 @@ interface ComboBoxLight<TItem = ComboBoxDefaultItem>
142
150
  KeyboardMixinClass,
143
151
  InputMixinClass,
144
152
  DisabledMixinClass,
145
- ThemableMixinClass {}
153
+ ThemableMixinClass,
154
+ ValidateMixinClass {}
146
155
 
147
156
  declare global {
148
157
  interface HTMLElementTagNameMap {
@@ -3,9 +3,12 @@
3
3
  * Copyright (c) 2015 - 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 './vaadin-combo-box-dropdown.js';
6
+ import './vaadin-combo-box-item.js';
7
+ import './vaadin-combo-box-overlay.js';
8
+ import './vaadin-combo-box-scroller.js';
7
9
  import { dashToCamelCase } from '@polymer/polymer/lib/utils/case-map.js';
8
10
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
11
+ import { ValidateMixin } from '@vaadin/field-base/src/validate-mixin.js';
9
12
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10
13
  import { ComboBoxDataProviderMixin } from './vaadin-combo-box-data-provider-mixin.js';
11
14
  import { ComboBoxMixin } from './vaadin-combo-box-mixin.js';
@@ -54,13 +57,15 @@ import { ComboBoxMixin } from './vaadin-combo-box-mixin.js';
54
57
  * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
55
58
  * @fires {CustomEvent} selected-item-changed - Fired when the `selectedItem` property changes.
56
59
  * @fires {CustomEvent} value-changed - Fired when the `value` property changes.
60
+ * @fires {CustomEvent} validated - Fired whenever the field is validated.
57
61
  *
58
62
  * @extends HTMLElement
59
63
  * @mixes ComboBoxDataProviderMixin
60
64
  * @mixes ComboBoxMixin
61
65
  * @mixes ThemableMixin
66
+ * @mixes ValidateMixin
62
67
  */
63
- class ComboBoxLight extends ComboBoxDataProviderMixin(ComboBoxMixin(ThemableMixin(PolymerElement))) {
68
+ class ComboBoxLight extends ComboBoxDataProviderMixin(ComboBoxMixin(ValidateMixin(ThemableMixin(PolymerElement)))) {
64
69
  static get is() {
65
70
  return 'vaadin-combo-box-light';
66
71
  }
@@ -75,19 +80,16 @@ class ComboBoxLight extends ComboBoxDataProviderMixin(ComboBoxMixin(ThemableMixi
75
80
 
76
81
  <slot></slot>
77
82
 
78
- <vaadin-combo-box-dropdown
79
- id="dropdown"
80
- opened="[[opened]]"
83
+ <vaadin-combo-box-overlay
84
+ id="overlay"
85
+ hidden$="[[_isOverlayHidden(filteredItems, loading)]]"
86
+ opened="[[_overlayOpened]]"
87
+ loading$="[[loading]]"
88
+ theme$="[[_theme]]"
81
89
  position-target="[[inputElement]]"
82
- restore-focus-on-close="[[__restoreFocusOnClose]]"
90
+ no-vertical-overlap
83
91
  restore-focus-node="[[inputElement]]"
84
- renderer="[[renderer]]"
85
- _focused-index="[[_focusedIndex]]"
86
- _item-id-path="[[itemIdPath]]"
87
- _item-label-path="[[itemLabelPath]]"
88
- loading="[[loading]]"
89
- theme="[[_theme]]"
90
- ></vaadin-combo-box-dropdown>
92
+ ></vaadin-combo-box-overlay>
91
93
  `;
92
94
  }
93
95
 
@@ -3,11 +3,11 @@
3
3
  * Copyright (c) 2015 - 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 { Constructor } from '@open-wc/dedupe-mixin';
7
- import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
- import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
9
- import { InputMixinClass } from '@vaadin/field-base/src/input-mixin.js';
10
- import { ComboBox } from './vaadin-combo-box.js';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
+ import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
9
+ import type { InputMixinClass } from '@vaadin/field-base/src/input-mixin.js';
10
+ import type { ComboBox } from './vaadin-combo-box.js';
11
11
 
12
12
  export type ComboBoxDefaultItem = any;
13
13
 
@@ -138,15 +138,15 @@ export declare class ComboBoxMixinClass<TItem> {
138
138
  */
139
139
  itemIdPath: string | null | undefined;
140
140
 
141
- /**
142
- * Set to true if the value is invalid.
143
- */
144
- invalid: boolean;
145
-
146
141
  protected readonly _propertyForValue: string;
147
142
 
148
143
  protected _inputElementValue: string | undefined;
149
144
 
145
+ /**
146
+ * Tag name prefix used by scroller and items.
147
+ */
148
+ protected readonly _tagNamePrefix: string;
149
+
150
150
  /**
151
151
  * Requests an update for the content of items.
152
152
  * While performing the update, it invokes the renderer (passed in the `renderer` property) once an item.
@@ -177,6 +177,4 @@ export declare class ComboBoxMixinClass<TItem> {
177
177
  checkValidity(): boolean;
178
178
 
179
179
  protected _revertInputValue(): void;
180
-
181
- protected _getItemElements(): HTMLElement[];
182
180
  }