diff --git a/src/vaadin-text-area.html b/src/vaadin-text-area.html index 9749ecbd..cf9b3167 100644 --- a/src/vaadin-text-area.html +++ b/src/vaadin-text-area.html @@ -68,7 +68,7 @@ -
+
[[helperText]]
diff --git a/src/vaadin-text-field.html b/src/vaadin-text-field.html index fe053efc..5b9bcf43 100644 --- a/src/vaadin-text-field.html +++ b/src/vaadin-text-field.html @@ -33,7 +33,7 @@
-
+
[[helperText]]
diff --git a/test/text-area.html b/test/text-area.html index 37253aea..0b78ca43 100644 --- a/test/text-area.html +++ b/test/text-area.html @@ -27,6 +27,14 @@ + + + + diff --git a/test/text-field.html b/test/text-field.html index 6dd13b67..03ddaf36 100644 --- a/test/text-field.html +++ b/test/text-field.html @@ -303,12 +303,6 @@ }); describe(`binding ${condition}`, function() { - function dispatchHelperSlotChange(node) { - // Workaround not to use timeouts - const evt = new CustomEvent('slotchange'); - node.shadowRoot.querySelector('[name="helper"]').dispatchEvent(evt); - } - it('default value should be empty string', function() { expect(textField.value).to.be.equal(''); }); @@ -381,56 +375,6 @@ expect(textField.hasAttribute('has-helper')).to.be.false; }); - it('text-field with slotted helper updates has-helper attribute', function() { - const textFieldSlottedHelper = fixture('default-with-slotted-helper'); - dispatchHelperSlotChange(textFieldSlottedHelper); - expect(textFieldSlottedHelper.hasAttribute('has-helper')).to.be.true; - }); - - it('setting helper with slot updates has-helper attribute', function() { - const helper = document.createElement('div'); - helper.setAttribute('slot', 'helper'); - helper.textContent = 'foo'; - textField.appendChild(helper); - dispatchHelperSlotChange(textField); - - expect(textField.hasAttribute('has-helper')).to.be.true; - }); - - it('removing slotted helper removes has-helper attribute', function() { - const textFieldSlottedHelper = fixture('default-with-slotted-helper'); - const helper = textFieldSlottedHelper.querySelector('[slot="helper"]'); - textFieldSlottedHelper.removeChild(helper); - dispatchHelperSlotChange(textFieldSlottedHelper); - expect(textFieldSlottedHelper.hasAttribute('has-helper')).to.be.false; - }); - - it('should not add "has-helper" with a slotted "slot" element', function() { - const xElement = fixture('custom-element-with-slotted-helper'); - const textField = xElement.$.textField; - expect(textField.hasAttribute('has-helper')).to.be.false; - }); - - it('should add "has-helper" when slotted "slot" and custom element sets string property', function() { - const xElement = fixture('custom-element-with-slotted-helper'); - const textField = xElement.$.textField; - xElement.helperText = 'helper text'; - expect(textField.hasAttribute('has-helper')).to.be.true; - }); - - it('should add "has-helper=slotted" when slotted "slot" and custom element sets content to slot', function() { - const xElement = fixture('custom-element-with-slotted-helper'); - const textField = xElement.$.textField; - const span = document.createElement('span'); - span.textContent = 'helper text'; - span.setAttribute('slot', 'helper'); - xElement.appendChild(span); - dispatchHelperSlotChange(textField); - - expect(textField.hasAttribute('has-helper')).to.be.true; - expect(textField.getAttribute('has-helper')).to.be.equal('slotted'); - }); - it('setting errorMessage updates has-error-message attribute', function() { textField.errorMessage = 'foo'; expect(textField.hasAttribute('has-error-message')).to.be.true; @@ -451,20 +395,11 @@ describe(`label ${condition}`, function() { it('should not update focused property on click if disabled', function() { textField.disabled = true; - const label = textField.root.querySelector('[part="label"]'); + const label = textField.shadowRoot.querySelector('[part="label"]'); label.click(); expect(textField.getAttribute('focused')).to.be.null; }); }); - - describe(`helper ${condition}`, function() { - it('should not update focused property on click if disabled', function() { - textField.disabled = true; - const helper = textField.root.querySelector('[part="helper-text"]'); - helper.click(); - expect(textField.getAttribute('focused')).to.be.null; - }); - }); } describe(`autoselect ${condition}`, function() { @@ -776,5 +711,75 @@ }); }); }); + + describe(`helper`, () => { + function dispatchHelperSlotChange(node) { + // Workaround not to use timeouts + const evt = new CustomEvent('slotchange'); + node.shadowRoot.querySelector('[name="helper"]').dispatchEvent(evt); + } + + it('setting helper with slot updates has-helper attribute', function() { + const textField = fixture(`default`); + const helper = document.createElement('div'); + helper.setAttribute('slot', 'helper'); + helper.textContent = 'foo'; + textField.appendChild(helper); + dispatchHelperSlotChange(textField); + + expect(textField.hasAttribute('has-helper')).to.be.true; + }); + + it('text-field with slotted helper updates has-helper attribute', function() { + const textFieldSlottedHelper = fixture('default-with-slotted-helper'); + dispatchHelperSlotChange(textFieldSlottedHelper); + expect(textFieldSlottedHelper.hasAttribute('has-helper')).to.be.true; + }); + + it('removing slotted helper removes has-helper attribute', function() { + const textFieldSlottedHelper = fixture('default-with-slotted-helper'); + const helper = textFieldSlottedHelper.querySelector('[slot="helper"]'); + textFieldSlottedHelper.removeChild(helper); + dispatchHelperSlotChange(textFieldSlottedHelper); + expect(textFieldSlottedHelper.hasAttribute('has-helper')).to.be.false; + }); + + it('should not get focus after helper click', function() { + const textFieldSlottedHelper = fixture('default-with-slotted-helper'); + const spy = sinon.spy(textFieldSlottedHelper, 'focus'); + const helper = textFieldSlottedHelper.querySelector('[slot="helper"]'); + + helper.click(); + + expect(spy.called).to.be.false; + }); + + it('should not add "has-helper" with a slotted "slot" element', function() { + const xElement = fixture('custom-element-with-slotted-helper'); + const textField = xElement.$.textField; + expect(textField.hasAttribute('has-helper')).to.be.false; + }); + + it('should add "has-helper" when slotted "slot" and custom element sets string property', function() { + const xElement = fixture('custom-element-with-slotted-helper'); + const textField = xElement.$.textField; + xElement.helperText = 'helper text'; + expect(textField.hasAttribute('has-helper')).to.be.true; + }); + + it('should add "has-helper=slotted" when slotted "slot" and custom element sets content to slot', function() { + const xElement = fixture('custom-element-with-slotted-helper'); + const textField = xElement.$.textField; + const span = document.createElement('span'); + span.textContent = 'helper text'; + span.setAttribute('slot', 'helper'); + xElement.appendChild(span); + dispatchHelperSlotChange(textField); + + expect(textField.hasAttribute('has-helper')).to.be.true; + expect(textField.getAttribute('has-helper')).to.be.equal('slotted'); + }); + + });