@vaadin/combo-box 24.0.0-alpha12 → 24.0.0-alpha13
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 +13 -13
- package/src/vaadin-combo-box-item-mixin.d.ts +65 -0
- package/src/vaadin-combo-box-item-mixin.js +127 -0
- package/src/vaadin-combo-box-item.d.ts +45 -0
- package/src/vaadin-combo-box-item.js +3 -114
- package/src/vaadin-combo-box-mixin.d.ts +3 -11
- package/src/vaadin-combo-box-mixin.js +1 -1
- package/src/vaadin-combo-box-overlay-mixin.d.ts +11 -0
- package/src/vaadin-combo-box-overlay-mixin.js +60 -0
- package/src/vaadin-combo-box-overlay.d.ts +20 -0
- package/src/vaadin-combo-box-overlay.js +9 -48
- package/src/vaadin-combo-box-scroller-mixin.d.ts +82 -0
- package/src/vaadin-combo-box-scroller-mixin.js +361 -0
- package/src/vaadin-combo-box-scroller.d.ts +19 -0
- package/src/vaadin-combo-box-scroller.js +5 -346
- package/theme/lumo/vaadin-combo-box-item-styles.js +2 -0
- package/theme/lumo/vaadin-combo-box-light.js +1 -1
- package/theme/lumo/{vaadin-combo-box-dropdown-styles.js → vaadin-combo-box-overlay-styles.js} +21 -13
- package/theme/lumo/vaadin-combo-box.js +1 -1
- package/theme/material/vaadin-combo-box-item-styles.js +2 -0
- package/theme/material/vaadin-combo-box-light.js +1 -1
- package/theme/material/{vaadin-combo-box-dropdown-styles.js → vaadin-combo-box-overlay-styles.js} +20 -9
- package/theme/material/vaadin-combo-box.js +1 -1
- package/web-types.json +2 -2
- package/web-types.lit.json +2 -2
|
@@ -4,17 +4,16 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
7
|
-
import {
|
|
8
|
-
import { Virtualizer } from '@vaadin/component-base/src/virtualizer.js';
|
|
9
|
-
import { ComboBoxPlaceholder } from './vaadin-combo-box-placeholder.js';
|
|
7
|
+
import { ComboBoxScrollerMixin } from './vaadin-combo-box-scroller-mixin.js';
|
|
10
8
|
|
|
11
9
|
/**
|
|
12
|
-
*
|
|
10
|
+
* An element used internally by `<vaadin-combo-box>`. Not intended to be used separately.
|
|
13
11
|
*
|
|
14
12
|
* @extends HTMLElement
|
|
13
|
+
* @mixes ComboBoxScrollerMixin
|
|
15
14
|
* @private
|
|
16
15
|
*/
|
|
17
|
-
export class ComboBoxScroller extends PolymerElement {
|
|
16
|
+
export class ComboBoxScroller extends ComboBoxScrollerMixin(PolymerElement) {
|
|
18
17
|
static get is() {
|
|
19
18
|
return 'vaadin-combo-box-scroller';
|
|
20
19
|
}
|
|
@@ -40,7 +39,7 @@ export class ComboBoxScroller extends PolymerElement {
|
|
|
40
39
|
#selector {
|
|
41
40
|
border-width: var(--_vaadin-combo-box-items-container-border-width);
|
|
42
41
|
border-style: var(--_vaadin-combo-box-items-container-border-style);
|
|
43
|
-
border-color: var(--_vaadin-combo-box-items-container-border-color);
|
|
42
|
+
border-color: var(--_vaadin-combo-box-items-container-border-color, transparent);
|
|
44
43
|
}
|
|
45
44
|
</style>
|
|
46
45
|
<div id="selector">
|
|
@@ -48,346 +47,6 @@ export class ComboBoxScroller extends PolymerElement {
|
|
|
48
47
|
</div>
|
|
49
48
|
`;
|
|
50
49
|
}
|
|
51
|
-
|
|
52
|
-
static get properties() {
|
|
53
|
-
return {
|
|
54
|
-
/**
|
|
55
|
-
* A full set of items to filter the visible options from.
|
|
56
|
-
* Set to an empty array when combo-box is not opened.
|
|
57
|
-
*/
|
|
58
|
-
items: {
|
|
59
|
-
type: Array,
|
|
60
|
-
observer: '__itemsChanged',
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Index of an item that has focus outline and is scrolled into view.
|
|
65
|
-
* The actual focus still remains in the input field.
|
|
66
|
-
*/
|
|
67
|
-
focusedIndex: {
|
|
68
|
-
type: Number,
|
|
69
|
-
observer: '__focusedIndexChanged',
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Set to true while combo-box fetches new page from the data provider.
|
|
74
|
-
*/
|
|
75
|
-
loading: {
|
|
76
|
-
type: Boolean,
|
|
77
|
-
observer: '__loadingChanged',
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Whether the combo-box is currently opened or not. If set to false,
|
|
82
|
-
* calling `scrollIntoView` does not have any effect.
|
|
83
|
-
*/
|
|
84
|
-
opened: {
|
|
85
|
-
type: Boolean,
|
|
86
|
-
observer: '__openedChanged',
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* The selected item from the `items` array.
|
|
91
|
-
*/
|
|
92
|
-
selectedItem: {
|
|
93
|
-
type: Object,
|
|
94
|
-
observer: '__selectedItemChanged',
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Path for the id of the item, used to detect whether the item is selected.
|
|
99
|
-
*/
|
|
100
|
-
itemIdPath: {
|
|
101
|
-
type: String,
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Reference to the combo-box, used by the item elements.
|
|
106
|
-
*/
|
|
107
|
-
comboBox: {
|
|
108
|
-
type: Object,
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Function used to set a label for every combo-box item.
|
|
113
|
-
*/
|
|
114
|
-
getItemLabel: {
|
|
115
|
-
type: Object,
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Function used to render the content of every combo-box item.
|
|
120
|
-
*/
|
|
121
|
-
renderer: {
|
|
122
|
-
type: Object,
|
|
123
|
-
observer: '__rendererChanged',
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Used to propagate the `theme` attribute from the host element.
|
|
128
|
-
*/
|
|
129
|
-
theme: {
|
|
130
|
-
type: String,
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
constructor() {
|
|
136
|
-
super();
|
|
137
|
-
this.__boundOnItemClick = this.__onItemClick.bind(this);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
get _viewportTotalPaddingBottom() {
|
|
141
|
-
if (this._cachedViewportTotalPaddingBottom === undefined) {
|
|
142
|
-
const itemsStyle = window.getComputedStyle(this.$.selector);
|
|
143
|
-
this._cachedViewportTotalPaddingBottom = [itemsStyle.paddingBottom, itemsStyle.borderBottomWidth]
|
|
144
|
-
.map((v) => {
|
|
145
|
-
return parseInt(v, 10);
|
|
146
|
-
})
|
|
147
|
-
.reduce((sum, v) => {
|
|
148
|
-
return sum + v;
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return this._cachedViewportTotalPaddingBottom;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
__openedChanged(opened) {
|
|
156
|
-
if (opened) {
|
|
157
|
-
this.requestContentUpdate();
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/** @protected */
|
|
162
|
-
ready() {
|
|
163
|
-
super.ready();
|
|
164
|
-
|
|
165
|
-
// Ensure every instance has unique ID
|
|
166
|
-
this.id = `${this.localName}-${generateUniqueId()}`;
|
|
167
|
-
|
|
168
|
-
// Allow extensions to customize tag name for the items
|
|
169
|
-
this.__hostTagName = this.constructor.is.replace('-scroller', '');
|
|
170
|
-
|
|
171
|
-
this.setAttribute('role', 'listbox');
|
|
172
|
-
|
|
173
|
-
this.addEventListener('click', (e) => e.stopPropagation());
|
|
174
|
-
|
|
175
|
-
this.__patchWheelOverScrolling();
|
|
176
|
-
|
|
177
|
-
this.__virtualizer = new Virtualizer({
|
|
178
|
-
createElements: this.__createElements.bind(this),
|
|
179
|
-
updateElement: this.__updateElement.bind(this),
|
|
180
|
-
elementsContainer: this,
|
|
181
|
-
scrollTarget: this,
|
|
182
|
-
scrollContainer: this.$.selector,
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
requestContentUpdate() {
|
|
187
|
-
if (this.__virtualizer) {
|
|
188
|
-
this.__virtualizer.update();
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
scrollIntoView(index) {
|
|
193
|
-
if (!(this.opened && index >= 0)) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const visibleItemsCount = this._visibleItemsCount();
|
|
198
|
-
|
|
199
|
-
let targetIndex = index;
|
|
200
|
-
|
|
201
|
-
if (index > this.__virtualizer.lastVisibleIndex - 1) {
|
|
202
|
-
// Index is below the bottom, scrolling down. Make the item appear at the bottom.
|
|
203
|
-
// First scroll to target (will be at the top of the scroller) to make sure it's rendered.
|
|
204
|
-
this.__virtualizer.scrollToIndex(index);
|
|
205
|
-
// Then calculate the index for the following scroll (to get the target to bottom of the scroller).
|
|
206
|
-
targetIndex = index - visibleItemsCount + 1;
|
|
207
|
-
} else if (index > this.__virtualizer.firstVisibleIndex) {
|
|
208
|
-
// The item is already visible, scrolling is unnecessary per se. But we need to trigger iron-list to set
|
|
209
|
-
// the correct scrollTop on the scrollTarget. Scrolling to firstVisibleIndex.
|
|
210
|
-
targetIndex = this.__virtualizer.firstVisibleIndex;
|
|
211
|
-
}
|
|
212
|
-
this.__virtualizer.scrollToIndex(Math.max(0, targetIndex));
|
|
213
|
-
|
|
214
|
-
// Sometimes the item is partly below the bottom edge, detect and adjust.
|
|
215
|
-
const lastPhysicalItem = [...this.children].find(
|
|
216
|
-
(el) => !el.hidden && el.index === this.__virtualizer.lastVisibleIndex,
|
|
217
|
-
);
|
|
218
|
-
if (!lastPhysicalItem || index !== lastPhysicalItem.index) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
const lastPhysicalItemRect = lastPhysicalItem.getBoundingClientRect();
|
|
222
|
-
const scrollerRect = this.getBoundingClientRect();
|
|
223
|
-
const scrollTopAdjust = lastPhysicalItemRect.bottom - scrollerRect.bottom + this._viewportTotalPaddingBottom;
|
|
224
|
-
if (scrollTopAdjust > 0) {
|
|
225
|
-
this.scrollTop += scrollTopAdjust;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/** @private */
|
|
230
|
-
__getAriaRole(itemIndex) {
|
|
231
|
-
return itemIndex !== undefined ? 'option' : false;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/** @private */
|
|
235
|
-
__getAriaSelected(focusedIndex, itemIndex) {
|
|
236
|
-
return this.__isItemFocused(focusedIndex, itemIndex).toString();
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/** @private */
|
|
240
|
-
__isItemFocused(focusedIndex, itemIndex) {
|
|
241
|
-
return !this.loading && focusedIndex === itemIndex;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/** @private */
|
|
245
|
-
__isItemSelected(item, selectedItem, itemIdPath) {
|
|
246
|
-
if (item instanceof ComboBoxPlaceholder) {
|
|
247
|
-
return false;
|
|
248
|
-
} else if (itemIdPath && item !== undefined && selectedItem !== undefined) {
|
|
249
|
-
return this.get(itemIdPath, item) === this.get(itemIdPath, selectedItem);
|
|
250
|
-
}
|
|
251
|
-
return item === selectedItem;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/** @private */
|
|
255
|
-
__itemsChanged(items) {
|
|
256
|
-
if (this.__virtualizer && items) {
|
|
257
|
-
this.__virtualizer.size = items.length;
|
|
258
|
-
this.__virtualizer.flush();
|
|
259
|
-
this.requestContentUpdate();
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/** @private */
|
|
264
|
-
__loadingChanged() {
|
|
265
|
-
this.requestContentUpdate();
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/** @private */
|
|
269
|
-
__selectedItemChanged() {
|
|
270
|
-
this.requestContentUpdate();
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/** @private */
|
|
274
|
-
__focusedIndexChanged(index, oldIndex) {
|
|
275
|
-
if (index !== oldIndex) {
|
|
276
|
-
this.requestContentUpdate();
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// Do not jump back to the previously focused item while loading
|
|
280
|
-
// when requesting next page from the data provider on scroll.
|
|
281
|
-
if (index >= 0 && !this.loading) {
|
|
282
|
-
this.scrollIntoView(index);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/** @private */
|
|
287
|
-
__rendererChanged(renderer, oldRenderer) {
|
|
288
|
-
if (renderer || oldRenderer) {
|
|
289
|
-
this.requestContentUpdate();
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/** @private */
|
|
294
|
-
__createElements(count) {
|
|
295
|
-
return [...Array(count)].map(() => {
|
|
296
|
-
const item = document.createElement(`${this.__hostTagName}-item`);
|
|
297
|
-
item.addEventListener('click', this.__boundOnItemClick);
|
|
298
|
-
// Negative tabindex prevents the item content from being focused.
|
|
299
|
-
item.tabIndex = '-1';
|
|
300
|
-
item.style.width = '100%';
|
|
301
|
-
return item;
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/** @private */
|
|
306
|
-
__updateElement(el, index) {
|
|
307
|
-
const item = this.items[index];
|
|
308
|
-
const focusedIndex = this.focusedIndex;
|
|
309
|
-
|
|
310
|
-
el.setProperties({
|
|
311
|
-
item,
|
|
312
|
-
index,
|
|
313
|
-
label: this.getItemLabel(item),
|
|
314
|
-
selected: this.__isItemSelected(item, this.selectedItem, this.itemIdPath),
|
|
315
|
-
renderer: this.renderer,
|
|
316
|
-
focused: this.__isItemFocused(focusedIndex, index),
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
el.id = `${this.__hostTagName}-item-${index}`;
|
|
320
|
-
el.setAttribute('role', this.__getAriaRole(index));
|
|
321
|
-
el.setAttribute('aria-selected', this.__getAriaSelected(focusedIndex, index));
|
|
322
|
-
el.setAttribute('aria-posinset', index + 1);
|
|
323
|
-
el.setAttribute('aria-setsize', this.items.length);
|
|
324
|
-
|
|
325
|
-
if (this.theme) {
|
|
326
|
-
el.setAttribute('theme', this.theme);
|
|
327
|
-
} else {
|
|
328
|
-
el.removeAttribute('theme');
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (item instanceof ComboBoxPlaceholder) {
|
|
332
|
-
this.__requestItemByIndex(index);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/** @private */
|
|
337
|
-
__onItemClick(e) {
|
|
338
|
-
this.dispatchEvent(new CustomEvent('selection-changed', { detail: { item: e.currentTarget.item } }));
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* We want to prevent the kinetic scrolling energy from being transferred from the overlay contents over to the parent.
|
|
343
|
-
* Further improvement ideas: after the contents have been scrolled to the top or bottom and scrolling has stopped, it could allow
|
|
344
|
-
* scrolling the parent similarly to touch scrolling.
|
|
345
|
-
*/
|
|
346
|
-
__patchWheelOverScrolling() {
|
|
347
|
-
this.$.selector.addEventListener('wheel', (e) => {
|
|
348
|
-
const scrolledToTop = this.scrollTop === 0;
|
|
349
|
-
const scrolledToBottom = this.scrollHeight - this.scrollTop - this.clientHeight <= 1;
|
|
350
|
-
if (scrolledToTop && e.deltaY < 0) {
|
|
351
|
-
e.preventDefault();
|
|
352
|
-
} else if (scrolledToBottom && e.deltaY > 0) {
|
|
353
|
-
e.preventDefault();
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Dispatches an `index-requested` event for the given index to notify
|
|
360
|
-
* the data provider that it should start loading the page containing the requested index.
|
|
361
|
-
*
|
|
362
|
-
* The event is dispatched asynchronously to prevent an immediate page request and therefore
|
|
363
|
-
* a possible infinite recursion in case the data provider implements page request cancelation logic
|
|
364
|
-
* by invoking data provider page callbacks with an empty array.
|
|
365
|
-
* The infinite recursion may occur otherwise since invoking a data provider page callback with an empty array
|
|
366
|
-
* triggers a synchronous scroller update and, if the callback corresponds to the currently visible page,
|
|
367
|
-
* the scroller will synchronously request the page again which may lead to looping in the end.
|
|
368
|
-
* That was the case for the Flow counterpart:
|
|
369
|
-
* https://github.com/vaadin/flow-components/issues/3553#issuecomment-1239344828
|
|
370
|
-
*/
|
|
371
|
-
__requestItemByIndex(index) {
|
|
372
|
-
requestAnimationFrame(() => {
|
|
373
|
-
this.dispatchEvent(
|
|
374
|
-
new CustomEvent('index-requested', {
|
|
375
|
-
detail: {
|
|
376
|
-
index,
|
|
377
|
-
currentScrollerPos: this._oldScrollerPosition,
|
|
378
|
-
},
|
|
379
|
-
}),
|
|
380
|
-
);
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/** @private */
|
|
385
|
-
_visibleItemsCount() {
|
|
386
|
-
// Ensure items are positioned
|
|
387
|
-
this.__virtualizer.scrollToIndex(this.__virtualizer.firstVisibleIndex);
|
|
388
|
-
const hasItems = this.__virtualizer.size > 0;
|
|
389
|
-
return hasItems ? this.__virtualizer.lastVisibleIndex - this.__virtualizer.firstVisibleIndex + 1 : 0;
|
|
390
|
-
}
|
|
391
50
|
}
|
|
392
51
|
|
|
393
52
|
customElements.define(ComboBoxScroller.is, ComboBoxScroller);
|
package/theme/lumo/{vaadin-combo-box-dropdown-styles.js → vaadin-combo-box-overlay-styles.js}
RENAMED
|
@@ -12,14 +12,6 @@ const comboBoxOverlay = css`
|
|
|
12
12
|
padding: 0;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
:host {
|
|
16
|
-
--_vaadin-combo-box-items-container-border-width: var(--lumo-space-xs);
|
|
17
|
-
--_vaadin-combo-box-items-container-border-style: solid;
|
|
18
|
-
--_vaadin-combo-box-items-container-border-color: transparent;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/* Loading state */
|
|
22
|
-
|
|
23
15
|
/* When items are empty, the spinner needs some room */
|
|
24
16
|
:host(:not([closing])) [part~='content'] {
|
|
25
17
|
min-height: calc(2 * var(--lumo-space-s) + var(--lumo-icon-size-s));
|
|
@@ -36,7 +28,9 @@ const comboBoxOverlay = css`
|
|
|
36
28
|
:host([bottom-aligned]) [part~='overlay'] {
|
|
37
29
|
margin-bottom: var(--lumo-space-xs);
|
|
38
30
|
}
|
|
31
|
+
`;
|
|
39
32
|
|
|
33
|
+
const comboBoxLoader = css`
|
|
40
34
|
[part~='loader'] {
|
|
41
35
|
position: absolute;
|
|
42
36
|
z-index: 1;
|
|
@@ -48,8 +42,6 @@ const comboBoxOverlay = css`
|
|
|
48
42
|
margin-inline-end: 0;
|
|
49
43
|
}
|
|
50
44
|
|
|
51
|
-
/* RTL specific styles */
|
|
52
|
-
|
|
53
45
|
:host([dir='rtl']) [part~='loader'] {
|
|
54
46
|
left: auto;
|
|
55
47
|
margin-left: 0;
|
|
@@ -59,6 +51,22 @@ const comboBoxOverlay = css`
|
|
|
59
51
|
}
|
|
60
52
|
`;
|
|
61
53
|
|
|
62
|
-
registerStyles(
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
registerStyles(
|
|
55
|
+
'vaadin-combo-box-overlay',
|
|
56
|
+
[
|
|
57
|
+
overlay,
|
|
58
|
+
menuOverlayCore,
|
|
59
|
+
comboBoxOverlay,
|
|
60
|
+
loader,
|
|
61
|
+
comboBoxLoader,
|
|
62
|
+
css`
|
|
63
|
+
:host {
|
|
64
|
+
--_vaadin-combo-box-items-container-border-width: var(--lumo-space-xs);
|
|
65
|
+
--_vaadin-combo-box-items-container-border-style: solid;
|
|
66
|
+
}
|
|
67
|
+
`,
|
|
68
|
+
],
|
|
69
|
+
{ moduleId: 'lumo-combo-box-overlay' },
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
export { comboBoxLoader, comboBoxOverlay };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@vaadin/input-container/theme/lumo/vaadin-input-container.js';
|
|
2
|
-
import './vaadin-combo-box-dropdown-styles.js';
|
|
3
2
|
import './vaadin-combo-box-item-styles.js';
|
|
3
|
+
import './vaadin-combo-box-overlay-styles.js';
|
|
4
4
|
import './vaadin-combo-box-styles.js';
|
|
5
5
|
import '../../src/vaadin-combo-box.js';
|
package/theme/material/{vaadin-combo-box-dropdown-styles.js → vaadin-combo-box-overlay-styles.js}
RENAMED
|
@@ -5,12 +5,6 @@ import { menuOverlay } from '@vaadin/vaadin-material-styles/mixins/menu-overlay.
|
|
|
5
5
|
import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
6
6
|
|
|
7
7
|
const comboBoxOverlay = css`
|
|
8
|
-
:host {
|
|
9
|
-
--_vaadin-combo-box-items-container-border-width: 8px 0;
|
|
10
|
-
--_vaadin-combo-box-items-container-border-style: solid;
|
|
11
|
-
--_vaadin-combo-box-items-container-border-color: transparent;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
8
|
[part='overlay'] {
|
|
15
9
|
position: relative;
|
|
16
10
|
overflow: visible;
|
|
@@ -21,7 +15,9 @@ const comboBoxOverlay = css`
|
|
|
21
15
|
[part='content'] {
|
|
22
16
|
padding: 0;
|
|
23
17
|
}
|
|
18
|
+
`;
|
|
24
19
|
|
|
20
|
+
const comboBoxLoader = css`
|
|
25
21
|
[part~='loader'] {
|
|
26
22
|
position: absolute;
|
|
27
23
|
z-index: 1;
|
|
@@ -31,6 +27,21 @@ const comboBoxOverlay = css`
|
|
|
31
27
|
}
|
|
32
28
|
`;
|
|
33
29
|
|
|
34
|
-
registerStyles(
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
registerStyles(
|
|
31
|
+
'vaadin-combo-box-overlay',
|
|
32
|
+
[
|
|
33
|
+
menuOverlay,
|
|
34
|
+
comboBoxOverlay,
|
|
35
|
+
loader,
|
|
36
|
+
comboBoxLoader,
|
|
37
|
+
css`
|
|
38
|
+
:host {
|
|
39
|
+
--_vaadin-combo-box-items-container-border-width: 8px 0;
|
|
40
|
+
--_vaadin-combo-box-items-container-border-style: solid;
|
|
41
|
+
}
|
|
42
|
+
`,
|
|
43
|
+
],
|
|
44
|
+
{ moduleId: 'material-combo-box-overlay' },
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
export { comboBoxLoader, comboBoxOverlay };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@vaadin/input-container/theme/material/vaadin-input-container.js';
|
|
2
|
-
import './vaadin-combo-box-dropdown-styles.js';
|
|
3
2
|
import './vaadin-combo-box-item-styles.js';
|
|
3
|
+
import './vaadin-combo-box-overlay-styles.js';
|
|
4
4
|
import './vaadin-combo-box-styles.js';
|
|
5
5
|
import '../../src/vaadin-combo-box.js';
|
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.0.0-
|
|
4
|
+
"version": "24.0.0-alpha13",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"contributions": {
|
|
7
7
|
"html": {
|
|
@@ -460,7 +460,7 @@
|
|
|
460
460
|
},
|
|
461
461
|
{
|
|
462
462
|
"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.0.0-
|
|
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.0.0-alpha13/#/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.0.0-alpha13/#/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.0.0-alpha13/#/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.0.0-alpha13/#/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.0.0-alpha13/#/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.0.0-alpha13/#/elements/vaadin-overlay).\n- `<vaadin-combo-box-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.0.0-alpha13/#/elements/vaadin-item).\n- [`<vaadin-input-container>`](https://cdn.vaadin.com/vaadin-web-components/24.0.0-alpha13/#/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/custom-theme/styling-components) documentation.",
|
|
464
464
|
"attributes": [
|
|
465
465
|
{
|
|
466
466
|
"name": "disabled",
|
package/web-types.lit.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.0.0-
|
|
4
|
+
"version": "24.0.0-alpha13",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"framework": "lit",
|
|
7
7
|
"framework-config": {
|
|
@@ -247,7 +247,7 @@
|
|
|
247
247
|
},
|
|
248
248
|
{
|
|
249
249
|
"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.0.0-
|
|
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.0.0-alpha13/#/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.0.0-alpha13/#/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.0.0-alpha13/#/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.0.0-alpha13/#/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.0.0-alpha13/#/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.0.0-alpha13/#/elements/vaadin-overlay).\n- `<vaadin-combo-box-item>` - has the same API as [`<vaadin-item>`](https://cdn.vaadin.com/vaadin-web-components/24.0.0-alpha13/#/elements/vaadin-item).\n- [`<vaadin-input-container>`](https://cdn.vaadin.com/vaadin-web-components/24.0.0-alpha13/#/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/custom-theme/styling-components) documentation.",
|
|
251
251
|
"extension": true,
|
|
252
252
|
"attributes": [
|
|
253
253
|
{
|