Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

va-statement-of-truth: reflect error prop in va-text-input for styling #1255

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import {
shadow: true,
})
export class VaStatementOfTruth {
private inputField: HTMLElement;
private checkboxField: HTMLElement;

/**
* An optional custom header for the component
*/
Expand Down Expand Up @@ -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);
Copy link
Contributor Author

@jamigibbs jamigibbs Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the error prop now rendering as an attribute on the va-text-input component using reflect, this logic is no longer necessary.

}
if (this.checkboxError) {
this.checkboxField.setAttribute('error', this.checkboxError);
}
}

render() {
const {
heading,
Expand All @@ -131,6 +115,8 @@ export class VaStatementOfTruth {
inputMessageAriaDescribedby,
checked,
inputValue,
inputError,
checkboxError,
} = this;
return (
<Host>
Expand All @@ -150,7 +136,6 @@ export class VaStatementOfTruth {
<va-icon
class="privacy-policy-icon"
icon="launch"
size={2}
></va-icon>
<span class="usa-sr-only">opens in a new window</span>
</a>
Expand All @@ -163,18 +148,18 @@ export class VaStatementOfTruth {
value={inputValue}
message-aria-describedby={inputMessageAriaDescribedby}
required
error={inputError}
onInput={this.handleInputChange}
onBlur={this.handleInputBlur}
ref={field => (this.inputField = field)}
/>
<va-checkbox
id="veteran-certify"
name="veteran-certify"
label={checkboxLabel}
required
checked={checked}
error={checkboxError}
onVaChange={this.handleCheckboxChange}
ref={field => (this.checkboxField = field)}
/>
</article>
</Host>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class VaTextInput {
/**
* The error message to render.
*/
@Prop() error?: string;
@Prop({ reflect: true }) error?: string;
Copy link
Contributor Author

@jamigibbs jamigibbs Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reflect will add the prop to the component's markup in the DOM which is how the error styles are applied.

Reference: https://stenciljs.com/docs/properties#reflect-properties-values-to-attributes-reflect


/**
* Whether or not to add usa-input--error as class if error message is outside of component
Expand Down Expand Up @@ -310,7 +310,7 @@ export class VaTextInput {
private getInputmode(): string {
if (this.currency) {
return 'numeric';
}
}
return this.inputmode ? this.inputmode : undefined
}

Expand Down Expand Up @@ -454,7 +454,7 @@ export class VaTextInput {
{currency && <div id="symbol">$</div>}
{inputPrefix && <div class="usa-input-prefix" part="input-prefix">{inputPrefix.substring(0, 25)}</div>}
{inputIconPrefix && <div class="usa-input-prefix" part="input-prefix"><va-icon icon={inputIconPrefix} size={3} part="icon"></va-icon></div>}

<input
class={inputClass}
id="inputField"
Expand Down Expand Up @@ -498,4 +498,4 @@ export class VaTextInput {
</Host>
);
}
}
}
Loading