Skip to content

Commit

Permalink
fix: handle required disabled field hints (#1990)
Browse files Browse the repository at this point in the history
- update snapshots and tests
  • Loading branch information
booc0mtaco authored Jun 12, 2024
1 parent 300af06 commit 11c0883
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 19 deletions.
13 changes: 13 additions & 0 deletions src/components/InputField/InputField-v2.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ export const Required: Story = {
},
};

/**
* Fields can be marked as required.
*/
export const RequiredDisabled: Story = {
args: {
label: 'Input field with fieldNote',
showHint: true,
required: true,
disabled: true,
fieldNote: 'This is a fieldnote for a required input field.',
},
};

/**
* When not using a visible label with `InputField`, you must apply some time of ARIA label to the component, like `aria-label`.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/components/InputField/InputField-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export const InputField: InputFieldType = forwardRef(
)}
{required && showHint && (
<Text
aria-disabled={disabled ?? undefined}
as="span"
className={requiredTextClassName}
preset="body-sm"
Expand All @@ -258,6 +259,7 @@ export const InputField: InputFieldType = forwardRef(
)}
{!required && showHint && (
<Text
aria-disabled={disabled ?? undefined}
as="span"
className={requiredTextClassName}
preset="body-sm"
Expand Down
82 changes: 65 additions & 17 deletions src/components/InputField/__snapshots__/InputField-v2.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ exports[`<InputField /> InputWithin story renders snapshot 1`] = `
>
<label
class="label label--lg input-field__label"
for=":ro:"
for=":rq:"
>
Input field with button inside
</label>
Expand All @@ -156,7 +156,7 @@ exports[`<InputField /> InputWithin story renders snapshot 1`] = `
<input
aria-invalid="false"
class="input input-field__input--input-within"
id=":ro:"
id=":rq:"
type="text"
/>
<div
Expand Down Expand Up @@ -264,18 +264,18 @@ exports[`<InputField /> NoVisibleLabel story renders snapshot 1`] = `
class="input-field__body input-field--has-fieldNote"
>
<input
aria-describedby=":rj:"
aria-describedby=":rl:"
aria-invalid="false"
aria-label="Input for no visible label"
class="input"
id=":ri:"
id=":rk:"
required=""
type="text"
/>
</div>
<div
class="field-note"
id=":rj:"
id=":rl:"
>
This input field has no visible label
</div>
Expand All @@ -295,7 +295,7 @@ exports[`<InputField /> Password story renders snapshot 1`] = `
>
<label
class="label label--lg input-field__label"
for=":rk:"
for=":rm:"
>
Password
</label>
Expand All @@ -306,7 +306,7 @@ exports[`<InputField /> Password story renders snapshot 1`] = `
<input
aria-invalid="false"
class="input"
id=":rk:"
id=":rm:"
type="password"
/>
</div>
Expand Down Expand Up @@ -398,6 +398,54 @@ exports[`<InputField /> Required story renders snapshot 1`] = `
</div>
`;

exports[`<InputField /> RequiredDisabled story renders snapshot 1`] = `
<div
class="p-8"
>
<div
class="w-96"
>
<div
class="input-field__overline"
>
<label
aria-disabled="true"
class="label label--lg label--disabled input-field__label input-field__label--disabled"
for=":ri:"
>
Input field with fieldNote
</label>
<span
aria-disabled="true"
class="text text--body-sm input-field__required-text input-field__required-text--disabled"
>
(Required)
</span>
</div>
<div
class="input-field__body input-field--has-fieldNote"
>
<input
aria-describedby=":rj:"
aria-invalid="false"
class="input"
disabled=""
id=":ri:"
required=""
type="text"
/>
</div>
<div
aria-disabled="true"
class="field-note field-note--disabled"
id=":rj:"
>
This is a fieldnote for a required input field.
</div>
</div>
</div>
`;

exports[`<InputField /> ShowHint story renders snapshot 1`] = `
<div
class="p-8"
Expand All @@ -410,7 +458,7 @@ exports[`<InputField /> ShowHint story renders snapshot 1`] = `
>
<label
class="label label--lg input-field__label"
for=":rm:"
for=":ro:"
>
Field with Optional Hint
</label>
Expand All @@ -426,7 +474,7 @@ exports[`<InputField /> ShowHint story renders snapshot 1`] = `
<input
aria-invalid="false"
class="input"
id=":rm:"
id=":ro:"
type="text"
/>
</div>
Expand Down Expand Up @@ -565,7 +613,7 @@ exports[`<InputField /> WithAMaxLength story renders snapshot 1`] = `
>
<label
class="label label--lg input-field__label"
for=":rq:"
for=":rs:"
>
test label
</label>
Expand All @@ -588,7 +636,7 @@ exports[`<InputField /> WithAMaxLength story renders snapshot 1`] = `
<input
aria-invalid="false"
class="input error"
id=":rq:"
id=":rs:"
maxlength="15"
required=""
type="text"
Expand All @@ -614,7 +662,7 @@ exports[`<InputField /> WithARecommendedLength story renders snapshot 1`] = `
>
<label
class="label label--lg input-field__label"
for=":rs:"
for=":ru:"
>
Shortened Length Field
</label>
Expand All @@ -637,7 +685,7 @@ exports[`<InputField /> WithARecommendedLength story renders snapshot 1`] = `
<input
aria-invalid="false"
class="input error"
id=":rs:"
id=":ru:"
required=""
type="text"
value="Some initial text"
Expand All @@ -662,7 +710,7 @@ exports[`<InputField /> WithBothMaxAndRecommendedLength story renders snapshot 1
>
<label
class="label label--lg input-field__label"
for=":ru:"
for=":r10:"
>
test label
</label>
Expand All @@ -683,10 +731,10 @@ exports[`<InputField /> WithBothMaxAndRecommendedLength story renders snapshot 1
class="input-field__body input-field--has-fieldNote"
>
<input
aria-describedby=":rv:"
aria-describedby=":r11:"
aria-invalid="false"
class="input error"
id=":ru:"
id=":r10:"
maxlength="20"
required=""
type="text"
Expand All @@ -698,7 +746,7 @@ exports[`<InputField /> WithBothMaxAndRecommendedLength story renders snapshot 1
>
<div
class="field-note field-note--error"
id=":rv:"
id=":r11:"
>
<svg
class="icon field-note__icon"
Expand Down
5 changes: 5 additions & 0 deletions src/components/Select/Select-v2.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
margin-bottom: 0.25rem;
}


/**
* Label on top of the select trigger button to label the select field.
*/
Expand Down Expand Up @@ -164,4 +165,8 @@
border-color: var(--eds-theme-color-border-utility-warning);
outline: calc(var(--eds-border-width-sm) * 1px) solid var(--eds-theme-color-border-utility-warning);
}
}

.select__required-text--disabled {
color: var(--eds-theme-color-text-utility-disabled-primary);
}
14 changes: 12 additions & 2 deletions src/components/Select/Select-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,22 @@ const SelectLabel = ({
{label}
</Listbox.Label>
{required && showHint && (
<Text as="span" className={requiredTextClassName} preset="body-sm">
<Text
aria-disabled={disabled ?? undefined}
as="span"
className={requiredTextClassName}
preset="body-sm"
>
(Required)
</Text>
)}
{!required && showHint && (
<Text as="span" className={requiredTextClassName} preset="body-sm">
<Text
aria-disabled={disabled ?? undefined}
as="span"
className={requiredTextClassName}
preset="body-sm"
>
(Optional)
</Text>
)}
Expand Down

0 comments on commit 11c0883

Please sign in to comment.