From fefcd5e37869173c554d28972ac9ba4da9ebadcd Mon Sep 17 00:00:00 2001 From: Jami Gibbs Date: Tue, 6 Aug 2024 10:57:41 -0500 Subject: [PATCH] reflect error prop in text-input for styling (#1255) --- .../va-statement-of-truth.tsx | 23 ++++--------------- .../va-text-input/va-text-input.tsx | 8 +++---- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/packages/web-components/src/components/va-statement-of-truth/va-statement-of-truth.tsx b/packages/web-components/src/components/va-statement-of-truth/va-statement-of-truth.tsx index 655d9fb63..b216776d2 100644 --- a/packages/web-components/src/components/va-statement-of-truth/va-statement-of-truth.tsx +++ b/packages/web-components/src/components/va-statement-of-truth/va-statement-of-truth.tsx @@ -20,9 +20,6 @@ import { shadow: true, }) export class VaStatementOfTruth { - private inputField: HTMLElement; - private checkboxField: HTMLElement; - /** * An optional custom header for the component */ @@ -110,19 +107,6 @@ export class VaStatementOfTruth { this.vaCheckboxChange.emit({ checked }); }; - /** - without this step the va-text-input and va-checkbox components will not - have an error attribute, which is used for styling. - */ - componentDidRender() { - if (this.inputError) { - this.inputField.setAttribute('error', this.inputError); - } - if (this.checkboxError) { - this.checkboxField.setAttribute('error', this.checkboxError); - } - } - render() { const { heading, @@ -131,6 +115,8 @@ export class VaStatementOfTruth { inputMessageAriaDescribedby, checked, inputValue, + inputError, + checkboxError, } = this; return ( @@ -150,7 +136,6 @@ export class VaStatementOfTruth { opens in a new window @@ -163,9 +148,9 @@ export class VaStatementOfTruth { value={inputValue} message-aria-describedby={inputMessageAriaDescribedby} required + error={inputError} onInput={this.handleInputChange} onBlur={this.handleInputBlur} - ref={field => (this.inputField = field)} /> (this.checkboxField = field)} /> diff --git a/packages/web-components/src/components/va-text-input/va-text-input.tsx b/packages/web-components/src/components/va-text-input/va-text-input.tsx index 8d7488ca1..8470a12e4 100644 --- a/packages/web-components/src/components/va-text-input/va-text-input.tsx +++ b/packages/web-components/src/components/va-text-input/va-text-input.tsx @@ -54,7 +54,7 @@ export class VaTextInput { /** * The error message to render. */ - @Prop() error?: string; + @Prop({ reflect: true }) error?: string; /** * Whether or not to add usa-input--error as class if error message is outside of component @@ -310,7 +310,7 @@ export class VaTextInput { private getInputmode(): string { if (this.currency) { return 'numeric'; - } + } return this.inputmode ? this.inputmode : undefined } @@ -454,7 +454,7 @@ export class VaTextInput { {currency &&
$
} {inputPrefix &&
{inputPrefix.substring(0, 25)}
} {inputIconPrefix &&
} - + ); } -} \ No newline at end of file +}