@vaadin/combo-box 23.1.0-beta1 → 23.1.0-beta4
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/lit.d.ts +1 -0
- package/lit.js +1 -0
- package/package.json +16 -13
- package/src/lit/renderer-directives.d.ts +63 -0
- package/src/lit/renderer-directives.js +60 -0
- package/src/vaadin-combo-box-data-provider-mixin.js +1 -1
- package/src/vaadin-combo-box-dropdown.js +2 -2
- package/src/vaadin-combo-box-light.js +1 -1
- package/src/vaadin-combo-box-mixin.js +10 -9
- package/src/vaadin-combo-box-scroller.js +3 -1
package/lit.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/lit/renderer-directives.js';
|
package/lit.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/lit/renderer-directives.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/combo-box",
|
|
3
|
-
"version": "23.1.0-
|
|
3
|
+
"version": "23.1.0-beta4",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"src",
|
|
23
23
|
"theme",
|
|
24
|
+
"lit.js",
|
|
25
|
+
"lit.d.ts",
|
|
24
26
|
"vaadin-*.d.ts",
|
|
25
27
|
"vaadin-*.js"
|
|
26
28
|
],
|
|
@@ -34,23 +36,24 @@
|
|
|
34
36
|
"dependencies": {
|
|
35
37
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
36
38
|
"@polymer/polymer": "^3.0.0",
|
|
37
|
-
"@vaadin/component-base": "23.1.0-
|
|
38
|
-
"@vaadin/field-base": "23.1.0-
|
|
39
|
-
"@vaadin/input-container": "23.1.0-
|
|
40
|
-
"@vaadin/item": "23.1.0-
|
|
41
|
-
"@vaadin/
|
|
42
|
-
"@vaadin/vaadin-
|
|
43
|
-
"@vaadin/vaadin-
|
|
44
|
-
"@vaadin/vaadin-
|
|
39
|
+
"@vaadin/component-base": "23.1.0-beta4",
|
|
40
|
+
"@vaadin/field-base": "23.1.0-beta4",
|
|
41
|
+
"@vaadin/input-container": "23.1.0-beta4",
|
|
42
|
+
"@vaadin/item": "23.1.0-beta4",
|
|
43
|
+
"@vaadin/lit-renderer": "23.1.0-beta4",
|
|
44
|
+
"@vaadin/vaadin-lumo-styles": "23.1.0-beta4",
|
|
45
|
+
"@vaadin/vaadin-material-styles": "23.1.0-beta4",
|
|
46
|
+
"@vaadin/vaadin-overlay": "23.1.0-beta4",
|
|
47
|
+
"@vaadin/vaadin-themable-mixin": "23.1.0-beta4"
|
|
45
48
|
},
|
|
46
49
|
"devDependencies": {
|
|
47
50
|
"@esm-bundle/chai": "^4.3.4",
|
|
48
|
-
"@vaadin/dialog": "23.1.0-
|
|
49
|
-
"@vaadin/polymer-legacy-adapter": "23.1.0-
|
|
51
|
+
"@vaadin/dialog": "23.1.0-beta4",
|
|
52
|
+
"@vaadin/polymer-legacy-adapter": "23.1.0-beta4",
|
|
50
53
|
"@vaadin/testing-helpers": "^0.3.2",
|
|
51
|
-
"@vaadin/text-field": "23.1.0-
|
|
54
|
+
"@vaadin/text-field": "23.1.0-beta4",
|
|
52
55
|
"lit": "^2.0.0",
|
|
53
56
|
"sinon": "^13.0.2"
|
|
54
57
|
},
|
|
55
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "06e283473964ecb3085aacf3eddb5333d052a045"
|
|
56
59
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2017 - 2022 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { TemplateResult } from 'lit';
|
|
7
|
+
import { DirectiveResult } from 'lit/directive.js';
|
|
8
|
+
import { LitRendererDirective } from '@vaadin/lit-renderer';
|
|
9
|
+
import { ComboBox, ComboBoxItemModel } from '../vaadin-combo-box.js';
|
|
10
|
+
|
|
11
|
+
export type ComboBoxLitRenderer<TItem> = (
|
|
12
|
+
item: TItem,
|
|
13
|
+
model: ComboBoxItemModel<TItem>,
|
|
14
|
+
comboBox: ComboBox<TItem>,
|
|
15
|
+
) => TemplateResult;
|
|
16
|
+
|
|
17
|
+
export class ComboBoxRendererDirective<TItem> extends LitRendererDirective<ComboBox, ComboBoxLitRenderer<TItem>> {
|
|
18
|
+
/**
|
|
19
|
+
* Adds the renderer callback to the combo-box.
|
|
20
|
+
*/
|
|
21
|
+
addRenderer(): void;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Runs the renderer callback on the combo-box.
|
|
25
|
+
*/
|
|
26
|
+
runRenderer(): void;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Removes the renderer callback from the combo-box.
|
|
30
|
+
*/
|
|
31
|
+
removeRenderer(): void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A Lit directive for rendering the content of the `<vaadin-combo-box-item>` elements.
|
|
36
|
+
*
|
|
37
|
+
* The directive accepts a renderer callback returning a Lit template and assigns it to the combo-box
|
|
38
|
+
* via the `renderer` property. The renderer is called for each combo-box item when assigned
|
|
39
|
+
* and whenever a single dependency or an array of dependencies changes.
|
|
40
|
+
* It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
|
|
41
|
+
*
|
|
42
|
+
* Dependencies can be a single value or an array of values.
|
|
43
|
+
* Values are checked against previous values with strict equality (`===`),
|
|
44
|
+
* so the check won't detect nested property changes inside objects or arrays.
|
|
45
|
+
* When dependencies are provided as an array, each item is checked against the previous value
|
|
46
|
+
* at the same index with strict equality. Nested arrays are also checked only by strict
|
|
47
|
+
* equality.
|
|
48
|
+
*
|
|
49
|
+
* Example of usage:
|
|
50
|
+
* ```js
|
|
51
|
+
* `<vaadin-combo-box
|
|
52
|
+
* ${comboBoxRenderer((item, model, comboBox) => html`...`)}
|
|
53
|
+
* ></vaadin-combo-box>`
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @param renderer the renderer callback that returns a Lit template.
|
|
57
|
+
* @param dependencies a single dependency or an array of dependencies
|
|
58
|
+
* which trigger a re-render when changed.
|
|
59
|
+
*/
|
|
60
|
+
export declare function comboBoxRenderer<TItem>(
|
|
61
|
+
renderer: ComboBoxLitRenderer<TItem>,
|
|
62
|
+
dependencies?: unknown,
|
|
63
|
+
): DirectiveResult<typeof ComboBoxRendererDirective>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2017 - 2022 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { directive } from 'lit/directive.js';
|
|
7
|
+
import { LitRendererDirective } from '@vaadin/lit-renderer';
|
|
8
|
+
|
|
9
|
+
export class ComboBoxRendererDirective extends LitRendererDirective {
|
|
10
|
+
/**
|
|
11
|
+
* Adds the renderer callback to the combo-box.
|
|
12
|
+
*/
|
|
13
|
+
addRenderer() {
|
|
14
|
+
this.element.renderer = (root, comboBox, model) => {
|
|
15
|
+
this.renderRenderer(root, model.item, model, comboBox);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Runs the renderer callback on the combo-box.
|
|
21
|
+
*/
|
|
22
|
+
runRenderer() {
|
|
23
|
+
this.element.requestContentUpdate();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Removes the renderer callback from the combo-box.
|
|
28
|
+
*/
|
|
29
|
+
removeRenderer() {
|
|
30
|
+
this.element.renderer = null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A Lit directive for rendering the content of the `<vaadin-combo-box-item>` elements.
|
|
36
|
+
*
|
|
37
|
+
* The directive accepts a renderer callback returning a Lit template and assigns it to the combo-box
|
|
38
|
+
* via the `renderer` property. The renderer is called for each combo-box item when assigned
|
|
39
|
+
* and whenever a single dependency or an array of dependencies changes.
|
|
40
|
+
* It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
|
|
41
|
+
*
|
|
42
|
+
* Dependencies can be a single value or an array of values.
|
|
43
|
+
* Values are checked against previous values with strict equality (`===`),
|
|
44
|
+
* so the check won't detect nested property changes inside objects or arrays.
|
|
45
|
+
* When dependencies are provided as an array, each item is checked against the previous value
|
|
46
|
+
* at the same index with strict equality. Nested arrays are also checked only by strict
|
|
47
|
+
* equality.
|
|
48
|
+
*
|
|
49
|
+
* Example of usage:
|
|
50
|
+
* ```js
|
|
51
|
+
* `<vaadin-combo-box
|
|
52
|
+
* ${comboBoxRenderer((item, model, comboBox) => html`...`)}
|
|
53
|
+
* ></vaadin-combo-box>`
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @param renderer the renderer callback that returns a Lit template.
|
|
57
|
+
* @param dependencies a single dependency or an array of dependencies
|
|
58
|
+
* which trigger a re-render when changed.
|
|
59
|
+
*/
|
|
60
|
+
export const comboBoxRenderer = directive(ComboBoxRendererDirective);
|
|
@@ -164,7 +164,7 @@ export const ComboBoxDataProviderMixin = (superClass) =>
|
|
|
164
164
|
|
|
165
165
|
/** @private */
|
|
166
166
|
_loadPage(page) {
|
|
167
|
-
//
|
|
167
|
+
// Make sure same page isn't requested multiple times.
|
|
168
168
|
if (!this._pendingRequests[page] && this.dataProvider) {
|
|
169
169
|
this.loading = true;
|
|
170
170
|
|
|
@@ -174,7 +174,7 @@ export class ComboBoxDropdown extends PolymerElement {
|
|
|
174
174
|
_fireTouchAction(sourceEvent) {
|
|
175
175
|
this.dispatchEvent(
|
|
176
176
|
new CustomEvent('vaadin-overlay-touch-action', {
|
|
177
|
-
detail: { sourceEvent
|
|
177
|
+
detail: { sourceEvent },
|
|
178
178
|
}),
|
|
179
179
|
);
|
|
180
180
|
}
|
|
@@ -275,7 +275,7 @@ export class ComboBoxDropdown extends PolymerElement {
|
|
|
275
275
|
}
|
|
276
276
|
|
|
277
277
|
_positionTargetChanged(target) {
|
|
278
|
-
//
|
|
278
|
+
// We must update the overlay width when the positionTarget is set (or changes)
|
|
279
279
|
if (target) {
|
|
280
280
|
this._setOverlayWidth();
|
|
281
281
|
}
|
|
@@ -151,7 +151,7 @@ class ComboBoxLight extends ComboBoxDataProviderMixin(ComboBoxMixin(ThemableMixi
|
|
|
151
151
|
_isClearButton(event) {
|
|
152
152
|
return (
|
|
153
153
|
super._isClearButton(event) ||
|
|
154
|
-
(event.type === 'input' && !event.isTrusted) || //
|
|
154
|
+
(event.type === 'input' && !event.isTrusted) || // Fake input event dispatched by clear button
|
|
155
155
|
event.composedPath()[0].getAttribute('part') === 'clear-button'
|
|
156
156
|
);
|
|
157
157
|
}
|
|
@@ -469,14 +469,14 @@ export const ComboBoxMixin = (subclass) =>
|
|
|
469
469
|
this._onArrowDown();
|
|
470
470
|
this._closeOnBlurIsPrevented = false;
|
|
471
471
|
|
|
472
|
-
//
|
|
472
|
+
// Prevent caret from moving
|
|
473
473
|
e.preventDefault();
|
|
474
474
|
} else if (e.key === 'ArrowUp') {
|
|
475
475
|
this._closeOnBlurIsPrevented = true;
|
|
476
476
|
this._onArrowUp();
|
|
477
477
|
this._closeOnBlurIsPrevented = false;
|
|
478
478
|
|
|
479
|
-
//
|
|
479
|
+
// Prevent caret from moving
|
|
480
480
|
e.preventDefault();
|
|
481
481
|
} else if (e.key === 'Enter') {
|
|
482
482
|
this._onEnter(e);
|
|
@@ -576,7 +576,7 @@ export const ComboBoxMixin = (subclass) =>
|
|
|
576
576
|
|
|
577
577
|
/** @private */
|
|
578
578
|
_onEnter(e) {
|
|
579
|
-
//
|
|
579
|
+
// Do not commit value when custom values are disallowed and input value is not a valid option
|
|
580
580
|
// also stop propagation of the event, otherwise the user could submit a form while the input
|
|
581
581
|
// still contains an invalid value
|
|
582
582
|
if (!this.allowCustomValue && this._inputElementValue !== '' && this._focusedIndex < 0) {
|
|
@@ -587,7 +587,7 @@ export const ComboBoxMixin = (subclass) =>
|
|
|
587
587
|
return;
|
|
588
588
|
}
|
|
589
589
|
|
|
590
|
-
//
|
|
590
|
+
// Stop propagation of the enter event only if the dropdown is opened, this
|
|
591
591
|
// "consumes" the enter event for the action of closing the dropdown
|
|
592
592
|
if (this.opened) {
|
|
593
593
|
// Do not submit the surrounding form.
|
|
@@ -704,7 +704,7 @@ export const ComboBoxMixin = (subclass) =>
|
|
|
704
704
|
if (this.selectedItem !== focusedItem) {
|
|
705
705
|
this.selectedItem = focusedItem;
|
|
706
706
|
}
|
|
707
|
-
//
|
|
707
|
+
// Make sure input field is updated in case value doesn't change (i.e. FOO -> foo)
|
|
708
708
|
this._inputElementValue = this._getItemLabel(this.selectedItem);
|
|
709
709
|
} else if (this._inputElementValue === '' || this._inputElementValue === undefined) {
|
|
710
710
|
this.selectedItem = null;
|
|
@@ -723,7 +723,7 @@ export const ComboBoxMixin = (subclass) =>
|
|
|
723
723
|
|
|
724
724
|
if (
|
|
725
725
|
this.allowCustomValue &&
|
|
726
|
-
//
|
|
726
|
+
// To prevent a repetitive input value being saved after pressing ESC and Tab.
|
|
727
727
|
!itemMatchingByLabel
|
|
728
728
|
) {
|
|
729
729
|
const customValue = this._inputElementValue;
|
|
@@ -971,10 +971,11 @@ export const ComboBoxMixin = (subclass) =>
|
|
|
971
971
|
this._selectItemForValue(this.value);
|
|
972
972
|
}
|
|
973
973
|
|
|
974
|
-
|
|
974
|
+
const inputValue = this._inputElementValue;
|
|
975
|
+
if (inputValue === undefined || inputValue === this._getItemLabel(this.selectedItem)) {
|
|
975
976
|
// When the input element value is the same as the current value or not defined,
|
|
976
977
|
// set the focused index to the item that matches the value.
|
|
977
|
-
this._focusedIndex = this.
|
|
978
|
+
this._focusedIndex = this.$.dropdown.indexOfLabel(this._getItemLabel(this.selectedItem));
|
|
978
979
|
} else {
|
|
979
980
|
// When the user filled in something that is different from the current value = filtering is enabled,
|
|
980
981
|
// set the focused index to the item that matches the filter query.
|
|
@@ -1056,7 +1057,7 @@ export const ComboBoxMixin = (subclass) =>
|
|
|
1056
1057
|
|
|
1057
1058
|
/** @private */
|
|
1058
1059
|
_overlaySelectedItemChanged(e) {
|
|
1059
|
-
//
|
|
1060
|
+
// Stop this private event from leaking outside.
|
|
1060
1061
|
e.stopPropagation();
|
|
1061
1062
|
|
|
1062
1063
|
if (e.detail.item instanceof ComboBoxPlaceholder) {
|
|
@@ -259,7 +259,9 @@ export class ComboBoxScroller extends PolymerElement {
|
|
|
259
259
|
this.requestContentUpdate();
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
|
|
262
|
+
// Do not jump back to the previously focused item while loading
|
|
263
|
+
// when requesting next page from the data provider on scroll.
|
|
264
|
+
if (index >= 0 && !this.loading) {
|
|
263
265
|
this.scrollIntoView(index);
|
|
264
266
|
}
|
|
265
267
|
}
|