@vaadin/combo-box 22.0.0-beta1 → 22.0.1

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/README.md CHANGED
@@ -1,13 +1,10 @@
1
- # <vaadin-combo-box>
1
+ # @vaadin/combo-box
2
2
 
3
- [Live Demo ↗](https://vaadin.com/components/vaadin-combo-box/html-examples)
4
- |
5
- [API documentation ↗](https://vaadin.com/components/vaadin-combo-box/html-api)
3
+ A web component for choosing a value from a filterable list of options presented in an overlay.
6
4
 
7
- [<vaadin-combo-box>](https://vaadin.com/components/vaadin-combo-box) is a Web Component combining a dropdown list with an input field for filtering the list of items, part of the [Vaadin components](https://vaadin.com/components).
5
+ [Documentation + Live Demo ↗](https://vaadin.com/docs/latest/ds/components/combo-box)
8
6
 
9
7
  [![npm version](https://badgen.net/npm/v/@vaadin/combo-box)](https://www.npmjs.com/package/@vaadin/combo-box)
10
- [![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/vaadinvaadin-combo-box)
11
8
  [![Discord](https://img.shields.io/discord/732335336448852018?label=discord)](https://discord.gg/PHmkCKC)
12
9
 
13
10
  ```html
@@ -27,45 +24,44 @@
27
24
  </script>
28
25
  ```
29
26
 
30
- [<img src="https://raw.githubusercontent.com/vaadin/vaadin-combo-box/master/screenshot.png" width="208" alt="Screenshot of vaadin-combo-box" />](https://vaadin.com/components/vaadin-combo-box)
27
+ [<img src="https://raw.githubusercontent.com/vaadin/web-components/master/packages/combo-box/screenshot.png" width="208" alt="Screenshot of vaadin-combo-box">](https://vaadin.com/docs/latest/ds/components/combo-box)
31
28
 
32
29
  ## Installation
33
30
 
34
- Install `vaadin-combo-box`:
31
+ Install the component:
35
32
 
36
33
  ```sh
37
- npm i @vaadin/combo-box --save
34
+ npm i @vaadin/combo-box
38
35
  ```
39
36
 
40
- Once installed, import it in your application:
37
+ Once installed, import the component in your application:
41
38
 
42
39
  ```js
43
- import '@vaadin/combo-box/vaadin-combo-box.js';
40
+ import '@vaadin/combo-box';
44
41
  ```
45
42
 
46
- ## Getting Started
43
+ ## Themes
47
44
 
48
- Vaadin components use the Lumo theme by default.
45
+ Vaadin components come with two built-in [themes](https://vaadin.com/docs/latest/ds/customization/using-themes), Lumo and Material.
46
+ The [main entrypoint](https://github.com/vaadin/web-components/blob/master/packages/combo-box/vaadin-combo-box.js) of the package uses the Lumo theme.
49
47
 
50
- To use the Material theme, import the correspondent file from the `theme/material` folder.
48
+ To use the Material theme, import the component from the `theme/material` folder:
51
49
 
52
- ## Entry points
53
-
54
- - The components with the Lumo theme:
55
-
56
- `theme/lumo/vaadin-combo-box.js`
57
- `theme/lumo/vaadin-combo-box-light.js`
50
+ ```js
51
+ import '@vaadin/combo-box/theme/material/vaadin-combo-box.js';
52
+ ```
58
53
 
59
- - The components with the Material theme:
54
+ You can also import the Lumo version of the component explicitly:
60
55
 
61
- `theme/material/vaadin-combo-box.js`
62
- `theme/material/vaadin-combo-box-light.js`
56
+ ```js
57
+ import '@vaadin/combo-box/theme/lumo/vaadin-combo-box.js';
58
+ ```
63
59
 
64
- - Alias for `theme/lumo/vaadin-combo-box.js`
65
- `theme/lumo/vaadin-combo-box-light.js`
60
+ Finally, you can import the un-themed component from the `src` folder to get a minimal starting point:
66
61
 
67
- `vaadin-combo-box.js`
68
- `vaadin-combo-box-light.js`
62
+ ```js
63
+ import '@vaadin/combo-box/src/vaadin-combo-box.js';
64
+ ```
69
65
 
70
66
  ## Contributing
71
67
 
@@ -75,4 +71,5 @@ Read the [contributing guide](https://vaadin.com/docs/latest/guide/contributing/
75
71
 
76
72
  Apache License 2.0
77
73
 
78
- Vaadin collects development time usage statistics to improve this product. For details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.
74
+ Vaadin collects usage statistics at development time to improve this product.
75
+ For details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/combo-box",
3
- "version": "22.0.0-beta1",
3
+ "version": "22.0.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -31,25 +31,26 @@
31
31
  "polymer"
32
32
  ],
33
33
  "dependencies": {
34
+ "@open-wc/dedupe-mixin": "^1.3.0",
34
35
  "@polymer/iron-resizable-behavior": "^3.0.0",
35
36
  "@polymer/polymer": "^3.0.0",
36
- "@vaadin/component-base": "22.0.0-beta1",
37
- "@vaadin/field-base": "22.0.0-beta1",
38
- "@vaadin/input-container": "22.0.0-beta1",
39
- "@vaadin/item": "22.0.0-beta1",
40
- "@vaadin/vaadin-lumo-styles": "22.0.0-beta1",
41
- "@vaadin/vaadin-material-styles": "22.0.0-beta1",
42
- "@vaadin/vaadin-overlay": "22.0.0-beta1",
43
- "@vaadin/vaadin-themable-mixin": "22.0.0-beta1"
37
+ "@vaadin/component-base": "^22.0.1",
38
+ "@vaadin/field-base": "^22.0.1",
39
+ "@vaadin/input-container": "^22.0.1",
40
+ "@vaadin/item": "^22.0.1",
41
+ "@vaadin/vaadin-lumo-styles": "^22.0.1",
42
+ "@vaadin/vaadin-material-styles": "^22.0.1",
43
+ "@vaadin/vaadin-overlay": "^22.0.1",
44
+ "@vaadin/vaadin-themable-mixin": "^22.0.1"
44
45
  },
45
46
  "devDependencies": {
46
47
  "@esm-bundle/chai": "^4.3.4",
47
- "@vaadin/dialog": "22.0.0-beta1",
48
- "@vaadin/polymer-legacy-adapter": "22.0.0-beta1",
49
- "@vaadin/testing-helpers": "^0.3.0",
50
- "@vaadin/text-field": "22.0.0-beta1",
48
+ "@vaadin/dialog": "^22.0.1",
49
+ "@vaadin/polymer-legacy-adapter": "^22.0.1",
50
+ "@vaadin/testing-helpers": "^0.3.2",
51
+ "@vaadin/text-field": "^22.0.1",
51
52
  "lit": "^2.0.0",
52
53
  "sinon": "^9.2.0"
53
54
  },
54
- "gitHead": "4cf8a9d0504994200c610e44b3676114fef49c1e"
55
+ "gitHead": "2b0a2bff0369d6020f7cc33ad35506aa2d1f6f68"
55
56
  }
@@ -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 { Constructor } from '@open-wc/dedupe-mixin';
6
7
 
7
8
  export type ComboBoxDataProviderCallback<TItem> = (items: Array<TItem>, size: number) => void;
8
9
 
@@ -17,15 +18,11 @@ export type ComboBoxDataProvider<TItem> = (
17
18
  callback: ComboBoxDataProviderCallback<TItem>
18
19
  ) => void;
19
20
 
20
- declare function ComboBoxDataProviderMixin<TItem, T extends new (...args: any[]) => {}>(
21
+ export declare function ComboBoxDataProviderMixin<TItem, T extends Constructor<HTMLElement>>(
21
22
  base: T
22
- ): T & ComboBoxDataProviderMixinConstructor<TItem>;
23
+ ): T & Constructor<ComboBoxDataProviderMixinClass<TItem>>;
23
24
 
24
- interface ComboBoxDataProviderMixinConstructor<TItem> {
25
- new (...args: any[]): ComboBoxDataProviderMixin<TItem>;
26
- }
27
-
28
- interface ComboBoxDataProviderMixin<TItem> {
25
+ export declare class ComboBoxDataProviderMixinClass<TItem> {
29
26
  /**
30
27
  * Number of items fetched at a time from the dataprovider.
31
28
  * @attr {number} page-size
@@ -57,5 +54,3 @@ interface ComboBoxDataProviderMixin<TItem> {
57
54
  */
58
55
  clearCache(): void;
59
56
  }
60
-
61
- export { ComboBoxDataProviderMixin, ComboBoxDataProviderMixinConstructor };
@@ -3,21 +3,12 @@
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 { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
7
- import { mixinBehaviors } from '@polymer/polymer/lib/legacy/class.js';
8
- import { IronResizableBehavior } from '@polymer/iron-resizable-behavior/iron-resizable-behavior.js';
9
6
  import './vaadin-combo-box-item.js';
10
7
  import './vaadin-combo-box-overlay.js';
11
8
  import './vaadin-combo-box-scroller.js';
12
-
13
- const TOUCH_DEVICE = (() => {
14
- try {
15
- document.createEvent('TouchEvent');
16
- return true;
17
- } catch (e) {
18
- return false;
19
- }
20
- })();
9
+ import { IronResizableBehavior } from '@polymer/iron-resizable-behavior/iron-resizable-behavior.js';
10
+ import { mixinBehaviors } from '@polymer/polymer/lib/legacy/class.js';
11
+ import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
21
12
 
22
13
  /**
23
14
  * Element for internal use only.
@@ -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,7 +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 { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
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
9
 
@@ -3,9 +3,12 @@
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 { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
7
- import { ComboBoxMixin } from './vaadin-combo-box-mixin.js';
8
- import { ComboBoxDataProviderMixin } from './vaadin-combo-box-data-provider-mixin.js';
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';
9
+ import { ThemableMixinClass } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10
+ import { ComboBoxDataProviderMixinClass } from './vaadin-combo-box-data-provider-mixin.js';
11
+ import { ComboBoxMixinClass } from './vaadin-combo-box-mixin.js';
9
12
  import { ComboBoxDefaultItem } from './vaadin-combo-box-mixin.js';
10
13
  export {
11
14
  ComboBoxDataProvider,
@@ -125,9 +128,12 @@ declare class ComboBoxLight<TItem = ComboBoxDefaultItem> extends HTMLElement {
125
128
  }
126
129
 
127
130
  interface ComboBoxLight<TItem = ComboBoxDefaultItem>
128
- extends ComboBoxDataProviderMixin<TItem>,
129
- ComboBoxMixin<TItem>,
130
- ThemableMixin {}
131
+ extends ComboBoxDataProviderMixinClass<TItem>,
132
+ ComboBoxMixinClass<TItem>,
133
+ KeyboardMixinClass,
134
+ InputMixinClass,
135
+ DisabledMixinClass,
136
+ ThemableMixinClass {}
131
137
 
132
138
  declare global {
133
139
  interface HTMLElementTagNameMap {
@@ -3,12 +3,12 @@
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 { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
6
+ import './vaadin-combo-box-dropdown.js';
7
7
  import { dashToCamelCase } from '@polymer/polymer/lib/utils/case-map.js';
8
+ import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
8
9
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
9
- import { ComboBoxMixin } from './vaadin-combo-box-mixin.js';
10
10
  import { ComboBoxDataProviderMixin } from './vaadin-combo-box-data-provider-mixin.js';
11
- import './vaadin-combo-box-dropdown.js';
11
+ import { ComboBoxMixin } from './vaadin-combo-box-mixin.js';
12
12
 
13
13
  /**
14
14
  * `<vaadin-combo-box-light>` is a customizable version of the `<vaadin-combo-box>` providing
@@ -3,9 +3,10 @@
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 { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js';
7
- import { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js';
8
- import { InputMixin } from '@vaadin/field-base/src/input-mixin.js';
6
+ import { Constructor } from '@open-wc/dedupe-mixin';
7
+ import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
+ import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
9
+ import { InputMixinClass } from '@vaadin/field-base/src/input-mixin.js';
9
10
  import { ComboBox } from './vaadin-combo-box.js';
10
11
 
11
12
  export type ComboBoxDefaultItem = any;
@@ -21,16 +22,22 @@ export type ComboBoxRenderer<TItem> = (
21
22
  model: ComboBoxItemModel<TItem>
22
23
  ) => void;
23
24
 
24
- declare function ComboBoxMixin<TItem, T extends new (...args: any[]) => {}>(
25
+ export declare function ComboBoxMixin<TItem, T extends Constructor<HTMLElement>>(
25
26
  base: T
26
- ): T & ComboBoxMixinConstructor<TItem>;
27
+ ): T &
28
+ Constructor<ComboBoxMixinClass<TItem>> &
29
+ Constructor<DisabledMixinClass> &
30
+ Constructor<InputMixinClass> &
31
+ Constructor<KeyboardMixinClass>;
27
32
 
28
- interface ComboBoxMixinConstructor<TItem> {
29
- new (...args: any[]): ComboBoxMixin<TItem>;
30
- }
33
+ export declare class ComboBoxMixinClass<TItem> {
34
+ protected readonly _propertyForValue: string;
35
+
36
+ protected _inputElementValue: string | undefined;
31
37
 
32
- interface ComboBoxMixin<TItem> extends DisabledMixin, InputMixin, KeyboardMixin {
33
- readonly _propertyForValue: string;
38
+ protected _revertInputValue(): void;
39
+
40
+ protected _getItemElements(): HTMLElement[];
34
41
 
35
42
  /**
36
43
  * True if the dropdown is open, false otherwise.
@@ -173,5 +180,3 @@ interface ComboBoxMixin<TItem> extends DisabledMixin, InputMixin, KeyboardMixin
173
180
  */
174
181
  checkValidity(): boolean;
175
182
  }
176
-
177
- export { ComboBoxMixin, ComboBoxMixinConstructor };
@@ -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
  });
@@ -930,6 +935,14 @@ export const ComboBoxMixin = (subclass) =>
930
935
  this.opened || this.autoOpenDisabled
931
936
  ? this.$.dropdown.indexOfLabel(this.filter)
932
937
  : this._indexOfValue(this.value, this.filteredItems);
938
+
939
+ // see https://github.com/vaadin/web-components/issues/2615
940
+ if (this.selectedItem === null && this._focusedIndex >= 0) {
941
+ const filteredItem = this.filteredItems[this._focusedIndex];
942
+ if (this._getItemValue(filteredItem) === this.value) {
943
+ this._selectItemForValue(this.value);
944
+ }
945
+ }
933
946
  }
934
947
  }
935
948
 
@@ -4,8 +4,8 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { OverlayElement } from '@vaadin/vaadin-overlay/src/vaadin-overlay.js';
7
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
8
7
  import { PositionMixin } from '@vaadin/vaadin-overlay/src/vaadin-overlay-position-mixin.js';
8
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
9
9
 
10
10
  registerStyles(
11
11
  'vaadin-combo-box-overlay',
@@ -3,7 +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 { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
6
+ import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
7
  import { Virtualizer } from '@vaadin/component-base/src/virtualizer.js';
8
8
  import { ComboBoxPlaceholder } from './vaadin-combo-box-placeholder.js';
9
9
 
@@ -3,12 +3,23 @@
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 { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
7
- import { InputControlMixin } from '@vaadin/field-base/src/input-control-mixin.js';
8
- import { PatternMixin } from '@vaadin/field-base/src/pattern-mixin.js';
9
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10
- import { ComboBoxDataProviderMixin } from './vaadin-combo-box-data-provider-mixin.js';
11
- import { ComboBoxMixin } from './vaadin-combo-box-mixin.js';
6
+ import { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
7
+ import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
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';
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';
18
+ import { PatternMixinClass } from '@vaadin/field-base/src/pattern-mixin.js';
19
+ import { ValidateMixinClass } from '@vaadin/field-base/src/validate-mixin.js';
20
+ import { ThemableMixinClass } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
21
+ import { ComboBoxDataProviderMixinClass } from './vaadin-combo-box-data-provider-mixin.js';
22
+ import { ComboBoxMixinClass } from './vaadin-combo-box-mixin.js';
12
23
  import { ComboBoxDefaultItem } from './vaadin-combo-box-mixin.js';
13
24
  export {
14
25
  ComboBoxDataProvider,
@@ -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:__
@@ -220,12 +214,23 @@ declare class ComboBox<TItem = ComboBoxDefaultItem> extends HTMLElement {
220
214
  }
221
215
 
222
216
  interface ComboBox<TItem = ComboBoxDefaultItem>
223
- extends ComboBoxDataProviderMixin<TItem>,
224
- ComboBoxMixin<TItem>,
225
- PatternMixin,
226
- InputControlMixin,
227
- ThemableMixin,
228
- ElementMixin {}
217
+ extends ComboBoxDataProviderMixinClass<TItem>,
218
+ ComboBoxMixinClass<TItem>,
219
+ ValidateMixinClass,
220
+ PatternMixinClass,
221
+ LabelMixinClass,
222
+ KeyboardMixinClass,
223
+ InputMixinClass,
224
+ InputControlMixinClass,
225
+ InputConstraintsMixinClass,
226
+ FocusMixinClass,
227
+ FieldMixinClass,
228
+ DisabledMixinClass,
229
+ DelegateStateMixinClass,
230
+ DelegateFocusMixinClass,
231
+ ThemableMixinClass,
232
+ ElementMixinClass,
233
+ ControllerMixinClass {}
229
234
 
230
235
  declare global {
231
236
  interface HTMLElementTagNameMap {
@@ -3,94 +3,76 @@
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 { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
6
+ import '@vaadin/input-container/src/vaadin-input-container.js';
7
+ import './vaadin-combo-box-dropdown.js';
8
+ import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
9
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
8
- import { AriaLabelController } from '@vaadin/field-base/src/aria-label-controller.js';
9
- import { InputController } from '@vaadin/field-base/src/input-controller.js';
10
10
  import { InputControlMixin } from '@vaadin/field-base/src/input-control-mixin.js';
11
+ import { InputController } from '@vaadin/field-base/src/input-controller.js';
12
+ import { LabelledInputController } from '@vaadin/field-base/src/labelled-input-controller.js';
11
13
  import { PatternMixin } from '@vaadin/field-base/src/pattern-mixin.js';
12
14
  import { inputFieldShared } from '@vaadin/field-base/src/styles/input-field-shared-styles.js';
13
- import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
14
- import { registerStyles } from '@vaadin/vaadin-themable-mixin/register-styles.js';
15
- import '@vaadin/input-container/src/vaadin-input-container.js';
15
+ import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
16
16
  import { ComboBoxDataProviderMixin } from './vaadin-combo-box-data-provider-mixin.js';
17
17
  import { ComboBoxMixin } from './vaadin-combo-box-mixin.js';
18
- import './vaadin-combo-box-dropdown.js';
19
18
 
20
19
  registerStyles('vaadin-combo-box', inputFieldShared, { moduleId: 'vaadin-combo-box-styles' });
21
20
 
22
21
  /**
23
- * `<vaadin-combo-box>` is a combo box element combining a dropdown list with an
24
- * input field for filtering the list of items. If you want to replace the default
25
- * input field with a custom implementation, you should use the
26
- * [`<vaadin-combo-box-light>`](#/elements/vaadin-combo-box-light) element.
27
- *
28
- * Items in the dropdown list must be provided as a list of `String` values.
29
- * Defining the items is done using the `items` property, which can be assigned
30
- * 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.
31
25
  *
32
26
  * ```html
33
- * <vaadin-combo-box
34
- * label="Fruit"
35
- * items="[[data]]">
36
- * </vaadin-combo-box>
27
+ * <vaadin-combo-box id="combo-box"></vaadin-combo-box>
37
28
  * ```
38
29
  *
39
30
  * ```js
40
- * combobox.items = ['apple', 'orange', 'banana'];
31
+ * document.querySelector('#combo-box').items = ['apple', 'orange', 'banana'];
41
32
  * ```
42
33
  *
43
34
  * When the selected `value` is changed, a `value-changed` event is triggered.
44
35
  *
45
36
  * ### Item rendering
46
37
  *
47
- * `<vaadin-combo-box>` supports using custom renderer callback function for defining the
48
- * 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.
49
41
  *
50
- * The renderer function provides `root`, `comboBox`, `model` arguments when applicable.
51
- * Generate DOM content by using `model` object properties if needed, append it to the `root`
52
- * element and control the state of the host element by accessing `comboBox`. Before generating new
53
- * 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.
54
45
  *
55
- * ```html
56
- * <vaadin-combo-box id="combo-box"></vaadin-combo-box>
57
- * ```
58
46
  * ```js
59
47
  * const comboBox = document.querySelector('#combo-box');
60
48
  * comboBox.items = [{'label': 'Hydrogen', 'value': 'H'}];
61
- * comboBox.renderer = function(root, comboBox, model) {
62
- * root.innerHTML = model.index + ': ' +
63
- * model.item.label + ' ' +
64
- * '<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>`;
65
52
  * };
66
53
  * ```
67
54
  *
68
55
  * Renderer is called on the opening of the combo-box and each time the related model is updated.
69
- * DOM generated during the renderer call can be reused
70
- * in the next renderer call and will be provided with the `root` argument.
71
- * 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.
72
59
  *
73
60
  * The following properties are available in the `model` argument:
74
61
  *
75
- * Property name | Type | Description
76
- * --------------|------|------------
77
- * `index`| Number | Index of the item in the `items` array
78
- * `item` | String or Object | The item reference
79
- * `selected` | Boolean | True when item is selected
80
- * `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
81
68
  *
82
69
  * ### Lazy Loading with Function Data Provider
83
70
  *
84
- * In addition to assigning an array to the items property, you can alternatively
85
- * provide the `<vaadin-combo-box>` data through the
71
+ * In addition to assigning an array to the items property, you can alternatively use the
86
72
  * [`dataProvider`](#/elements/vaadin-combo-box#property-dataProvider) function property.
87
73
  * The `<vaadin-combo-box>` calls this function lazily, only when it needs more data
88
74
  * to be displayed.
89
75
  *
90
- * See the [`dataProvider`](#/elements/vaadin-combo-box#property-dataProvider) in
91
- * the API reference below for the detailed data provider arguments description,
92
- * and the “Lazy Loading“ example on “Basics” page in the demos.
93
- *
94
76
  * __Note that when using function data providers, the total number of items
95
77
  * needs to be set manually. The total number of items can be returned
96
78
  * in the second argument of the data provider callback:__
@@ -260,7 +242,7 @@ class ComboBox extends ComboBoxDataProviderMixin(
260
242
  this.ariaTarget = input;
261
243
  })
262
244
  );
263
- this.addController(new AriaLabelController(this, this.inputElement, this._labelNode));
245
+ this.addController(new LabelledInputController(this.inputElement, this._labelNode));
264
246
  this._positionTarget = this.shadowRoot.querySelector('[part="input-field"]');
265
247
  this._toggleElement = this.$.toggleButton;
266
248
  }
@@ -1,10 +1,10 @@
1
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
1
  import '@vaadin/vaadin-lumo-styles/color.js';
3
2
  import '@vaadin/vaadin-lumo-styles/spacing.js';
4
3
  import '@vaadin/vaadin-lumo-styles/style.js';
5
- import { overlay } from '@vaadin/vaadin-lumo-styles/mixins/overlay.js';
6
4
  import '@vaadin/vaadin-overlay/theme/lumo/vaadin-overlay.js';
7
5
  import { menuOverlayCore } from '@vaadin/vaadin-lumo-styles/mixins/menu-overlay.js';
6
+ import { overlay } from '@vaadin/vaadin-lumo-styles/mixins/overlay.js';
7
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
8
8
 
9
9
  const comboBoxOverlay = css`
10
10
  [part='content'] {
@@ -1,45 +1,21 @@
1
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
- import { item } from '@vaadin/item/theme/lumo/vaadin-item-styles.js';
3
1
  import '@vaadin/vaadin-lumo-styles/color.js';
4
2
  import '@vaadin/vaadin-lumo-styles/spacing.js';
5
3
  import '@vaadin/vaadin-lumo-styles/style.js';
4
+ import { item } from '@vaadin/item/theme/lumo/vaadin-item-styles.js';
5
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
6
6
 
7
- /* TODO partly duplicated from vaadin-list-box styles. Should find a way to make it DRY */
8
7
  const comboBoxItem = css`
9
8
  :host {
10
- cursor: default;
11
- -webkit-tap-highlight-color: var(--lumo-primary-color-10pct);
12
- padding-left: calc(var(--lumo-border-radius-m) / 4);
13
- padding-right: calc(var(--lumo-space-l) + var(--lumo-border-radius-m) / 4);
14
9
  transition: background-color 100ms;
15
- border-radius: var(--lumo-border-radius-m);
16
10
  overflow: hidden;
17
11
  --_lumo-item-selected-icon-display: block;
18
12
  }
19
13
 
20
- :host(:hover) {
21
- background-color: var(--lumo-primary-color-10pct);
22
- }
23
-
24
- :host([focused]:not([disabled])) {
25
- box-shadow: inset 0 0 0 2px var(--lumo-primary-color-50pct);
26
- }
27
-
28
- @media (pointer: coarse) {
29
- :host(:hover) {
30
- background-color: transparent;
31
- }
32
-
14
+ @media (any-hover: hover) {
33
15
  :host([focused]:not([disabled])) {
34
- box-shadow: none;
16
+ box-shadow: inset 0 0 0 2px var(--lumo-primary-color-50pct);
35
17
  }
36
18
  }
37
-
38
- /* RTL specific styles */
39
- :host([dir='rtl']) {
40
- padding-right: calc(var(--lumo-border-radius-m) / 4);
41
- padding-left: calc(var(--lumo-space-l) + var(--lumo-border-radius-m) / 4);
42
- }
43
19
  `;
44
20
 
45
21
  registerStyles('vaadin-combo-box-item', [item, comboBoxItem], {
@@ -1,6 +1,6 @@
1
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
1
  import '@vaadin/vaadin-lumo-styles/font-icons.js';
3
2
  import { inputFieldShared } from '@vaadin/vaadin-lumo-styles/mixins/input-field-shared.js';
3
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
4
4
 
5
5
  const comboBox = css`
6
6
  :host {
@@ -1,6 +1,6 @@
1
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
1
  import '@vaadin/vaadin-material-styles/color.js';
3
2
  import { menuOverlay } from '@vaadin/vaadin-material-styles/mixins/menu-overlay.js';
3
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
4
4
 
5
5
  const comboBoxOverlay = css`
6
6
  :host {
@@ -1,33 +1,16 @@
1
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
1
  import '@vaadin/vaadin-material-styles/color.js';
3
2
  import '@vaadin/vaadin-material-styles/font-icons.js';
4
3
  import '@vaadin/vaadin-material-styles/typography.js';
5
4
  import { item } from '@vaadin/item/theme/material/vaadin-item-styles.js';
5
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
6
6
 
7
7
  const comboBoxItem = css`
8
8
  :host {
9
9
  cursor: pointer;
10
10
  -webkit-tap-highlight-color: transparent;
11
11
  padding: 4px 10px;
12
- min-height: 36px;
13
- font-size: var(--material-small-font-size);
14
12
  --_material-item-selected-icon-display: block;
15
13
  }
16
-
17
- :host(:hover) {
18
- background-color: var(--material-secondary-background-color);
19
- }
20
-
21
- :host([focused]) {
22
- background-color: var(--material-divider-color);
23
- }
24
-
25
- @media (pointer: coarse) {
26
- :host(:hover),
27
- :host([focused]) {
28
- background-color: transparent;
29
- }
30
- }
31
14
  `;
32
15
 
33
16
  registerStyles('vaadin-combo-box-item', [item, comboBoxItem], {
@@ -1,7 +1,7 @@
1
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
1
  import '@vaadin/vaadin-material-styles/color.js';
3
2
  import '@vaadin/vaadin-material-styles/font-icons.js';
4
3
  import { inputFieldShared } from '@vaadin/vaadin-material-styles/mixins/input-field-shared.js';
4
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
5
5
 
6
6
  const comboBox = css`
7
7
  :host {