diff --git a/bower.json b/bower.json
index 8b8932098..dff4a77c9 100644
--- a/bower.json
+++ b/bower.json
@@ -38,7 +38,7 @@
"polymer": "^2.0.0",
"vaadin-control-state-mixin": "vaadin/vaadin-control-state-mixin#^2.1.1",
"vaadin-overlay": "vaadin/vaadin-overlay#^3.2.0",
- "vaadin-text-field": "vaadin/vaadin-text-field#^2.1.1",
+ "vaadin-text-field": "vaadin/vaadin-text-field#^2.3.0",
"vaadin-themable-mixin": "vaadin/vaadin-themable-mixin#^1.3.2",
"vaadin-lumo-styles": "vaadin/vaadin-lumo-styles#^1.1.1",
"vaadin-material-styles": "vaadin/vaadin-material-styles#^1.1.2",
diff --git a/demo/combo-box-basic-demos.html b/demo/combo-box-basic-demos.html
index 7b3d57200..0c7897e98 100644
--- a/demo/combo-box-basic-demos.html
+++ b/demo/combo-box-basic-demos.html
@@ -40,6 +40,23 @@
Configuring the Combo Box
+ Clear Button
+
+ Use the clear-button-visible attribute to display the clear button of an individual combobox.
+
+
+
+
+
+
+
+
Allow Custom Values
Allow the user to set any value for the field in addition to selecting a value from the dropdown menu.
diff --git a/src/vaadin-combo-box-light.html b/src/vaadin-combo-box-light.html
index ebccdb8f4..d3efc49dd 100644
--- a/src/vaadin-combo-box-light.html
+++ b/src/vaadin-combo-box-light.html
@@ -5,6 +5,7 @@
-->
+
@@ -13,6 +14,11 @@
+
@@ -74,16 +80,18 @@
*
* ```
* @memberof Vaadin
+ * @mixes Vaadin.ControlStateMixin
* @mixes Vaadin.ComboBoxDataProviderMixin
* @mixes Vaadin.ComboBoxMixin
* @mixes Vaadin.ThemableMixin
* @mixes Vaadin.ThemePropertyMixin
*/
class ComboBoxLightElement extends
- Vaadin.ThemePropertyMixin(
- Vaadin.ThemableMixin(
- Vaadin.ComboBoxDataProviderMixin(
- Vaadin.ComboBoxMixin(Polymer.Element)))) {
+ Vaadin.ControlStateMixin(
+ Vaadin.ThemePropertyMixin(
+ Vaadin.ThemableMixin(
+ Vaadin.ComboBoxDataProviderMixin(
+ Vaadin.ComboBoxMixin(Polymer.Element))))) {
static get is() {
return 'vaadin-combo-box-light';
@@ -118,10 +126,6 @@
this._clearElement = this.querySelector('.clear-button');
}
- get focused() {
- return this.getRootNode().activeElement === this.inputElement;
- }
-
connectedCallback() {
super.connectedCallback();
const cssSelector = 'vaadin-text-field,iron-input,paper-input,.paper-input-input,.input';
@@ -150,6 +154,18 @@
this.inputElement[this._propertyForValue] = value;
}
}
+
+ /**
+ * Focusable element used by vaadin-control-state-mixin
+ */
+ get focusElement() {
+ // Needed for focusing a paper-input properly
+ if (this.inputElement && this.inputElement._focusableElement) {
+ return this.inputElement._focusableElement;
+ }
+ // inputElement might not be defined on property changes before ready.
+ return this.inputElement || this;
+ }
}
customElements.define(ComboBoxLightElement.is, ComboBoxLightElement);
diff --git a/src/vaadin-combo-box.html b/src/vaadin-combo-box.html
index ce0e47fe9..b5563f249 100644
--- a/src/vaadin-combo-box.html
+++ b/src/vaadin-combo-box.html
@@ -33,12 +33,6 @@
width: 100%;
min-width: 0;
}
-
- :host([disabled]) [part="clear-button"],
- :host([readonly]) [part="clear-button"],
- :host(:not([has-value])) [part="clear-button"] {
- display: none;
- }
-
@@ -210,7 +204,6 @@
* Part name | Description
* ----------------|----------------
* `text-field` | The text field
- * `clear-button` | The clear button
* `toggle-button` | The toggle button
*
* See [`` documentation](https://github.com/vaadin/vaadin-overlay/blob/master/src/vaadin-overlay.html)
@@ -338,6 +331,14 @@
readonly: {
type: Boolean,
value: false
+ },
+
+ /**
+ * Set to true to display the clear icon which clears the input.
+ */
+ clearButtonVisible: {
+ type: Boolean,
+ value: false
}
};
}
@@ -361,9 +362,24 @@
ready() {
super.ready();
- this._nativeInput = this.$.input.focusElement;
+ this._nativeInput = this.inputElement.focusElement;
this._toggleElement = this.$.toggleButton;
- this._clearElement = this.$.clearButton;
+ this._clearElement = this.inputElement.shadowRoot.querySelector('[part="clear-button"]');
+
+ // Stop propagation of Esc in capturing phase so that
+ // vaadin-text-field will not handle Esc as a shortcut
+ // to clear the value.
+ // We need to set this listener for "this.inputElement"
+ // instead of just "this", otherwise keyboard navigation behaviour
+ // breaks a bit on Safari and some related tests fail.
+ this.inputElement.addEventListener('keydown', e => {
+ if (this._isEventKey(e, 'esc')) {
+ this._stopPropagation(e);
+ // Trigger _onEscape method of vaadin-combo-box-mixin because
+ // bubbling phase is not reached.
+ this._onEscape(e);
+ }
+ }, true);
this._nativeInput.setAttribute('role', 'combobox');
this._nativeInput.setAttribute('aria-autocomplete', 'list');
diff --git a/test/aria.html b/test/aria.html
index fe3d87493..98cf30d5f 100644
--- a/test/aria.html
+++ b/test/aria.html
@@ -35,9 +35,6 @@
function getToggleIcon() {
return comboBox._toggleElement;
}
- function getClearIcon() {
- return comboBox._clearElement;
- }
function getItemElement(i) {
return comboBox.$.overlay._selector.querySelectorAll('vaadin-combo-box-item')[i];
}
@@ -63,8 +60,6 @@
expect(getNativeInput().hasAttribute('aria-labelledby')).to.be.true;
expect(getToggleIcon().getAttribute('role')).to.equal('button');
expect(getToggleIcon().getAttribute('aria-label')).to.equal('Toggle');
- expect(getClearIcon().getAttribute('role')).to.equal('button');
- expect(getClearIcon().getAttribute('aria-label')).to.equal('Clear');
});
});
diff --git a/test/selecting-items.html b/test/selecting-items.html
index 0de2488e9..bbbd3c20a 100644
--- a/test/selecting-items.html
+++ b/test/selecting-items.html
@@ -20,6 +20,12 @@
+
+
+
+
+
+
diff --git a/test/visual/clear-button.html b/test/visual/clear-button.html
new file mode 100644
index 000000000..7aba05d4d
--- /dev/null
+++ b/test/visual/clear-button.html
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ No value
+
+
+
Basic value
+
+
+
Disabled
+
+
+
Read-only
+
+
+
+
diff --git a/test/visual/screens/vaadin-combo-box/clear-button-tests-lumo/default/chrome.png b/test/visual/screens/vaadin-combo-box/clear-button-tests-lumo/default/chrome.png
new file mode 100644
index 000000000..dfcb2a96f
Binary files /dev/null and b/test/visual/screens/vaadin-combo-box/clear-button-tests-lumo/default/chrome.png differ
diff --git a/test/visual/screens/vaadin-combo-box/clear-button-tests-lumo/default/firefox.png b/test/visual/screens/vaadin-combo-box/clear-button-tests-lumo/default/firefox.png
new file mode 100644
index 000000000..ef0a8b4e0
Binary files /dev/null and b/test/visual/screens/vaadin-combo-box/clear-button-tests-lumo/default/firefox.png differ
diff --git a/test/visual/screens/vaadin-combo-box/clear-button-tests-material/default/chrome.png b/test/visual/screens/vaadin-combo-box/clear-button-tests-material/default/chrome.png
new file mode 100644
index 000000000..df4fcf93c
Binary files /dev/null and b/test/visual/screens/vaadin-combo-box/clear-button-tests-material/default/chrome.png differ
diff --git a/test/visual/screens/vaadin-combo-box/clear-button-tests-material/default/firefox.png b/test/visual/screens/vaadin-combo-box/clear-button-tests-material/default/firefox.png
new file mode 100644
index 000000000..160896956
Binary files /dev/null and b/test/visual/screens/vaadin-combo-box/clear-button-tests-material/default/firefox.png differ
diff --git a/test/visual/screens/vaadin-combo-box/default-tests-lumo/default/chrome.png b/test/visual/screens/vaadin-combo-box/default-tests-lumo/default/chrome.png
index f57fc6c5d..70cc8613d 100644
Binary files a/test/visual/screens/vaadin-combo-box/default-tests-lumo/default/chrome.png and b/test/visual/screens/vaadin-combo-box/default-tests-lumo/default/chrome.png differ
diff --git a/test/visual/screens/vaadin-combo-box/default-tests-lumo/default/firefox.png b/test/visual/screens/vaadin-combo-box/default-tests-lumo/default/firefox.png
index c1560f39e..ff9daa8c8 100644
Binary files a/test/visual/screens/vaadin-combo-box/default-tests-lumo/default/firefox.png and b/test/visual/screens/vaadin-combo-box/default-tests-lumo/default/firefox.png differ
diff --git a/test/visual/screens/vaadin-combo-box/default-tests-material/default/chrome.png b/test/visual/screens/vaadin-combo-box/default-tests-material/default/chrome.png
index 447ecbda7..f5ff5b64d 100644
Binary files a/test/visual/screens/vaadin-combo-box/default-tests-material/default/chrome.png and b/test/visual/screens/vaadin-combo-box/default-tests-material/default/chrome.png differ
diff --git a/test/visual/screens/vaadin-combo-box/default-tests-material/default/firefox.png b/test/visual/screens/vaadin-combo-box/default-tests-material/default/firefox.png
index 8ae0f5920..708898d0a 100644
Binary files a/test/visual/screens/vaadin-combo-box/default-tests-material/default/firefox.png and b/test/visual/screens/vaadin-combo-box/default-tests-material/default/firefox.png differ
diff --git a/test/visual/test.js b/test/visual/test.js
index ecd60d252..1a22189dd 100644
--- a/test/visual/test.js
+++ b/test/visual/test.js
@@ -22,6 +22,13 @@ gemini.suite('vaadin-combo-box', function(rootSuite) {
.capture('default');
});
+ gemini.suite(`clear-button-tests-${theme}`, function(suite) {
+ suite
+ .setUrl(`clear-button.html?theme=${theme}`)
+ .setCaptureElements('#clear-button-tests')
+ .capture('default');
+ });
+
gemini.suite(`icons-${theme}`, function(suite) {
suite
.setUrl(`icons.html?theme=${theme}`)
diff --git a/theme/lumo/vaadin-combo-box-styles.html b/theme/lumo/vaadin-combo-box-styles.html
index 81a826be4..919ace940 100644
--- a/theme/lumo/vaadin-combo-box-styles.html
+++ b/theme/lumo/vaadin-combo-box-styles.html
@@ -13,10 +13,6 @@
[part="toggle-button"]::before {
content: var(--lumo-icons-dropdown);
}
-
- [part="clear-button"]::before {
- content: var(--lumo-icons-cross);
- }
diff --git a/theme/material/vaadin-combo-box-styles.html b/theme/material/vaadin-combo-box-styles.html
index f6d336ee6..db371f404 100644
--- a/theme/material/vaadin-combo-box-styles.html
+++ b/theme/material/vaadin-combo-box-styles.html
@@ -20,10 +20,6 @@
:host([opened]) [part="toggle-button"] {
transform: rotate(180deg);
}
-
- [part="clear-button"]::before {
- content: var(--material-icons-clear);
- }