@vaadin/combo-box 24.0.0-alpha9 → 24.0.0-beta2

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 (29) hide show
  1. package/package.json +13 -13
  2. package/src/vaadin-combo-box-data-provider-mixin.js +4 -6
  3. package/src/vaadin-combo-box-item-mixin.d.ts +65 -0
  4. package/src/vaadin-combo-box-item-mixin.js +127 -0
  5. package/src/vaadin-combo-box-item.d.ts +45 -0
  6. package/src/vaadin-combo-box-item.js +3 -114
  7. package/src/vaadin-combo-box-light.js +25 -25
  8. package/src/vaadin-combo-box-mixin.d.ts +4 -12
  9. package/src/vaadin-combo-box-mixin.js +42 -40
  10. package/src/vaadin-combo-box-overlay-mixin.d.ts +11 -0
  11. package/src/vaadin-combo-box-overlay-mixin.js +60 -0
  12. package/src/vaadin-combo-box-overlay.d.ts +20 -0
  13. package/src/vaadin-combo-box-overlay.js +12 -45
  14. package/src/vaadin-combo-box-scroller-mixin.d.ts +82 -0
  15. package/src/vaadin-combo-box-scroller-mixin.js +361 -0
  16. package/src/vaadin-combo-box-scroller.d.ts +19 -0
  17. package/src/vaadin-combo-box-scroller.js +5 -345
  18. package/src/vaadin-combo-box.d.ts +2 -0
  19. package/src/vaadin-combo-box.js +5 -4
  20. package/theme/lumo/vaadin-combo-box-item-styles.js +2 -0
  21. package/theme/lumo/vaadin-combo-box-light.js +1 -1
  22. package/theme/lumo/{vaadin-combo-box-dropdown-styles.js → vaadin-combo-box-overlay-styles.js} +21 -13
  23. package/theme/lumo/vaadin-combo-box.js +1 -1
  24. package/theme/material/vaadin-combo-box-item-styles.js +2 -0
  25. package/theme/material/vaadin-combo-box-light.js +1 -1
  26. package/theme/material/{vaadin-combo-box-dropdown-styles.js → vaadin-combo-box-overlay-styles.js} +20 -9
  27. package/theme/material/vaadin-combo-box.js +1 -1
  28. package/web-types.json +18 -18
  29. package/web-types.lit.json +6 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/combo-box",
3
- "version": "24.0.0-alpha9",
3
+ "version": "24.0.0-beta2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -38,20 +38,20 @@
38
38
  "dependencies": {
39
39
  "@open-wc/dedupe-mixin": "^1.3.0",
40
40
  "@polymer/polymer": "^3.0.0",
41
- "@vaadin/component-base": "24.0.0-alpha9",
42
- "@vaadin/field-base": "24.0.0-alpha9",
43
- "@vaadin/input-container": "24.0.0-alpha9",
44
- "@vaadin/item": "24.0.0-alpha9",
45
- "@vaadin/lit-renderer": "24.0.0-alpha9",
46
- "@vaadin/overlay": "24.0.0-alpha9",
47
- "@vaadin/vaadin-lumo-styles": "24.0.0-alpha9",
48
- "@vaadin/vaadin-material-styles": "24.0.0-alpha9",
49
- "@vaadin/vaadin-themable-mixin": "24.0.0-alpha9"
41
+ "@vaadin/component-base": "24.0.0-beta2",
42
+ "@vaadin/field-base": "24.0.0-beta2",
43
+ "@vaadin/input-container": "24.0.0-beta2",
44
+ "@vaadin/item": "24.0.0-beta2",
45
+ "@vaadin/lit-renderer": "24.0.0-beta2",
46
+ "@vaadin/overlay": "24.0.0-beta2",
47
+ "@vaadin/vaadin-lumo-styles": "24.0.0-beta2",
48
+ "@vaadin/vaadin-material-styles": "24.0.0-beta2",
49
+ "@vaadin/vaadin-themable-mixin": "24.0.0-beta2"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@esm-bundle/chai": "^4.3.4",
53
- "@vaadin/testing-helpers": "^0.3.2",
54
- "@vaadin/text-field": "24.0.0-alpha9",
53
+ "@vaadin/testing-helpers": "^0.4.0",
54
+ "@vaadin/text-field": "24.0.0-beta2",
55
55
  "lit": "^2.0.0",
56
56
  "sinon": "^13.0.2"
57
57
  },
@@ -59,5 +59,5 @@
59
59
  "web-types.json",
60
60
  "web-types.lit.json"
61
61
  ],
62
- "gitHead": "cc3f747164041566b300bde4b105d2475649e93f"
62
+ "gitHead": "00086f1f6d487f042f189c9b9ecd7ba736960888"
63
63
  }
@@ -311,13 +311,11 @@ export const ComboBoxDataProviderMixin = (superClass) =>
311
311
  _flushPendingRequests(size) {
312
312
  if (this._pendingRequests) {
313
313
  const lastPage = Math.ceil(size / this.pageSize);
314
- const pendingRequestsKeys = Object.keys(this._pendingRequests);
315
- for (let reqIdx = 0; reqIdx < pendingRequestsKeys.length; reqIdx++) {
316
- const page = parseInt(pendingRequestsKeys[reqIdx]);
317
- if (page >= lastPage) {
318
- this._pendingRequests[page]([], size);
314
+ Object.entries(this._pendingRequests).forEach(([page, callback]) => {
315
+ if (parseInt(page) >= lastPage) {
316
+ callback([], size);
319
317
  }
320
- }
318
+ });
321
319
  }
322
320
  }
323
321
  };
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2015 - 2023 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 type ComboBoxDefaultItem = any;
9
+
10
+ export interface ComboBoxItemModel<TItem> {
11
+ index: number;
12
+ item: TItem;
13
+ selected: boolean;
14
+ focused: boolean;
15
+ }
16
+
17
+ export type ComboBoxItemRenderer<TItem, TOwner> = (
18
+ root: HTMLElement,
19
+ owner: TOwner,
20
+ model: ComboBoxItemModel<TItem>,
21
+ ) => void;
22
+
23
+ export declare function ComboBoxItemMixin<TItem, TOwner, T extends Constructor<HTMLElement>>(
24
+ base: T,
25
+ ): Constructor<ComboBoxItemMixinClass<TItem, TOwner>> & T;
26
+
27
+ export declare class ComboBoxItemMixinClass<TItem, TOwner> {
28
+ /**
29
+ * The item to render.
30
+ */
31
+ index: number;
32
+
33
+ /**
34
+ * The item to render.
35
+ */
36
+ item: TItem;
37
+
38
+ /**
39
+ * The text to render in the item.
40
+ */
41
+ label: string;
42
+
43
+ /**
44
+ * True when item is selected.
45
+ */
46
+ selected: boolean;
47
+
48
+ /**
49
+ * True when item is focused.
50
+ */
51
+ focused: boolean;
52
+
53
+ /**
54
+ * Custom function for rendering the item content.
55
+ */
56
+ renderer: ComboBoxItemRenderer<TItem, TOwner>;
57
+
58
+ /**
59
+ * Requests an update for the content of the item.
60
+ * While performing the update, it invokes the renderer passed in the `renderer` property.
61
+ *
62
+ * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
63
+ */
64
+ requestContentUpdate(): void;
65
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2015 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+
7
+ /**
8
+ * @polymerMixin
9
+ */
10
+ export const ComboBoxItemMixin = (superClass) =>
11
+ class ComboBoxItemMixinClass extends superClass {
12
+ static get properties() {
13
+ return {
14
+ /**
15
+ * The index of the item.
16
+ */
17
+ index: {
18
+ type: Number,
19
+ },
20
+
21
+ /**
22
+ * The item to render.
23
+ */
24
+ item: {
25
+ type: Object,
26
+ },
27
+
28
+ /**
29
+ * The text to render in the item.
30
+ */
31
+ label: {
32
+ type: String,
33
+ },
34
+
35
+ /**
36
+ * True when item is selected.
37
+ */
38
+ selected: {
39
+ type: Boolean,
40
+ value: false,
41
+ reflectToAttribute: true,
42
+ },
43
+
44
+ /**
45
+ * True when item is focused.
46
+ */
47
+ focused: {
48
+ type: Boolean,
49
+ value: false,
50
+ reflectToAttribute: true,
51
+ },
52
+
53
+ /**
54
+ * Custom function for rendering the item content.
55
+ */
56
+ renderer: {
57
+ type: Function,
58
+ },
59
+ };
60
+ }
61
+
62
+ static get observers() {
63
+ return ['__rendererOrItemChanged(renderer, index, item.*, selected, focused)', '__updateLabel(label, renderer)'];
64
+ }
65
+
66
+ /** @protected */
67
+ connectedCallback() {
68
+ super.connectedCallback();
69
+
70
+ this._owner = this.parentNode.owner;
71
+
72
+ const hostDir = this._owner.getAttribute('dir');
73
+ if (hostDir) {
74
+ this.setAttribute('dir', hostDir);
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Requests an update for the content of the item.
80
+ * While performing the update, it invokes the renderer passed in the `renderer` property.
81
+ *
82
+ * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
83
+ */
84
+ requestContentUpdate() {
85
+ if (!this.renderer) {
86
+ return;
87
+ }
88
+
89
+ const model = {
90
+ index: this.index,
91
+ item: this.item,
92
+ focused: this.focused,
93
+ selected: this.selected,
94
+ };
95
+
96
+ this.renderer(this, this._owner, model);
97
+ }
98
+
99
+ /** @private */
100
+ __rendererOrItemChanged(renderer, index, item) {
101
+ if (item === undefined || index === undefined) {
102
+ return;
103
+ }
104
+
105
+ if (this._oldRenderer !== renderer) {
106
+ this.innerHTML = '';
107
+ // Whenever a Lit-based renderer is used, it assigns a Lit part to the node it was rendered into.
108
+ // When clearing the rendered content, this part needs to be manually disposed of.
109
+ // Otherwise, using a Lit-based renderer on the same node will throw an exception or render nothing afterward.
110
+ delete this._$litPart$;
111
+ }
112
+
113
+ if (renderer) {
114
+ this._oldRenderer = renderer;
115
+ this.requestContentUpdate();
116
+ }
117
+ }
118
+
119
+ /** @private */
120
+ __updateLabel(label, renderer) {
121
+ if (renderer) {
122
+ return;
123
+ }
124
+
125
+ this.textContent = label;
126
+ }
127
+ };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2015 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import type { DirMixinClass } from '@vaadin/component-base/src/dir-mixin.js';
7
+ import type { ThemableMixinClass } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
8
+ import type { ComboBox } from './vaadin-combo-box.js';
9
+ import type { ComboBoxDefaultItem, ComboBoxItemMixinClass } from './vaadin-combo-box-item-mixin.js';
10
+
11
+ /**
12
+ * An item element used by the `<vaadin-combo-box>` dropdown.
13
+ *
14
+ * ### Styling
15
+ *
16
+ * The following shadow DOM parts are available for styling:
17
+ *
18
+ * Part name | Description
19
+ * ------------|--------------
20
+ * `checkmark` | The graphical checkmark shown for a selected item
21
+ * `content` | The element that wraps the item content
22
+ *
23
+ * The following state attributes are exposed for styling:
24
+ *
25
+ * Attribute | Description
26
+ * -------------|-------------
27
+ * `selected` | Set when the item is selected
28
+ * `focused` | Set when the item is focused
29
+ *
30
+ * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
31
+ */
32
+ declare class ComboBoxItem extends HTMLElement {}
33
+
34
+ interface ComboBoxItem<TItem = ComboBoxDefaultItem>
35
+ extends ComboBoxItemMixinClass<TItem, ComboBox>,
36
+ DirMixinClass,
37
+ ThemableMixinClass {}
38
+
39
+ declare global {
40
+ interface HTMLElementTagNameMap {
41
+ 'vaadin-combo-box-item': ComboBoxItem;
42
+ }
43
+ }
44
+
45
+ export { ComboBoxItem };
@@ -6,6 +6,7 @@
6
6
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
7
  import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
8
8
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
9
+ import { ComboBoxItemMixin } from './vaadin-combo-box-item-mixin.js';
9
10
 
10
11
  /**
11
12
  * An item element used by the `<vaadin-combo-box>` dropdown.
@@ -28,11 +29,12 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
28
29
  *
29
30
  * See [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.
30
31
  *
32
+ * @mixes ComboBoxItemMixin
31
33
  * @mixes ThemableMixin
32
34
  * @mixes DirMixin
33
35
  * @private
34
36
  */
35
- export class ComboBoxItem extends ThemableMixin(DirMixin(PolymerElement)) {
37
+ export class ComboBoxItem extends ComboBoxItemMixin(ThemableMixin(DirMixin(PolymerElement))) {
36
38
  static get template() {
37
39
  return html`
38
40
  <style>
@@ -54,119 +56,6 @@ export class ComboBoxItem extends ThemableMixin(DirMixin(PolymerElement)) {
54
56
  static get is() {
55
57
  return 'vaadin-combo-box-item';
56
58
  }
57
-
58
- static get properties() {
59
- return {
60
- /**
61
- * The index of the item
62
- */
63
- index: Number,
64
-
65
- /**
66
- * The item to render
67
- * @type {(String|Object)}
68
- */
69
- item: Object,
70
-
71
- /**
72
- * The text label corresponding to the item
73
- */
74
- label: String,
75
-
76
- /**
77
- * True when item is selected
78
- */
79
- selected: {
80
- type: Boolean,
81
- value: false,
82
- reflectToAttribute: true,
83
- },
84
-
85
- /**
86
- * True when item is focused
87
- */
88
- focused: {
89
- type: Boolean,
90
- value: false,
91
- reflectToAttribute: true,
92
- },
93
-
94
- /**
95
- * Custom function for rendering the content of the `<vaadin-combo-box-item>` propagated from the combo box element.
96
- */
97
- renderer: Function,
98
-
99
- /**
100
- * Saved instance of a custom renderer function.
101
- */
102
- _oldRenderer: Function,
103
- };
104
- }
105
-
106
- static get observers() {
107
- return ['__rendererOrItemChanged(renderer, index, item.*, selected, focused)', '__updateLabel(label, renderer)'];
108
- }
109
-
110
- connectedCallback() {
111
- super.connectedCallback();
112
-
113
- this._comboBox = this.parentNode.comboBox;
114
-
115
- const hostDir = this._comboBox.getAttribute('dir');
116
- if (hostDir) {
117
- this.setAttribute('dir', hostDir);
118
- }
119
- }
120
-
121
- /**
122
- * Requests an update for the content of the item.
123
- * While performing the update, it invokes the renderer passed in the `renderer` property.
124
- *
125
- * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
126
- */
127
- requestContentUpdate() {
128
- if (!this.renderer) {
129
- return;
130
- }
131
-
132
- const model = {
133
- index: this.index,
134
- item: this.item,
135
- focused: this.focused,
136
- selected: this.selected,
137
- };
138
-
139
- this.renderer(this, this._comboBox, model);
140
- }
141
-
142
- /** @private */
143
- __rendererOrItemChanged(renderer, index, item) {
144
- if (item === undefined || index === undefined) {
145
- return;
146
- }
147
-
148
- if (this._oldRenderer !== renderer) {
149
- this.innerHTML = '';
150
- // Whenever a Lit-based renderer is used, it assigns a Lit part to the node it was rendered into.
151
- // When clearing the rendered content, this part needs to be manually disposed of.
152
- // Otherwise, using a Lit-based renderer on the same node will throw an exception or render nothing afterward.
153
- delete this._$litPart$;
154
- }
155
-
156
- if (renderer) {
157
- this._oldRenderer = renderer;
158
- this.requestContentUpdate();
159
- }
160
- }
161
-
162
- /** @private */
163
- __updateLabel(label, renderer) {
164
- if (renderer) {
165
- return;
166
- }
167
-
168
- this.textContent = label;
169
- }
170
59
  }
171
60
 
172
61
  customElements.define(ComboBoxItem.is, ComboBoxItem);
@@ -117,30 +117,6 @@ class ComboBoxLight extends ComboBoxDataProviderMixin(ComboBoxMixin(ValidateMixi
117
117
  return this.querySelector('.clear-button');
118
118
  }
119
119
 
120
- /** @protected */
121
- ready() {
122
- super.ready();
123
-
124
- this._toggleElement = this.querySelector('.toggle-button');
125
-
126
- // Wait until the slotted input DOM is ready
127
- afterNextRender(this, () => {
128
- this._setInputElement(this.querySelector('vaadin-text-field,.input'));
129
- this._revertInputValue();
130
- });
131
- }
132
-
133
- /**
134
- * Returns true if the current input value satisfies all constraints (if any).
135
- * @return {boolean}
136
- */
137
- checkValidity() {
138
- if (this.inputElement.validate) {
139
- return this.inputElement.validate();
140
- }
141
- return super.checkValidity();
142
- }
143
-
144
120
  /**
145
121
  * @return {string}
146
122
  * @protected
@@ -181,6 +157,30 @@ class ComboBoxLight extends ComboBoxDataProviderMixin(ComboBoxMixin(ValidateMixi
181
157
  return undefined;
182
158
  }
183
159
 
160
+ /** @protected */
161
+ ready() {
162
+ super.ready();
163
+
164
+ this._toggleElement = this.querySelector('.toggle-button');
165
+
166
+ // Wait until the slotted input DOM is ready
167
+ afterNextRender(this, () => {
168
+ this._setInputElement(this.querySelector('vaadin-text-field,.input'));
169
+ this._revertInputValue();
170
+ });
171
+ }
172
+
173
+ /**
174
+ * Returns true if the current input value satisfies all constraints (if any).
175
+ * @return {boolean}
176
+ */
177
+ checkValidity() {
178
+ if (this.inputElement.validate) {
179
+ return this.inputElement.validate();
180
+ }
181
+ return super.checkValidity();
182
+ }
183
+
184
184
  /** @protected */
185
185
  _isClearButton(event) {
186
186
  return (
@@ -198,7 +198,7 @@ class ComboBoxLight extends ComboBoxDataProviderMixin(ComboBoxMixin(ValidateMixi
198
198
  super._onChange(event);
199
199
 
200
200
  if (this._isClearButton(event)) {
201
- this._clear();
201
+ this._onClearAction();
202
202
  }
203
203
  }
204
204
  }
@@ -9,19 +9,11 @@ import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mix
9
9
  import type { OverlayClassMixinClass } from '@vaadin/component-base/src/overlay-class-mixin.js';
10
10
  import type { InputMixinClass } from '@vaadin/field-base/src/input-mixin.js';
11
11
  import type { ComboBox } from './vaadin-combo-box.js';
12
+ import type { ComboBoxDefaultItem, ComboBoxItemModel, ComboBoxItemRenderer } from './vaadin-combo-box-item-mixin.js';
12
13
 
13
- export type ComboBoxDefaultItem = any;
14
+ export type { ComboBoxDefaultItem, ComboBoxItemModel };
14
15
 
15
- export interface ComboBoxItemModel<TItem> {
16
- index: number;
17
- item: TItem;
18
- }
19
-
20
- export type ComboBoxRenderer<TItem> = (
21
- root: HTMLElement,
22
- comboBox: ComboBox<TItem>,
23
- model: ComboBoxItemModel<TItem>,
24
- ) => void;
16
+ export type ComboBoxRenderer<TItem> = ComboBoxItemRenderer<TItem, ComboBox<TItem>>;
25
17
 
26
18
  export declare function ComboBoxMixin<TItem, T extends Constructor<HTMLElement>>(
27
19
  base: T,
@@ -87,7 +79,7 @@ export declare class ComboBoxMixinClass<TItem> {
87
79
  /**
88
80
  * The `String` value for the selected item of the combo box.
89
81
  *
90
- * When there’s no item selected, the value is an empty string.
82
+ * When there is no item selected, the value is an empty string.
91
83
  *
92
84
  * Use `selectedItem` property to get the raw selected item from
93
85
  * the `items` array.