@vaadin/combo-box 25.2.0-alpha8 → 25.2.0-beta1

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": "25.2.0-alpha8",
3
+ "version": "25.2.0-beta1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,22 +36,22 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "@open-wc/dedupe-mixin": "^1.3.0",
39
- "@vaadin/a11y-base": "25.2.0-alpha8",
40
- "@vaadin/component-base": "25.2.0-alpha8",
41
- "@vaadin/field-base": "25.2.0-alpha8",
42
- "@vaadin/input-container": "25.2.0-alpha8",
43
- "@vaadin/item": "25.2.0-alpha8",
44
- "@vaadin/lit-renderer": "25.2.0-alpha8",
45
- "@vaadin/overlay": "25.2.0-alpha8",
46
- "@vaadin/vaadin-themable-mixin": "25.2.0-alpha8",
39
+ "@vaadin/a11y-base": "25.2.0-beta1",
40
+ "@vaadin/component-base": "25.2.0-beta1",
41
+ "@vaadin/field-base": "25.2.0-beta1",
42
+ "@vaadin/input-container": "25.2.0-beta1",
43
+ "@vaadin/item": "25.2.0-beta1",
44
+ "@vaadin/lit-renderer": "25.2.0-beta1",
45
+ "@vaadin/overlay": "25.2.0-beta1",
46
+ "@vaadin/vaadin-themable-mixin": "25.2.0-beta1",
47
47
  "lit": "^3.0.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@vaadin/aura": "25.2.0-alpha8",
51
- "@vaadin/chai-plugins": "25.2.0-alpha8",
52
- "@vaadin/test-runner-commands": "25.2.0-alpha8",
50
+ "@vaadin/aura": "25.2.0-beta1",
51
+ "@vaadin/chai-plugins": "25.2.0-beta1",
52
+ "@vaadin/test-runner-commands": "25.2.0-beta1",
53
53
  "@vaadin/testing-helpers": "^2.0.0",
54
- "@vaadin/vaadin-lumo-styles": "25.2.0-alpha8",
54
+ "@vaadin/vaadin-lumo-styles": "25.2.0-beta1",
55
55
  "sinon": "^21.0.2"
56
56
  },
57
57
  "customElements": "custom-elements.json",
@@ -59,5 +59,5 @@
59
59
  "web-types.json",
60
60
  "web-types.lit.json"
61
61
  ],
62
- "gitHead": "2b82e20cdfc605b1187e9a24ae42869e1500ab68"
62
+ "gitHead": "471a23f60d1eb725f98a33f62cb9664d9c0a4163"
63
63
  }
@@ -12,14 +12,6 @@ import { InputMixin } from '@vaadin/field-base/src/input-mixin.js';
12
12
  import { VirtualKeyboardController } from '@vaadin/field-base/src/virtual-keyboard-controller.js';
13
13
  import { ComboBoxPlaceholder } from './vaadin-combo-box-placeholder.js';
14
14
 
15
- /**
16
- * @polymerMixin
17
- * @mixes DisabledMixin
18
- * @mixes FocusMixin
19
- * @mixes InputMixin
20
- * @mixes KeyboardMixin
21
- * @param {function(new:HTMLElement)} superClass
22
- */
23
15
  export const ComboBoxBaseMixin = (superClass) =>
24
16
  class ComboBoxMixinBaseClass extends KeyboardMixin(InputMixin(DisabledMixin(FocusMixin(superClass)))) {
25
17
  static get properties() {
@@ -6,9 +6,6 @@
6
6
  import { DataProviderController } from '@vaadin/component-base/src/data-provider-controller/data-provider-controller.js';
7
7
  import { ComboBoxPlaceholder } from './vaadin-combo-box-placeholder.js';
8
8
 
9
- /**
10
- * @polymerMixin
11
- */
12
9
  export const ComboBoxDataProviderMixin = (superClass) =>
13
10
  class DataProviderMixin extends superClass {
14
11
  static get properties() {
@@ -4,9 +4,6 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
 
7
- /**
8
- * @polymerMixin
9
- */
10
7
  export const ComboBoxItemMixin = (superClass) =>
11
8
  class ComboBoxItemMixinClass extends superClass {
12
9
  static get properties() {
@@ -35,9 +35,6 @@ import { ComboBoxItemMixin } from './vaadin-combo-box-item-mixin.js';
35
35
  * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
36
36
  *
37
37
  * @customElement vaadin-combo-box-item
38
- * @mixes ComboBoxItemMixin
39
- * @mixes ThemableMixin
40
- * @mixes DirMixin
41
38
  * @private
42
39
  */
43
40
  export class ComboBoxItem extends ComboBoxItemMixin(
@@ -35,10 +35,6 @@ function findItemIndex(items, callback) {
35
35
  });
36
36
  }
37
37
 
38
- /**
39
- * @polymerMixin
40
- * @mixes ComboBoxBaseMixin
41
- */
42
38
  export const ComboBoxItemsMixin = (superClass) =>
43
39
  class ComboBoxItemsMixinClass extends ComboBoxBaseMixin(superClass) {
44
40
  static get properties() {
@@ -16,12 +16,6 @@ function isValidValue(value) {
16
16
  return value !== undefined && value !== null;
17
17
  }
18
18
 
19
- /**
20
- * @polymerMixin
21
- * @mixes ComboBoxItemsMixin
22
- * @mixes ValidateMixin
23
- * @param {function(new:HTMLElement)} superClass
24
- */
25
19
  export const ComboBoxMixin = (superClass) =>
26
20
  class ComboBoxMixinClass extends ValidateMixin(ComboBoxItemsMixin(superClass)) {
27
21
  static get properties() {
@@ -177,7 +171,7 @@ export const ComboBoxMixin = (superClass) =>
177
171
  _openedOrItemsChanged(opened, items, loading, keepOverlayOpened) {
178
172
  // Close the overlay if there are no items to display.
179
173
  // See https://github.com/vaadin/vaadin-combo-box/pull/964
180
- this._overlayOpened = opened && (keepOverlayOpened || loading || !!(items && items.length));
174
+ this._overlayOpened = opened && (keepOverlayOpened || loading || !!items?.length);
181
175
  }
182
176
 
183
177
  /**
@@ -552,43 +546,4 @@ export const ComboBoxMixin = (superClass) =>
552
546
 
553
547
  super._handleFocusOut();
554
548
  }
555
-
556
- /**
557
- * Fired when the value changes.
558
- *
559
- * @event value-changed
560
- * @param {Object} detail
561
- * @param {String} detail.value the combobox value
562
- */
563
-
564
- /**
565
- * Fired when selected item changes.
566
- *
567
- * @event selected-item-changed
568
- * @param {Object} detail
569
- * @param {Object|String} detail.value the selected item. Type is the same as the type of `items`.
570
- */
571
-
572
- /**
573
- * Fired when the user sets a custom value.
574
- * @event custom-value-set
575
- * @param {String} detail the custom value
576
- */
577
-
578
- /**
579
- * Fired when the user commits a value change.
580
- * @event change
581
- */
582
-
583
- /**
584
- * Fired after the `vaadin-combo-box-overlay` opens.
585
- *
586
- * @event vaadin-combo-box-dropdown-opened
587
- */
588
-
589
- /**
590
- * Fired after the `vaadin-combo-box-overlay` closes.
591
- *
592
- * @event vaadin-combo-box-dropdown-closed
593
- */
594
549
  };
@@ -6,10 +6,6 @@
6
6
  import { isElementFocusable } from '@vaadin/a11y-base/src/focus-utils.js';
7
7
  import { PositionMixin } from '@vaadin/overlay/src/vaadin-overlay-position-mixin.js';
8
8
 
9
- /**
10
- * @polymerMixin
11
- * @mixes PositionMixin
12
- */
13
9
  export const ComboBoxOverlayMixin = (superClass) =>
14
10
  class ComboBoxOverlayMixin extends PositionMixin(superClass) {
15
11
  static get observers() {
@@ -19,10 +19,6 @@ import { ComboBoxOverlayMixin } from './vaadin-combo-box-overlay-mixin.js';
19
19
  *
20
20
  * @customElement vaadin-combo-box-overlay
21
21
  * @extends HTMLElement
22
- * @mixes ComboBoxOverlayMixin
23
- * @mixes DirMixin
24
- * @mixes OverlayMixin
25
- * @mixes ThemableMixin
26
22
  * @private
27
23
  */
28
24
  export class ComboBoxOverlay extends ComboBoxOverlayMixin(
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2015 - 2026 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
+
8
+ export declare function ComboBoxScrollToIndexMixin<T extends Constructor<HTMLElement>>(
9
+ base: T,
10
+ ): Constructor<ComboBoxScrollToIndexMixinClass> & T;
11
+
12
+ export declare class ComboBoxScrollToIndexMixinClass {
13
+ /**
14
+ * Scrolls the dropdown to the item at the given index and sets it as the
15
+ * focused (highlighted) item. Safe to call before the dropdown is opened
16
+ * or while the data provider is loading: the call is queued and executed
17
+ * once the overlay is open and not loading.
18
+ *
19
+ * Because this sets the focused item, closing the dropdown without an
20
+ * explicit selection change (e.g. via outside click or blur) will commit
21
+ * the focused item as `selectedItem`. In the typical use case (scroll to
22
+ * the currently selected item) this is a no-op; callers scrolling to a
23
+ * different index should be aware of this behavior.
24
+ *
25
+ * @param index Index of the item to scroll to
26
+ */
27
+ scrollToIndex(index: number): void;
28
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2015 - 2026 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { ComboBoxPlaceholder } from './vaadin-combo-box-placeholder.js';
7
+
8
+ export const ComboBoxScrollToIndexMixin = (superClass) =>
9
+ class ScrollToIndexMixin extends superClass {
10
+ static get observers() {
11
+ return ['__clearPendingScrollOnFilter(filter)'];
12
+ }
13
+
14
+ /**
15
+ * Scrolls the dropdown to the item at the given index and sets it as the
16
+ * focused (highlighted) item. Safe to call before the dropdown is opened
17
+ * or while the data provider is loading: the call is queued and executed
18
+ * once the overlay is open and not loading.
19
+ *
20
+ * Because this sets the focused item, closing the dropdown without an
21
+ * explicit selection change (e.g. via outside click or blur) will commit
22
+ * the focused item as `selectedItem`. In the typical use case (scroll to
23
+ * the currently selected item) this is a no-op; callers scrolling to a
24
+ * different index should be aware of this behavior.
25
+ *
26
+ * @param {number} index Index of the item to scroll to
27
+ */
28
+ scrollToIndex(index) {
29
+ if (typeof index !== 'number' || Number.isNaN(index) || index < 0) {
30
+ return;
31
+ }
32
+
33
+ if (!this._overlayOpened || this.loading) {
34
+ this.__scrollToPendingIndex = index;
35
+ return;
36
+ }
37
+
38
+ if (!this._dropdownItems || index >= this._dropdownItems.length) {
39
+ return;
40
+ }
41
+
42
+ if (this._dropdownItems[index] instanceof ComboBoxPlaceholder) {
43
+ // The target item is on a page that has not been loaded yet. Request
44
+ // the page directly and queue the focus-index update for after the
45
+ // page loads (see `__onDataProviderPageLoaded` →
46
+ // `__scrollToPendingIndexIfNeeded`). Relying on `_scrollIntoView` to
47
+ // trigger the page load via the visible-placeholder `index-requested`
48
+ // chain is unreliable on reopen with cached data: the virtualizer
49
+ // has just been torn down by closing the overlay and its scroll API
50
+ // is a no-op while it rebuilds physical items.
51
+ this.__scrollToPendingIndex = index;
52
+ this.__dataProviderController.ensureFlatIndexLoaded(index);
53
+ return;
54
+ }
55
+
56
+ delete this.__scrollToPendingIndex;
57
+ this._focusedIndex = index;
58
+ requestAnimationFrame(() => {
59
+ if (this.isConnected) {
60
+ this._updateActiveDescendant(index);
61
+ }
62
+ });
63
+ }
64
+
65
+ /** @private */
66
+ __scrollToPendingIndexIfNeeded() {
67
+ if (this.__scrollToPendingIndex !== undefined && !this.loading) {
68
+ this.scrollToIndex(this.__scrollToPendingIndex);
69
+ }
70
+ }
71
+
72
+ /** @private */
73
+ __clearPendingScrollOnFilter() {
74
+ delete this.__scrollToPendingIndex;
75
+ }
76
+
77
+ /**
78
+ * Override method from `ComboBoxBaseMixin` to flush any pending
79
+ * `scrollToIndex` call after the overlay opens.
80
+ *
81
+ * @protected
82
+ * @override
83
+ */
84
+ _onOpened() {
85
+ super._onOpened();
86
+ this.__scrollToPendingIndexIfNeeded();
87
+ }
88
+
89
+ /**
90
+ * Override method from `ComboBoxDataProviderMixin` to flush any pending
91
+ * `scrollToIndex` call after a data-provider page lands.
92
+ *
93
+ * @private
94
+ * @override
95
+ */
96
+ __onDataProviderPageLoaded() {
97
+ super.__onDataProviderPageLoaded();
98
+ this.__scrollToPendingIndexIfNeeded();
99
+ }
100
+ };
@@ -8,9 +8,6 @@ import { generateUniqueId } from '@vaadin/component-base/src/unique-id-utils.js'
8
8
  import { Virtualizer } from '@vaadin/component-base/src/virtualizer.js';
9
9
  import { ComboBoxPlaceholder } from './vaadin-combo-box-placeholder.js';
10
10
 
11
- /**
12
- * @polymerMixin
13
- */
14
11
  export const ComboBoxScrollerMixin = (superClass) =>
15
12
  class ComboBoxScrollerMixin extends superClass {
16
13
  static get properties() {
@@ -262,6 +259,25 @@ export const ComboBoxScrollerMixin = (superClass) =>
262
259
  }
263
260
 
264
261
  this.requestContentUpdate();
262
+ return;
263
+ }
264
+
265
+ // Reset the DOM scrollTop and the virtualizer adapter's
266
+ // `_scrollPosition` cache. Without the cache reset, the adapter's
267
+ // ResizeObserver restores the prior offset when the overlay becomes
268
+ // visible again, leaving the next open stuck at the previous offset
269
+ // (or blank with dataProvider) until the user scrolls. The
270
+ // virtualizer's own `scrollToIndex` can't help — by the time this
271
+ // observer runs, `offsetHeight` is already 0 and its scroll API is
272
+ // a no-op. Guarded on `_scrollPosition > 0` so the reset is skipped
273
+ // when there is nothing to reset (e.g. the initial observer run
274
+ // before the dropdown has ever been opened); unconditionally
275
+ // touching `scrollTop` on connect can affect the outer document's
276
+ // scroll position (see the combo-box re-layout integration test).
277
+ const adapter = this.__virtualizer && this.__virtualizer.__adapter;
278
+ if (adapter && adapter._scrollPosition > 0) {
279
+ this.scrollTop = 0;
280
+ adapter._scrollPosition = 0;
265
281
  }
266
282
  }
267
283
 
@@ -14,7 +14,6 @@ import { ComboBoxScrollerMixin } from './vaadin-combo-box-scroller-mixin.js';
14
14
  *
15
15
  * @customElement vaadin-combo-box-scroller
16
16
  * @extends HTMLElement
17
- * @mixes ComboBoxScrollerMixin
18
17
  * @private
19
18
  */
20
19
  export class ComboBoxScroller extends ComboBoxScrollerMixin(PolylitMixin(LitElement)) {
@@ -24,6 +24,7 @@ import type { ComboBoxDataProviderMixinClass } from './vaadin-combo-box-data-pro
24
24
  import type { ComboBoxItemsMixinClass } from './vaadin-combo-box-items-mixin.js';
25
25
  import type { ComboBoxMixinClass } from './vaadin-combo-box-mixin.js';
26
26
  import type { ComboBoxDefaultItem } from './vaadin-combo-box-mixin.js';
27
+ import type { ComboBoxScrollToIndexMixinClass } from './vaadin-combo-box-scroll-to-index-mixin.js';
27
28
 
28
29
  export {
29
30
  ComboBoxDataProvider,
@@ -225,6 +226,8 @@ export interface ComboBoxEventMap<TItem> extends HTMLElementEventMap {
225
226
  * @fires {CustomEvent} selected-item-changed - Fired when the `selectedItem` property changes.
226
227
  * @fires {CustomEvent} value-changed - Fired when the `value` property changes.
227
228
  * @fires {CustomEvent} validated - Fired whenever the field is validated.
229
+ * @fires {CustomEvent} vaadin-combo-box-dropdown-opened - Fired after the `vaadin-combo-box-overlay` opens.
230
+ * @fires {CustomEvent} vaadin-combo-box-dropdown-closed - Fired after the `vaadin-combo-box-overlay` closes.
228
231
  */
229
232
  declare class ComboBox<TItem = ComboBoxDefaultItem> extends HTMLElement {
230
233
  addEventListener<K extends keyof ComboBoxEventMap<TItem>>(
@@ -245,6 +248,7 @@ interface ComboBox<TItem = ComboBoxDefaultItem>
245
248
  ComboBoxDataProviderMixinClass<TItem>,
246
249
  ComboBoxItemsMixinClass<TItem>,
247
250
  ComboBoxMixinClass<TItem>,
251
+ ComboBoxScrollToIndexMixinClass,
248
252
  ComboBoxBaseMixinClass,
249
253
  ValidateMixinClass,
250
254
  PatternMixinClass,
@@ -23,6 +23,7 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
23
23
  import { comboBoxStyles } from './styles/vaadin-combo-box-base-styles.js';
24
24
  import { ComboBoxDataProviderMixin } from './vaadin-combo-box-data-provider-mixin.js';
25
25
  import { ComboBoxMixin } from './vaadin-combo-box-mixin.js';
26
+ import { ComboBoxScrollToIndexMixin } from './vaadin-combo-box-scroll-to-index-mixin.js';
26
27
 
27
28
  /**
28
29
  * `<vaadin-combo-box>` is a web component for choosing a value from a filterable list of options
@@ -157,19 +158,17 @@ import { ComboBoxMixin } from './vaadin-combo-box-mixin.js';
157
158
  * @fires {CustomEvent} selected-item-changed - Fired when the `selectedItem` property changes.
158
159
  * @fires {CustomEvent} value-changed - Fired when the `value` property changes.
159
160
  * @fires {CustomEvent} validated - Fired whenever the field is validated.
161
+ * @fires {CustomEvent} vaadin-combo-box-dropdown-opened - Fired after the `vaadin-combo-box-overlay` opens.
162
+ * @fires {CustomEvent} vaadin-combo-box-dropdown-closed - Fired after the `vaadin-combo-box-overlay` closes.
160
163
  *
161
164
  * @customElement vaadin-combo-box
162
165
  * @extends HTMLElement
163
- * @mixes ElementMixin
164
- * @mixes ThemableMixin
165
- * @mixes InputControlMixin
166
- * @mixes PatternMixin
167
- * @mixes ComboBoxDataProviderMixin
168
- * @mixes ComboBoxMixin
169
166
  */
170
- class ComboBox extends ComboBoxDataProviderMixin(
171
- ComboBoxMixin(
172
- PatternMixin(InputControlMixin(ThemableMixin(ElementMixin(PolylitMixin(LumoInjectionMixin(LitElement)))))),
167
+ class ComboBox extends ComboBoxScrollToIndexMixin(
168
+ ComboBoxDataProviderMixin(
169
+ ComboBoxMixin(
170
+ PatternMixin(InputControlMixin(ThemableMixin(ElementMixin(PolylitMixin(LumoInjectionMixin(LitElement)))))),
171
+ ),
173
172
  ),
174
173
  ) {
175
174
  static get is() {