@vaadin/combo-box 25.0.0-alpha2 → 25.0.0-alpha21

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 (34) hide show
  1. package/package.json +14 -17
  2. package/src/styles/vaadin-combo-box-base-styles.js +2 -2
  3. package/src/styles/vaadin-combo-box-overlay-base-styles.js +31 -48
  4. package/src/vaadin-combo-box-base-mixin.d.ts +54 -0
  5. package/src/vaadin-combo-box-base-mixin.js +772 -0
  6. package/src/vaadin-combo-box-data-provider-mixin.js +17 -32
  7. package/src/vaadin-combo-box-item-mixin.js +6 -1
  8. package/src/vaadin-combo-box-item.js +5 -2
  9. package/src/vaadin-combo-box-items-mixin.d.ts +60 -0
  10. package/src/vaadin-combo-box-items-mixin.js +292 -0
  11. package/src/vaadin-combo-box-mixin.d.ts +3 -74
  12. package/src/vaadin-combo-box-mixin.js +84 -886
  13. package/src/vaadin-combo-box-overlay-mixin.js +1 -22
  14. package/src/vaadin-combo-box-overlay.js +4 -4
  15. package/src/vaadin-combo-box-scroller-mixin.d.ts +1 -2
  16. package/src/vaadin-combo-box-scroller-mixin.js +5 -0
  17. package/src/vaadin-combo-box-scroller.js +1 -1
  18. package/src/vaadin-combo-box.d.ts +33 -19
  19. package/src/vaadin-combo-box.js +67 -22
  20. package/vaadin-combo-box.js +1 -1
  21. package/web-types.json +59 -70
  22. package/web-types.lit.json +20 -20
  23. package/src/styles/vaadin-combo-box-core-styles.d.ts +0 -8
  24. package/src/styles/vaadin-combo-box-core-styles.js +0 -12
  25. package/src/styles/vaadin-combo-box-overlay-core-styles.js +0 -18
  26. package/src/styles/vaadin-combo-box-scroller-core-styles.js +0 -30
  27. package/theme/lumo/vaadin-combo-box-item-styles.d.ts +0 -5
  28. package/theme/lumo/vaadin-combo-box-item-styles.js +0 -25
  29. package/theme/lumo/vaadin-combo-box-overlay-styles.d.ts +0 -6
  30. package/theme/lumo/vaadin-combo-box-overlay-styles.js +0 -60
  31. package/theme/lumo/vaadin-combo-box-styles.d.ts +0 -2
  32. package/theme/lumo/vaadin-combo-box-styles.js +0 -12
  33. package/theme/lumo/vaadin-combo-box.d.ts +0 -4
  34. package/theme/lumo/vaadin-combo-box.js +0 -4
@@ -22,18 +22,6 @@ export const ComboBoxOverlayMixin = (superClass) =>
22
22
  this.requiredVerticalSpace = 200;
23
23
  }
24
24
 
25
- /** @protected */
26
- connectedCallback() {
27
- super.connectedCallback();
28
-
29
- const comboBox = this._comboBox;
30
-
31
- const hostDir = comboBox && comboBox.getAttribute('dir');
32
- if (hostDir) {
33
- this.setAttribute('dir', hostDir);
34
- }
35
- }
36
-
37
25
  /**
38
26
  * Override method inherited from `Overlay`
39
27
  * to not close on position target click.
@@ -63,16 +51,7 @@ export const ComboBoxOverlayMixin = (superClass) =>
63
51
 
64
52
  /** @protected */
65
53
  _updateOverlayWidth() {
66
- const propPrefix = this.localName;
67
- this.style.setProperty(`--_${propPrefix}-default-width`, `${this.positionTarget.offsetWidth}px`);
68
-
69
- const customWidth = getComputedStyle(this._comboBox).getPropertyValue(`--${propPrefix}-width`);
70
-
71
- if (customWidth === '') {
72
- this.style.removeProperty(`--${propPrefix}-width`);
73
- } else {
74
- this.style.setProperty(`--${propPrefix}-width`, customWidth);
75
- }
54
+ this.style.setProperty(`--_${this.localName}-default-width`, `${this.positionTarget.offsetWidth}px`);
76
55
  }
77
56
 
78
57
  /** @private */
@@ -7,10 +7,11 @@ 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 { overlayStyles } from '@vaadin/overlay/src/styles/vaadin-overlay-base-styles.js';
10
11
  import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js';
11
- import { overlayStyles } from '@vaadin/overlay/src/vaadin-overlay-styles.js';
12
+ import { LumoInjectionMixin } from '@vaadin/vaadin-themable-mixin/lumo-injection-mixin.js';
12
13
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
13
- import { comboBoxOverlayStyles } from './styles/vaadin-combo-box-overlay-core-styles.js';
14
+ import { comboBoxOverlayStyles } from './styles/vaadin-combo-box-overlay-base-styles.js';
14
15
  import { ComboBoxOverlayMixin } from './vaadin-combo-box-overlay-mixin.js';
15
16
 
16
17
  /**
@@ -25,7 +26,7 @@ import { ComboBoxOverlayMixin } from './vaadin-combo-box-overlay-mixin.js';
25
26
  * @private
26
27
  */
27
28
  export class ComboBoxOverlay extends ComboBoxOverlayMixin(
28
- OverlayMixin(DirMixin(ThemableMixin(PolylitMixin(LitElement)))),
29
+ OverlayMixin(DirMixin(ThemableMixin(PolylitMixin(LumoInjectionMixin(LitElement))))),
29
30
  ) {
30
31
  static get is() {
31
32
  return 'vaadin-combo-box-overlay';
@@ -38,7 +39,6 @@ export class ComboBoxOverlay extends ComboBoxOverlayMixin(
38
39
  /** @protected */
39
40
  render() {
40
41
  return html`
41
- <div id="backdrop" part="backdrop" hidden></div>
42
42
  <div part="overlay" id="overlay">
43
43
  <div part="loader"></div>
44
44
  <div part="content" id="content"><slot></slot></div>
@@ -45,8 +45,7 @@ export declare class ComboBoxScrollerMixinClass<TItem, TOwner> {
45
45
  owner: TOwner;
46
46
 
47
47
  /**
48
- * Set true to prevent the overlay from opening automatically.
49
- * @attr {boolean} auto-open-disabled
48
+ * Function used to render the content of every combo-box item.
50
49
  */
51
50
  renderer: ComboBoxItemRenderer<TItem, TOwner> | null | undefined;
52
51
 
@@ -234,6 +234,11 @@ export const ComboBoxScrollerMixin = (superClass) =>
234
234
  scrollTarget: this,
235
235
  scrollContainer: this.$.selector,
236
236
  reorderElements: true,
237
+ // Combo-box items have a CSS-defined minimum height, so the virtualizer's
238
+ // height placeholder logic can be disabled. This helps save reflows which
239
+ // might otherwise be triggered by this logic because it reads the row height
240
+ // right after updating the rows' content.
241
+ __disableHeightPlaceholder: true,
237
242
  });
238
243
  }
239
244
 
@@ -6,7 +6,7 @@
6
6
  import { html, LitElement } from 'lit';
7
7
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
8
8
  import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
9
- import { comboBoxScrollerStyles } from './styles/vaadin-combo-box-scroller-core-styles.js';
9
+ import { comboBoxScrollerStyles } from './styles/vaadin-combo-box-scroller-base-styles.js';
10
10
  import { ComboBoxScrollerMixin } from './vaadin-combo-box-scroller-mixin.js';
11
11
 
12
12
  /**
@@ -9,7 +9,6 @@ import type { FocusMixinClass } from '@vaadin/a11y-base/src/focus-mixin.js';
9
9
  import type { KeyboardMixinClass } from '@vaadin/a11y-base/src/keyboard-mixin.js';
10
10
  import type { DelegateStateMixinClass } from '@vaadin/component-base/src/delegate-state-mixin.js';
11
11
  import type { ElementMixinClass } from '@vaadin/component-base/src/element-mixin.js';
12
- import type { OverlayClassMixinClass } from '@vaadin/component-base/src/overlay-class-mixin.js';
13
12
  import type { ClearButtonMixinClass } from '@vaadin/field-base/src/clear-button-mixin.js';
14
13
  import type { FieldMixinClass } from '@vaadin/field-base/src/field-mixin.js';
15
14
  import type { InputConstraintsMixinClass } from '@vaadin/field-base/src/input-constraints-mixin.js';
@@ -20,7 +19,9 @@ import type { PatternMixinClass } from '@vaadin/field-base/src/pattern-mixin.js'
20
19
  import type { ValidateMixinClass } from '@vaadin/field-base/src/validate-mixin.js';
21
20
  import type { ThemableMixinClass } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
22
21
  import type { ThemePropertyMixinClass } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
22
+ import type { ComboBoxBaseMixinClass } from './vaadin-combo-box-base-mixin.js';
23
23
  import type { ComboBoxDataProviderMixinClass } from './vaadin-combo-box-data-provider-mixin.js';
24
+ import type { ComboBoxItemsMixinClass } from './vaadin-combo-box-items-mixin.js';
24
25
  import type { ComboBoxMixinClass } from './vaadin-combo-box-mixin.js';
25
26
  import type { ComboBoxDefaultItem } from './vaadin-combo-box-mixin.js';
26
27
 
@@ -174,33 +175,45 @@ export interface ComboBoxEventMap<TItem> extends HTMLElementEventMap {
174
175
  * `--vaadin-combo-box-overlay-width` | Width of the overlay | `auto`
175
176
  * `--vaadin-combo-box-overlay-max-height` | Max height of the overlay | `65vh`
176
177
  *
177
- * `<vaadin-combo-box>` provides the same set of shadow DOM parts and state attributes as `<vaadin-text-field>`.
178
- * See [`<vaadin-text-field>`](#/elements/vaadin-text-field) for the styling documentation.
178
+ * The following shadow DOM parts are available for styling:
179
179
  *
180
- * In addition to `<vaadin-text-field>` parts, the following parts are available for theming:
180
+ * Part name | Description
181
+ * ---------------------|----------------
182
+ * `label` | The label element
183
+ * `input-field` | The element that wraps prefix, value and buttons
184
+ * `field-button` | Set on both clear and toggle buttons
185
+ * `clear-button` | The clear button
186
+ * `error-message` | The error message element
187
+ * `helper-text` | The helper text element wrapper
188
+ * `required-indicator` | The `required` state indicator element
189
+ * `toggle-button` | The toggle button
190
+ * `overlay` | The overlay container
191
+ * `content` | The overlay content
192
+ * `loader` | The loading indicator shown while loading items
181
193
  *
182
- * Part name | Description
183
- * ----------------|----------------
184
- * `toggle-button` | The toggle button
194
+ * The following state attributes are available for styling:
185
195
  *
186
- * In addition to `<vaadin-text-field>` state attributes, the following state attributes are available for theming:
187
- *
188
- * Attribute | Description | Part name
189
- * ----------|-------------|------------
190
- * `opened` | Set when the combo box dropdown is open | :host
191
- * `loading` | Set when new items are expected | :host
196
+ * Attribute | Description
197
+ * ---------------------|---------------------------------
198
+ * `disabled` | Set when the element is disabled
199
+ * `has-value` | Set when the element has a value
200
+ * `has-label` | Set when the element has a label
201
+ * `has-helper` | Set when the element has helper text or slot
202
+ * `has-error-message` | Set when the element has an error message
203
+ * `has-tooltip` | Set when the element has a slotted tooltip
204
+ * `invalid` | Set when the element is invalid
205
+ * `focused` | Set when the element is focused
206
+ * `focus-ring` | Set when the element is keyboard focused
207
+ * `readonly` | Set when the element is readonly
208
+ * `opened` | Set when the overlay is opened
209
+ * `loading` | Set when loading items from the data provider
192
210
  *
193
211
  * ### Internal components
194
212
  *
195
213
  * In addition to `<vaadin-combo-box>` itself, the following internal
196
214
  * components are themable:
197
215
  *
198
- * - `<vaadin-combo-box-overlay>` - has the same API as [`<vaadin-overlay>`](#/elements/vaadin-overlay).
199
216
  * - `<vaadin-combo-box-item>` - has the same API as [`<vaadin-item>`](#/elements/vaadin-item).
200
- * - [`<vaadin-input-container>`](#/elements/vaadin-input-container) - an internal element wrapping the input.
201
- *
202
- * Note: the `theme` attribute value set on `<vaadin-combo-box>` is
203
- * propagated to the internal components listed above.
204
217
  *
205
218
  * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
206
219
  *
@@ -229,12 +242,13 @@ declare class ComboBox<TItem = ComboBoxDefaultItem> extends HTMLElement {
229
242
 
230
243
  interface ComboBox<TItem = ComboBoxDefaultItem>
231
244
  extends ComboBoxDataProviderMixinClass<TItem>,
245
+ ComboBoxItemsMixinClass<TItem>,
232
246
  ComboBoxMixinClass<TItem>,
247
+ ComboBoxBaseMixinClass,
233
248
  ValidateMixinClass,
234
249
  PatternMixinClass,
235
250
  LabelMixinClass,
236
251
  KeyboardMixinClass,
237
- OverlayClassMixinClass,
238
252
  InputMixinClass,
239
253
  ClearButtonMixinClass,
240
254
  InputControlMixinClass,
@@ -18,8 +18,9 @@ import { InputController } from '@vaadin/field-base/src/input-controller.js';
18
18
  import { LabelledInputController } from '@vaadin/field-base/src/labelled-input-controller.js';
19
19
  import { PatternMixin } from '@vaadin/field-base/src/pattern-mixin.js';
20
20
  import { inputFieldShared } from '@vaadin/field-base/src/styles/input-field-shared-styles.js';
21
+ import { LumoInjectionMixin } from '@vaadin/vaadin-themable-mixin/lumo-injection-mixin.js';
21
22
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
22
- import { comboBoxStyles } from './styles/vaadin-combo-box-core-styles.js';
23
+ import { comboBoxStyles } from './styles/vaadin-combo-box-base-styles.js';
23
24
  import { ComboBoxDataProviderMixin } from './vaadin-combo-box-data-provider-mixin.js';
24
25
  import { ComboBoxMixin } from './vaadin-combo-box-mixin.js';
25
26
 
@@ -106,33 +107,45 @@ import { ComboBoxMixin } from './vaadin-combo-box-mixin.js';
106
107
  * `--vaadin-combo-box-overlay-width` | Width of the overlay | `auto`
107
108
  * `--vaadin-combo-box-overlay-max-height` | Max height of the overlay | `65vh`
108
109
  *
109
- * `<vaadin-combo-box>` provides the same set of shadow DOM parts and state attributes as `<vaadin-text-field>`.
110
- * See [`<vaadin-text-field>`](#/elements/vaadin-text-field) for the styling documentation.
110
+ * The following shadow DOM parts are available for styling:
111
111
  *
112
- * In addition to `<vaadin-text-field>` parts, the following parts are available for theming:
112
+ * Part name | Description
113
+ * ---------------------|----------------
114
+ * `label` | The label element
115
+ * `input-field` | The element that wraps prefix, value and buttons
116
+ * `field-button` | Set on both clear and toggle buttons
117
+ * `clear-button` | The clear button
118
+ * `error-message` | The error message element
119
+ * `helper-text` | The helper text element wrapper
120
+ * `required-indicator` | The `required` state indicator element
121
+ * `toggle-button` | The toggle button
122
+ * `overlay` | The overlay container
123
+ * `content` | The overlay content
124
+ * `loader` | The loading indicator shown while loading items
113
125
  *
114
- * Part name | Description
115
- * ----------------|----------------
116
- * `toggle-button` | The toggle button
126
+ * The following state attributes are available for styling:
117
127
  *
118
- * In addition to `<vaadin-text-field>` state attributes, the following state attributes are available for theming:
119
- *
120
- * Attribute | Description | Part name
121
- * ----------|-------------|------------
122
- * `opened` | Set when the combo box dropdown is open | :host
123
- * `loading` | Set when new items are expected | :host
128
+ * Attribute | Description
129
+ * ---------------------|---------------------------------
130
+ * `disabled` | Set when the element is disabled
131
+ * `has-value` | Set when the element has a value
132
+ * `has-label` | Set when the element has a label
133
+ * `has-helper` | Set when the element has helper text or slot
134
+ * `has-error-message` | Set when the element has an error message
135
+ * `has-tooltip` | Set when the element has a slotted tooltip
136
+ * `invalid` | Set when the element is invalid
137
+ * `focused` | Set when the element is focused
138
+ * `focus-ring` | Set when the element is keyboard focused
139
+ * `readonly` | Set when the element is readonly
140
+ * `opened` | Set when the overlay is opened
141
+ * `loading` | Set when loading items from the data provider
124
142
  *
125
143
  * ### Internal components
126
144
  *
127
145
  * In addition to `<vaadin-combo-box>` itself, the following internal
128
146
  * components are themable:
129
147
  *
130
- * - `<vaadin-combo-box-overlay>` - has the same API as [`<vaadin-overlay>`](#/elements/vaadin-overlay).
131
148
  * - `<vaadin-combo-box-item>` - has the same API as [`<vaadin-item>`](#/elements/vaadin-item).
132
- * - [`<vaadin-input-container>`](#/elements/vaadin-input-container) - an internal element wrapping the input.
133
- *
134
- * Note: the `theme` attribute value set on `<vaadin-combo-box>` is
135
- * propagated to the internal components listed above.
136
149
  *
137
150
  * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
138
151
  *
@@ -155,7 +168,9 @@ import { ComboBoxMixin } from './vaadin-combo-box-mixin.js';
155
168
  * @mixes ComboBoxMixin
156
169
  */
157
170
  class ComboBox extends ComboBoxDataProviderMixin(
158
- ComboBoxMixin(PatternMixin(InputControlMixin(ThemableMixin(ElementMixin(PolylitMixin(LitElement)))))),
171
+ ComboBoxMixin(
172
+ PatternMixin(InputControlMixin(ThemableMixin(ElementMixin(PolylitMixin(LumoInjectionMixin(LitElement)))))),
173
+ ),
159
174
  ) {
160
175
  static get is() {
161
176
  return 'vaadin-combo-box';
@@ -203,8 +218,8 @@ class ComboBox extends ComboBoxDataProviderMixin(
203
218
  >
204
219
  <slot name="prefix" slot="prefix"></slot>
205
220
  <slot name="input"></slot>
206
- <div id="clearButton" part="clear-button" slot="suffix" aria-hidden="true"></div>
207
- <div id="toggleButton" part="toggle-button" slot="suffix" aria-hidden="true"></div>
221
+ <div id="clearButton" part="field-button clear-button" slot="suffix" aria-hidden="true"></div>
222
+ <div id="toggleButton" part="field-button toggle-button" slot="suffix" aria-hidden="true"></div>
208
223
  </vaadin-input-container>
209
224
 
210
225
  <div part="helper-text">
@@ -218,12 +233,17 @@ class ComboBox extends ComboBoxDataProviderMixin(
218
233
 
219
234
  <vaadin-combo-box-overlay
220
235
  id="overlay"
236
+ exportparts="overlay, content, loader"
237
+ .owner="${this}"
238
+ .dir="${this.dir}"
221
239
  .opened="${this._overlayOpened}"
222
240
  ?loading="${this.loading}"
223
241
  theme="${ifDefined(this._theme)}"
224
242
  .positionTarget="${this._positionTarget}"
225
243
  no-vertical-overlap
226
- ></vaadin-combo-box-overlay>
244
+ >
245
+ <slot name="overlay"></slot>
246
+ </vaadin-combo-box-overlay>
227
247
 
228
248
  <slot name="tooltip"></slot>
229
249
  `;
@@ -253,6 +273,15 @@ class ComboBox extends ComboBoxDataProviderMixin(
253
273
  this._toggleElement = this.$.toggleButton;
254
274
  }
255
275
 
276
+ /** @protected */
277
+ updated(props) {
278
+ super.updated(props);
279
+
280
+ if (props.has('dataProvider') || props.has('value')) {
281
+ this._warnDataProviderValue(this.dataProvider, this.value);
282
+ }
283
+ }
284
+
256
285
  /**
257
286
  * Override the method from `InputControlMixin`
258
287
  * to stop event propagation to prevent `ComboBoxMixin`
@@ -279,6 +308,22 @@ class ComboBox extends ComboBoxDataProviderMixin(
279
308
  super._onHostClick(event);
280
309
  }
281
310
  }
311
+
312
+ /** @private */
313
+ _warnDataProviderValue(dataProvider, value) {
314
+ if (dataProvider && value !== '' && (this.selectedItem === undefined || this.selectedItem === null)) {
315
+ const valueIndex = this.__getItemIndexByValue(this.filteredItems, value);
316
+ if (valueIndex < 0 || !this._getItemLabel(this.filteredItems[valueIndex])) {
317
+ console.warn(
318
+ 'Warning: unable to determine the label for the provided `value`. ' +
319
+ 'Nothing to display in the text field. This usually happens when ' +
320
+ 'setting an initial `value` before any items are returned from ' +
321
+ 'the `dataProvider` callback. Consider setting `selectedItem` ' +
322
+ 'instead of `value`',
323
+ );
324
+ }
325
+ }
326
+ }
282
327
  }
283
328
 
284
329
  defineCustomElement(ComboBox);
@@ -1,2 +1,2 @@
1
- import './theme/lumo/vaadin-combo-box.js';
1
+ import './src/vaadin-combo-box.js';
2
2
  export * from './src/vaadin-combo-box.js';