@vaadin/combo-box 22.0.0-beta2 → 22.0.2

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": "22.0.0-beta2",
3
+ "version": "22.0.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -34,23 +34,23 @@
34
34
  "@open-wc/dedupe-mixin": "^1.3.0",
35
35
  "@polymer/iron-resizable-behavior": "^3.0.0",
36
36
  "@polymer/polymer": "^3.0.0",
37
- "@vaadin/component-base": "22.0.0-beta2",
38
- "@vaadin/field-base": "22.0.0-beta2",
39
- "@vaadin/input-container": "22.0.0-beta2",
40
- "@vaadin/item": "22.0.0-beta2",
41
- "@vaadin/vaadin-lumo-styles": "22.0.0-beta2",
42
- "@vaadin/vaadin-material-styles": "22.0.0-beta2",
43
- "@vaadin/vaadin-overlay": "22.0.0-beta2",
44
- "@vaadin/vaadin-themable-mixin": "22.0.0-beta2"
37
+ "@vaadin/component-base": "^22.0.2",
38
+ "@vaadin/field-base": "^22.0.2",
39
+ "@vaadin/input-container": "^22.0.2",
40
+ "@vaadin/item": "^22.0.2",
41
+ "@vaadin/vaadin-lumo-styles": "^22.0.2",
42
+ "@vaadin/vaadin-material-styles": "^22.0.2",
43
+ "@vaadin/vaadin-overlay": "^22.0.2",
44
+ "@vaadin/vaadin-themable-mixin": "^22.0.2"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@esm-bundle/chai": "^4.3.4",
48
- "@vaadin/dialog": "22.0.0-beta2",
49
- "@vaadin/polymer-legacy-adapter": "22.0.0-beta2",
50
- "@vaadin/testing-helpers": "^0.3.0",
51
- "@vaadin/text-field": "22.0.0-beta2",
48
+ "@vaadin/dialog": "^22.0.2",
49
+ "@vaadin/polymer-legacy-adapter": "^22.0.2",
50
+ "@vaadin/testing-helpers": "^0.3.2",
51
+ "@vaadin/text-field": "^22.0.2",
52
52
  "lit": "^2.0.0",
53
53
  "sinon": "^9.2.0"
54
54
  },
55
- "gitHead": "f13833683e6667f6ca6678452db14aa6b7eac4a4"
55
+ "gitHead": "df21370c4a655a38eac11f79686021ab3b0887ad"
56
56
  }
@@ -10,15 +10,6 @@ import { IronResizableBehavior } from '@polymer/iron-resizable-behavior/iron-res
10
10
  import { mixinBehaviors } from '@polymer/polymer/lib/legacy/class.js';
11
11
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
12
12
 
13
- const TOUCH_DEVICE = (() => {
14
- try {
15
- document.createEvent('TouchEvent');
16
- return true;
17
- } catch (e) {
18
- return false;
19
- }
20
- })();
21
-
22
13
  /**
23
14
  * Element for internal use only.
24
15
  *
@@ -47,13 +38,9 @@ export class ComboBoxDropdown extends mixinBehaviors(IronResizableBehavior, Poly
47
38
  static get properties() {
48
39
  return {
49
40
  /**
50
- * True if the device supports touch events.
41
+ * True if the combo-box has been activate by the user.
42
+ * The actual opened state depends on whether the dropdown has items.
51
43
  */
52
- touchDevice: {
53
- type: Boolean,
54
- value: TOUCH_DEVICE
55
- },
56
-
57
44
  opened: Boolean,
58
45
 
59
46
  /**
@@ -3,6 +3,9 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
7
+ import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
8
+ import { InputMixinClass } from '@vaadin/field-base/src/input-mixin.js';
6
9
  import { ThemableMixinClass } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
7
10
  import { ComboBoxDataProviderMixinClass } from './vaadin-combo-box-data-provider-mixin.js';
8
11
  import { ComboBoxMixinClass } from './vaadin-combo-box-mixin.js';
@@ -127,6 +130,9 @@ declare class ComboBoxLight<TItem = ComboBoxDefaultItem> extends HTMLElement {
127
130
  interface ComboBoxLight<TItem = ComboBoxDefaultItem>
128
131
  extends ComboBoxDataProviderMixinClass<TItem>,
129
132
  ComboBoxMixinClass<TItem>,
133
+ KeyboardMixinClass,
134
+ InputMixinClass,
135
+ DisabledMixinClass,
130
136
  ThemableMixinClass {}
131
137
 
132
138
  declare global {
@@ -3,6 +3,7 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { isTouch } from '@vaadin/component-base/src/browser-utils.js';
6
7
  import { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js';
7
8
  import { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js';
8
9
  import { processTemplates } from '@vaadin/component-base/src/templates.js';
@@ -360,7 +361,7 @@ export const ComboBoxMixin = (subclass) =>
360
361
  this._openedWithFocusRing = this.hasAttribute('focus-ring');
361
362
  // For touch devices, we don't want to popup virtual keyboard
362
363
  // unless input element is explicitly focused by the user.
363
- if (!this.hasAttribute('focused') && !this.$.dropdown.touchDevice) {
364
+ if (!this.hasAttribute('focused') && !isTouch) {
364
365
  this.focus();
365
366
  }
366
367
  } else {
@@ -569,11 +570,14 @@ export const ComboBoxMixin = (subclass) =>
569
570
  _onEscape(e) {
570
571
  if (this.autoOpenDisabled) {
571
572
  // Auto-open is disabled
572
- if (this.value !== this._inputElementValue) {
573
+ if (this.opened || (this.value !== this._inputElementValue && this._inputElementValue.length > 0)) {
574
+ // The overlay is open or
573
575
  // The input value has changed but the change hasn't been committed, so cancel it.
576
+ e.stopPropagation();
574
577
  this._focusedIndex = -1;
575
578
  this.cancel();
576
- } else if (this.clearButtonVisible && !this.opened) {
579
+ } else if (this.clearButtonVisible && !this.opened && !!this.value) {
580
+ e.stopPropagation();
577
581
  // The clear button is visible and the overlay is closed, so clear the value.
578
582
  this._clear();
579
583
  }
@@ -591,7 +595,8 @@ export const ComboBoxMixin = (subclass) =>
591
595
  // No item is focused, cancel the change and close the overlay
592
596
  this.cancel();
593
597
  }
594
- } else if (this.clearButtonVisible) {
598
+ } else if (this.clearButtonVisible && !!this.value) {
599
+ e.stopPropagation();
595
600
  // The clear button is visible and the overlay is closed, so clear the value.
596
601
  this._clear();
597
602
  }
@@ -605,7 +610,7 @@ export const ComboBoxMixin = (subclass) =>
605
610
  toggleElement.addEventListener('mousedown', (e) => e.preventDefault());
606
611
  // Unfocus previously focused element if focus is not inside combo box (on touch devices)
607
612
  toggleElement.addEventListener('click', () => {
608
- if (this.$.dropdown.touchDevice && !this.hasAttribute('focused')) {
613
+ if (isTouch && !this.hasAttribute('focused')) {
609
614
  document.activeElement.blur();
610
615
  }
611
616
  });
@@ -3,9 +3,20 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
7
+ import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
6
8
  import { ElementMixinClass } from '@vaadin/component-base/src/element-mixin.js';
9
+ import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
10
+ import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
11
+ import { DelegateFocusMixinClass } from '@vaadin/field-base/src/delegate-focus-mixin.js';
12
+ import { DelegateStateMixinClass } from '@vaadin/field-base/src/delegate-state-mixin.js';
13
+ import { FieldMixinClass } from '@vaadin/field-base/src/field-mixin.js';
14
+ import { InputConstraintsMixinClass } from '@vaadin/field-base/src/input-constraints-mixin.js';
7
15
  import { InputControlMixinClass } from '@vaadin/field-base/src/input-control-mixin.js';
16
+ import { InputMixinClass } from '@vaadin/field-base/src/input-mixin.js';
17
+ import { LabelMixinClass } from '@vaadin/field-base/src/label-mixin.js';
8
18
  import { PatternMixinClass } from '@vaadin/field-base/src/pattern-mixin.js';
19
+ import { ValidateMixinClass } from '@vaadin/field-base/src/validate-mixin.js';
9
20
  import { ThemableMixinClass } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10
21
  import { ComboBoxDataProviderMixinClass } from './vaadin-combo-box-data-provider-mixin.js';
11
22
  import { ComboBoxMixinClass } from './vaadin-combo-box-mixin.js';
@@ -62,77 +73,60 @@ export interface ComboBoxEventMap<TItem> extends HTMLElementEventMap {
62
73
  }
63
74
 
64
75
  /**
65
- * `<vaadin-combo-box>` is a combo box element combining a dropdown list with an
66
- * input field for filtering the list of items. If you want to replace the default
67
- * input field with a custom implementation, you should use the
68
- * [`<vaadin-combo-box-light>`](#/elements/vaadin-combo-box-light) element.
69
- *
70
- * Items in the dropdown list must be provided as a list of `String` values.
71
- * Defining the items is done using the `items` property, which can be assigned
72
- * with data-binding, using an attribute or directly with the JavaScript property.
76
+ * `<vaadin-combo-box>` is a web component for choosing a value from a filterable list of options
77
+ * presented in a dropdown overlay. The options can be provided as a list of strings or objects
78
+ * by setting [`items`](#/elements/vaadin-combo-box#property-items) property on the element.
73
79
  *
74
80
  * ```html
75
- * <vaadin-combo-box
76
- * label="Fruit"
77
- * items="[[data]]">
78
- * </vaadin-combo-box>
81
+ * <vaadin-combo-box id="combo-box"></vaadin-combo-box>
79
82
  * ```
80
83
  *
81
84
  * ```js
82
- * combobox.items = ['apple', 'orange', 'banana'];
85
+ * document.querySelector('#combo-box').items = ['apple', 'orange', 'banana'];
83
86
  * ```
84
87
  *
85
88
  * When the selected `value` is changed, a `value-changed` event is triggered.
86
89
  *
87
90
  * ### Item rendering
88
91
  *
89
- * `<vaadin-combo-box>` supports using custom renderer callback function for defining the
90
- * content of `<vaadin-combo-box-item>`.
92
+ * To customize the content of the `<vaadin-combo-box-item>` elements placed in the dropdown, use
93
+ * [`renderer`](#/elements/vaadin-combo-box#property-renderer) property which accepts a function.
94
+ * The renderer function is called with `root`, `comboBox`, and `model` as arguments.
91
95
  *
92
- * The renderer function provides `root`, `comboBox`, `model` arguments when applicable.
93
- * Generate DOM content by using `model` object properties if needed, append it to the `root`
94
- * element and control the state of the host element by accessing `comboBox`. Before generating new
95
- * content, users are able to check if there is already content in `root` for reusing it.
96
+ * Generate DOM content by using `model` object properties if needed, and append it to the `root`
97
+ * element. The `comboBox` reference is provided to access the combo-box element state. Do not
98
+ * set combo-box properties in a `renderer` function.
96
99
  *
97
- * ```html
98
- * <vaadin-combo-box id="combo-box"></vaadin-combo-box>
99
- * ```
100
100
  * ```js
101
101
  * const comboBox = document.querySelector('#combo-box');
102
102
  * comboBox.items = [{'label': 'Hydrogen', 'value': 'H'}];
103
- * comboBox.renderer = function(root, comboBox, model) {
104
- * root.innerHTML = model.index + ': ' +
105
- * model.item.label + ' ' +
106
- * '<b>' + model.item.value + '</b>';
103
+ * comboBox.renderer = (root, comboBox, model) => {
104
+ * const item = model.item;
105
+ * root.innerHTML = `${model.index}: ${item.label} <b>${item.value}</b>`;
107
106
  * };
108
107
  * ```
109
108
  *
110
109
  * Renderer is called on the opening of the combo-box and each time the related model is updated.
111
- * DOM generated during the renderer call can be reused
112
- * in the next renderer call and will be provided with the `root` argument.
113
- * On first call it will be empty.
110
+ * Before creating new content, it is recommended to check if there is already an existing DOM
111
+ * element in `root` from a previous renderer call for reusing it. Even though combo-box uses
112
+ * infinite scrolling, reducing DOM operations might improve performance.
114
113
  *
115
114
  * The following properties are available in the `model` argument:
116
115
  *
117
- * Property name | Type | Description
118
- * --------------|------|------------
119
- * `index`| Number | Index of the item in the `items` array
120
- * `item` | String or Object | The item reference
121
- * `selected` | Boolean | True when item is selected
122
- * `focused` | Boolean | True when item is focused
116
+ * Property | Type | Description
117
+ * -----------|------------------|-------------
118
+ * `index` | Number | Index of the item in the `items` array
119
+ * `item` | String or Object | The item reference
120
+ * `selected` | Boolean | True when item is selected
121
+ * `focused` | Boolean | True when item is focused
123
122
  *
124
123
  * ### Lazy Loading with Function Data Provider
125
124
  *
126
- * In addition to assigning an array to the items property, you can alternatively
127
- * provide the `<vaadin-combo-box>` data through the
125
+ * In addition to assigning an array to the items property, you can alternatively use the
128
126
  * [`dataProvider`](#/elements/vaadin-combo-box#property-dataProvider) function property.
129
127
  * The `<vaadin-combo-box>` calls this function lazily, only when it needs more data
130
128
  * to be displayed.
131
129
  *
132
- * See the [`dataProvider`](#/elements/vaadin-combo-box#property-dataProvider) in
133
- * the API reference below for the detailed data provider arguments description,
134
- * and the “Lazy Loading“ example on “Basics” page in the demos.
135
- *
136
130
  * __Note that when using function data providers, the total number of items
137
131
  * needs to be set manually. The total number of items can be returned
138
132
  * in the second argument of the data provider callback:__
@@ -222,10 +216,21 @@ declare class ComboBox<TItem = ComboBoxDefaultItem> extends HTMLElement {
222
216
  interface ComboBox<TItem = ComboBoxDefaultItem>
223
217
  extends ComboBoxDataProviderMixinClass<TItem>,
224
218
  ComboBoxMixinClass<TItem>,
219
+ ValidateMixinClass,
225
220
  PatternMixinClass,
221
+ LabelMixinClass,
222
+ KeyboardMixinClass,
223
+ InputMixinClass,
226
224
  InputControlMixinClass,
225
+ InputConstraintsMixinClass,
226
+ FocusMixinClass,
227
+ FieldMixinClass,
228
+ DisabledMixinClass,
229
+ DelegateStateMixinClass,
230
+ DelegateFocusMixinClass,
227
231
  ThemableMixinClass,
228
- ElementMixinClass {}
232
+ ElementMixinClass,
233
+ ControllerMixinClass {}
229
234
 
230
235
  declare global {
231
236
  interface HTMLElementTagNameMap {
@@ -7,9 +7,9 @@ import '@vaadin/input-container/src/vaadin-input-container.js';
7
7
  import './vaadin-combo-box-dropdown.js';
8
8
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
9
9
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
10
- import { AriaLabelController } from '@vaadin/field-base/src/aria-label-controller.js';
11
10
  import { InputControlMixin } from '@vaadin/field-base/src/input-control-mixin.js';
12
11
  import { InputController } from '@vaadin/field-base/src/input-controller.js';
12
+ import { LabelledInputController } from '@vaadin/field-base/src/labelled-input-controller.js';
13
13
  import { PatternMixin } from '@vaadin/field-base/src/pattern-mixin.js';
14
14
  import { inputFieldShared } from '@vaadin/field-base/src/styles/input-field-shared-styles.js';
15
15
  import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
@@ -19,77 +19,60 @@ import { ComboBoxMixin } from './vaadin-combo-box-mixin.js';
19
19
  registerStyles('vaadin-combo-box', inputFieldShared, { moduleId: 'vaadin-combo-box-styles' });
20
20
 
21
21
  /**
22
- * `<vaadin-combo-box>` is a combo box element combining a dropdown list with an
23
- * input field for filtering the list of items. If you want to replace the default
24
- * input field with a custom implementation, you should use the
25
- * [`<vaadin-combo-box-light>`](#/elements/vaadin-combo-box-light) element.
26
- *
27
- * Items in the dropdown list must be provided as a list of `String` values.
28
- * Defining the items is done using the `items` property, which can be assigned
29
- * with data-binding, using an attribute or directly with the JavaScript property.
22
+ * `<vaadin-combo-box>` is a web component for choosing a value from a filterable list of options
23
+ * presented in a dropdown overlay. The options can be provided as a list of strings or objects
24
+ * by setting [`items`](#/elements/vaadin-combo-box#property-items) property on the element.
30
25
  *
31
26
  * ```html
32
- * <vaadin-combo-box
33
- * label="Fruit"
34
- * items="[[data]]">
35
- * </vaadin-combo-box>
27
+ * <vaadin-combo-box id="combo-box"></vaadin-combo-box>
36
28
  * ```
37
29
  *
38
30
  * ```js
39
- * combobox.items = ['apple', 'orange', 'banana'];
31
+ * document.querySelector('#combo-box').items = ['apple', 'orange', 'banana'];
40
32
  * ```
41
33
  *
42
34
  * When the selected `value` is changed, a `value-changed` event is triggered.
43
35
  *
44
36
  * ### Item rendering
45
37
  *
46
- * `<vaadin-combo-box>` supports using custom renderer callback function for defining the
47
- * content of `<vaadin-combo-box-item>`.
38
+ * To customize the content of the `<vaadin-combo-box-item>` elements placed in the dropdown, use
39
+ * [`renderer`](#/elements/vaadin-combo-box#property-renderer) property which accepts a function.
40
+ * The renderer function is called with `root`, `comboBox`, and `model` as arguments.
48
41
  *
49
- * The renderer function provides `root`, `comboBox`, `model` arguments when applicable.
50
- * Generate DOM content by using `model` object properties if needed, append it to the `root`
51
- * element and control the state of the host element by accessing `comboBox`. Before generating new
52
- * content, users are able to check if there is already content in `root` for reusing it.
42
+ * Generate DOM content by using `model` object properties if needed, and append it to the `root`
43
+ * element. The `comboBox` reference is provided to access the combo-box element state. Do not
44
+ * set combo-box properties in a `renderer` function.
53
45
  *
54
- * ```html
55
- * <vaadin-combo-box id="combo-box"></vaadin-combo-box>
56
- * ```
57
46
  * ```js
58
47
  * const comboBox = document.querySelector('#combo-box');
59
48
  * comboBox.items = [{'label': 'Hydrogen', 'value': 'H'}];
60
- * comboBox.renderer = function(root, comboBox, model) {
61
- * root.innerHTML = model.index + ': ' +
62
- * model.item.label + ' ' +
63
- * '<b>' + model.item.value + '</b>';
49
+ * comboBox.renderer = (root, comboBox, model) => {
50
+ * const item = model.item;
51
+ * root.innerHTML = `${model.index}: ${item.label} <b>${item.value}</b>`;
64
52
  * };
65
53
  * ```
66
54
  *
67
55
  * Renderer is called on the opening of the combo-box and each time the related model is updated.
68
- * DOM generated during the renderer call can be reused
69
- * in the next renderer call and will be provided with the `root` argument.
70
- * On first call it will be empty.
56
+ * Before creating new content, it is recommended to check if there is already an existing DOM
57
+ * element in `root` from a previous renderer call for reusing it. Even though combo-box uses
58
+ * infinite scrolling, reducing DOM operations might improve performance.
71
59
  *
72
60
  * The following properties are available in the `model` argument:
73
61
  *
74
- * Property name | Type | Description
75
- * --------------|------|------------
76
- * `index`| Number | Index of the item in the `items` array
77
- * `item` | String or Object | The item reference
78
- * `selected` | Boolean | True when item is selected
79
- * `focused` | Boolean | True when item is focused
62
+ * Property | Type | Description
63
+ * -----------|------------------|-------------
64
+ * `index` | Number | Index of the item in the `items` array
65
+ * `item` | String or Object | The item reference
66
+ * `selected` | Boolean | True when item is selected
67
+ * `focused` | Boolean | True when item is focused
80
68
  *
81
69
  * ### Lazy Loading with Function Data Provider
82
70
  *
83
- * In addition to assigning an array to the items property, you can alternatively
84
- * provide the `<vaadin-combo-box>` data through the
71
+ * In addition to assigning an array to the items property, you can alternatively use the
85
72
  * [`dataProvider`](#/elements/vaadin-combo-box#property-dataProvider) function property.
86
73
  * The `<vaadin-combo-box>` calls this function lazily, only when it needs more data
87
74
  * to be displayed.
88
75
  *
89
- * See the [`dataProvider`](#/elements/vaadin-combo-box#property-dataProvider) in
90
- * the API reference below for the detailed data provider arguments description,
91
- * and the “Lazy Loading“ example on “Basics” page in the demos.
92
- *
93
76
  * __Note that when using function data providers, the total number of items
94
77
  * needs to be set manually. The total number of items can be returned
95
78
  * in the second argument of the data provider callback:__
@@ -259,7 +242,7 @@ class ComboBox extends ComboBoxDataProviderMixin(
259
242
  this.ariaTarget = input;
260
243
  })
261
244
  );
262
- this.addController(new AriaLabelController(this, this.inputElement, this._labelNode));
245
+ this.addController(new LabelledInputController(this.inputElement, this._labelNode));
263
246
  this._positionTarget = this.shadowRoot.querySelector('[part="input-field"]');
264
247
  this._toggleElement = this.$.toggleButton;
265
248
  }