Visitar URL original
USWDS - Input: Add error state story by mahoneycm · Pull Request #5996 · uswds/uswds · GitHub
Skip to content
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
5 changes: 5 additions & 0 deletions packages/usa-input/src/usa-input.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ AriaDisabled.args = {
state: "aria-disabled",
};

export const Error = Template.bind({});
Error.args = {
Comment thread
amyleadem marked this conversation as resolved.
Resolved
state: "error",
};

export const StateShowcase = ShowcaseTemplate.bind({});
StateShowcase.argTypes = {
state: {
Expand Down
44 changes: 24 additions & 20 deletions packages/usa-input/src/usa-input.twig
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<label class="usa-label" for="input-type-text">Text input label</label>
{% if state == "error" %} <span class="usa-error-message" id="input-error-message" role="alert">Helpful error message</span>{%- endif %}
<input class="usa-input
{% if state == "focus" %} usa-focus{%- endif%}
{% if state == "error" %} usa-input--error{%- endif%}
{% if state == "success" %} usa-input--success{%- endif%}"
{% if state == "disabled" %} disabled{%- endif%}
{% if state == "aria-disabled" %} aria-disabled="true"{%- endif%}
id="input-type-text" name="input-type-text" type="text">
<label class="usa-label" for="input-type-textarea">Text area label</label>
{% if state == "error" %}
<span class="usa-error-message" id="textarea-error-message" role="alert">Helpful error message</span>
{%- endif %}
<textarea class="usa-textarea
{% if state == "focus" %} usa-focus{%- endif%}
{% if state == "error" %} usa-input--error{%- endif%}
{% if state == "success" %} usa-input--success{%- endif%}"
{% if state == "disabled" %} disabled{%- endif%}
{% if state == "aria-disabled" %} aria-disabled="true"{%- endif%}
id="input-type-textarea" name="input-type-textarea"></textarea>
{% if state == "error" %}<div class="usa-form-group usa-form-group--error">{%- endif %}
<label class="usa-label{% if state == "error" %} usa-label--error{%- endif %}" for="input-type-text">Text input label</label>
{% if state == "error" %} <span class="usa-error-message" id="input-error-message" role="alert">Helpful error message</span>{%- endif %}
<input class="usa-input
{% if state == "focus" %} usa-focus{%- endif%}
{% if state == "error" %} usa-input--error" aria-describedby="input-error-message{%- endif%}
{% if state == "success" %} usa-input--success{%- endif%}"
{% if state == "disabled" %} disabled{%- endif%}
{% if state == "aria-disabled" %} aria-disabled="true"{%- endif%}
id="input-type-text" name="input-type-text" type="text">
Comment thread
mahoneycm marked this conversation as resolved.
Resolved
{% if state == "error" %}</div>
<div class="usa-form-group usa-form-group--error">{%- endif %}
<label class="usa-label{% if state == "error" %} usa-label--error{%- endif %}" for="input-type-textarea">Text area label</label>
{% if state == "error" %}
<span class="usa-error-message" id="textarea-error-message" role="alert">Helpful error message</span>
{%- endif %}
<textarea class="usa-textarea
{% if state == "focus" %} usa-focus{%- endif%}
{% if state == "error" %} usa-input--error" aria-describedby="textarea-error-message{%- endif%}
{% if state == "success" %} usa-input--success{%- endif%}"
{% if state == "disabled" %} disabled{%- endif%}
{% if state == "aria-disabled" %} aria-disabled="true"{%- endif%}
id="input-type-textarea" name="input-type-textarea"></textarea>
{% if state == "error" %}</div>{%- endif %}