From 4310aa1f7ca11193447d7a0fe71ca3568efc127c Mon Sep 17 00:00:00 2001 From: "Chris E. Kelley" Date: Tue, 6 Oct 2020 14:59:29 -0500 Subject: [PATCH] Fix for #warn-text bg color displaying when empty --- demo/index.html | 25 ++++++++++++++ input/tangy-input.js | 7 ++-- input/tangy-location.js | 15 +++++---- input/tangy-select.js | 73 +++++++++++++++++++---------------------- 4 files changed, 72 insertions(+), 48 deletions(-) diff --git a/demo/index.html b/demo/index.html index 1a24d767..5b67e359 100644 --- a/demo/index.html +++ b/demo/index.html @@ -249,6 +249,31 @@

Custom warning messages and custom warning logic

+ + + + + + + + + + + + diff --git a/input/tangy-input.js b/input/tangy-input.js index 61a47f2f..a51a3b94 100644 --- a/input/tangy-input.js +++ b/input/tangy-input.js @@ -37,11 +37,12 @@ export class TangyInput extends PolymerElement {
+
+
+
-
-
-
+ ` } diff --git a/input/tangy-location.js b/input/tangy-location.js index 26908030..9b4df231 100644 --- a/input/tangy-location.js +++ b/input/tangy-location.js @@ -669,12 +669,7 @@ class TangyLocation extends PolymerElement { : '' } -
- ${this.hasWarning - ? `
${ this.hasAttribute('warn-text') ? this.getAttribute('warn-text') : ''}
` - : '' - } -
+
${this.hasDiscrepancy ? `
${ this.hasAttribute('discrepancy-text') ? this.getAttribute('discrepancy-text') : ''}
` @@ -821,6 +816,14 @@ class TangyLocation extends PolymerElement { this.render() } } + + onWarnChange(value) { + if (this.shadowRoot.querySelector('#warn-text')) { + this.shadowRoot.querySelector('#warn-text').innerHTML = this.hasWarning + ? `
${ this.hasAttribute('warn-text') ? this.getAttribute('warn-text') : ''}
` + : '' + } + } } diff --git a/input/tangy-select.js b/input/tangy-select.js index 184bcd92..3576614d 100644 --- a/input/tangy-select.js +++ b/input/tangy-select.js @@ -20,21 +20,19 @@ class TangySelect extends PolymerElement { - -
-
+
+
+
+
`; @@ -107,8 +105,8 @@ class TangySelect extends PolymerElement { }, invalid: { type: Boolean, - observer: 'onInvalidChange', value: false, + observer: 'onInvalidChange', reflectToAttribute: true }, incomplete: { @@ -175,25 +173,6 @@ class TangySelect extends PolymerElement {
- -
- ${this.hasWarning - ? `
${ this.hasAttribute('warn-text') ? this.getAttribute('warn-text') : ''}
` - : '' - } -
-
- ${this.hasDiscrepancy - ? `
${ this.hasAttribute('discrepancy-text') ? this.getAttribute('discrepancy-text') : ''}
` - : '' - } -
` this._onChangeListener = this .shadowRoot @@ -202,15 +181,6 @@ class TangySelect extends PolymerElement { this.dispatchEvent(new CustomEvent('render')) } - onInvalidChange(value) { - // @TODO I'm not sure this hook is what ends up causing the error message to be displayed. - if (this.shadowRoot.querySelector('#error-text')) { - this.shadowRoot.querySelector('#error-text').innerHTML = this.invalid - ? `
${ this.hasAttribute('error-text') ? this.getAttribute('error-text') : ''}
` - : '' - } - } - onChange(event) { this.value = event.target.value this.dispatchEvent(new CustomEvent('change')) @@ -233,5 +203,30 @@ class TangySelect extends PolymerElement { } } + onInvalidChange(value) { + // @TODO I'm not sure this hook is what ends up causing the error message to be displayed. + if (this.shadowRoot.querySelector('#error-text')) { + this.shadowRoot.querySelector('#error-text').innerHTML = this.invalid + ? `
${ this.hasAttribute('error-text') ? this.getAttribute('error-text') : ''}
` + : '' + } + } + + onDiscrepancyChange(value) { + if (this.shadowRoot.querySelector('#discrepancy-text')) { + this.shadowRoot.querySelector('#discrepancy-text').innerHTML = this.hasDiscrepancy + ? `
${ this.hasAttribute('discrepancy-text') ? this.getAttribute('discrepancy-text') : ''}
` + : '' + } + } + + onWarnChange(value) { + if (this.shadowRoot.querySelector('#warn-text')) { + this.shadowRoot.querySelector('#warn-text').innerHTML = this.hasWarning + ? `
${ this.hasAttribute('warn-text') ? this.getAttribute('warn-text') : ''}
` + : '' + } + } + } window.customElements.define(TangySelect.is, TangySelect);