Skip to content

Commit

Permalink
Let aria-required be undefined if not passed (#4058)
Browse files Browse the repository at this point in the history
* skips rendering aria-required attr on inputs if it 'required' prop is undefined

* adds changeset

* Update light-frogs-leave.md

---------

Co-authored-by: Siddharth Kshetrapal <siddharthkp@github.com>
  • Loading branch information
mperrotti and siddharthkp authored Dec 14, 2023
1 parent 71baff3 commit 4d841b7
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 43 deletions.
7 changes: 7 additions & 0 deletions .changeset/light-frogs-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@primer/react': patch
---

TextInput, Textarea: Does not pass `aria-required` attribute to input or textarea if it is undefined. This fixes some tests that were breaking in dotcom.

<!-- Changed components: TextInput, Textarea -->
2 changes: 1 addition & 1 deletion src/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const TextInput = React.forwardRef<HTMLInputElement, TextInputProps>(
onFocus={handleInputFocus}
onBlur={handleInputBlur}
type={type}
aria-required={required ? 'true' : 'false'}
aria-required={required}
{...inputProps}
data-component="input"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/Textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
<StyledTextarea
value={value}
resize={resize}
aria-required={required ? 'true' : 'false'}
aria-required={required}
aria-invalid={validationStatus === 'error' ? 'true' : 'false'}
ref={ref}
disabled={disabled}
Expand Down
7 changes: 0 additions & 7 deletions src/__tests__/__snapshots__/Autocomplete.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ exports[`snapshots renders a custom empty state message 1`] = `
aria-expanded={false}
aria-haspopup="listbox"
aria-owns="autocompleteId-listbox"
aria-required="false"
autoComplete="off"
className="c2"
data-component="input"
Expand Down Expand Up @@ -286,7 +285,6 @@ exports[`snapshots renders a loading state 1`] = `
aria-expanded={false}
aria-haspopup="listbox"
aria-owns="autocompleteId-listbox"
aria-required="false"
autoComplete="off"
className="c2"
data-component="input"
Expand Down Expand Up @@ -505,7 +503,6 @@ exports[`snapshots renders a menu that contains an item to add to the menu 1`] =
aria-expanded={false}
aria-haspopup="listbox"
aria-owns="autocompleteId-listbox"
aria-required="false"
autoComplete="off"
className="c2"
data-component="input"
Expand Down Expand Up @@ -1278,7 +1275,6 @@ exports[`snapshots renders a multiselect input 1`] = `
aria-expanded={false}
aria-haspopup="listbox"
aria-owns="autocompleteId-listbox"
aria-required="false"
autoComplete="off"
className="c2"
data-component="input"
Expand Down Expand Up @@ -1954,7 +1950,6 @@ exports[`snapshots renders a multiselect input with selected menu items 1`] = `
aria-expanded={false}
aria-haspopup="listbox"
aria-owns="autocompleteId-listbox"
aria-required="false"
autoComplete="off"
className="c2"
data-component="input"
Expand Down Expand Up @@ -2764,7 +2759,6 @@ exports[`snapshots renders a single select input 1`] = `
aria-expanded={false}
aria-haspopup="listbox"
aria-owns="autocompleteId-listbox"
aria-required="false"
autoComplete="off"
className="c2"
data-component="input"
Expand Down Expand Up @@ -3793,7 +3787,6 @@ exports[`snapshots renders with an input value 1`] = `
aria-expanded={false}
aria-haspopup="listbox"
aria-owns="autocompleteId-listbox"
aria-required="false"
autoComplete="off"
className="c2"
data-component="input"
Expand Down
33 changes: 0 additions & 33 deletions src/__tests__/__snapshots__/TextInput.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ exports[`TextInput renders 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
name="zipcode"
Expand Down Expand Up @@ -243,7 +242,6 @@ exports[`TextInput renders block 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
name="zipcode"
Expand Down Expand Up @@ -366,7 +364,6 @@ exports[`TextInput renders consistently 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
onBlur={[Function]}
Expand Down Expand Up @@ -489,7 +486,6 @@ exports[`TextInput renders contrast 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
name="zipcode"
Expand Down Expand Up @@ -619,7 +615,6 @@ exports[`TextInput renders error 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
name="zipcode"
Expand Down Expand Up @@ -749,7 +744,6 @@ exports[`TextInput renders large 1`] = `
size="large"
>
<input
aria-required="false"
className="c2"
data-component="input"
name="zipcode"
Expand Down Expand Up @@ -898,7 +892,6 @@ exports[`TextInput renders leadingVisual 1`] = `
</svg>
</span>
<input
aria-required="false"
className="c2"
data-component="input"
name="search"
Expand Down Expand Up @@ -1048,7 +1041,6 @@ exports[`TextInput renders leadingVisual 2`] = `
</svg>
</span>
<input
aria-required="false"
className="c2"
data-component="input"
name="search"
Expand Down Expand Up @@ -1179,7 +1171,6 @@ exports[`TextInput renders leadingVisual 3`] = `
</div>
</span>
<input
aria-required="false"
className="c2"
data-component="input"
name="search"
Expand Down Expand Up @@ -1310,7 +1301,6 @@ exports[`TextInput renders leadingVisual 4`] = `
</div>
</span>
<input
aria-required="false"
className="c2"
data-component="input"
name="search"
Expand Down Expand Up @@ -1435,7 +1425,6 @@ exports[`TextInput renders monospace 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
name="zipcode"
Expand Down Expand Up @@ -1558,7 +1547,6 @@ exports[`TextInput renders placeholder 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
name="zipcode"
Expand Down Expand Up @@ -1691,7 +1679,6 @@ exports[`TextInput renders small 1`] = `
size="small"
>
<input
aria-required="false"
className="c2"
data-component="input"
name="zipcode"
Expand Down Expand Up @@ -2308,7 +2295,6 @@ exports[`TextInput renders trailingAction icon button 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
name="search"
Expand Down Expand Up @@ -2748,7 +2734,6 @@ exports[`TextInput renders trailingAction text button 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
name="search"
Expand Down Expand Up @@ -3394,7 +3379,6 @@ exports[`TextInput renders trailingAction text button with a tooltip 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
name="search"
Expand Down Expand Up @@ -3547,7 +3531,6 @@ exports[`TextInput renders trailingVisual 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
name="search"
Expand Down Expand Up @@ -3697,7 +3680,6 @@ exports[`TextInput renders trailingVisual 2`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
name="search"
Expand Down Expand Up @@ -3847,7 +3829,6 @@ exports[`TextInput renders trailingVisual 3`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
name="search"
Expand Down Expand Up @@ -3978,7 +3959,6 @@ exports[`TextInput renders trailingVisual 4`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
name="search"
Expand Down Expand Up @@ -4132,7 +4112,6 @@ exports[`TextInput renders with a loading indicator 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
onBlur={[Function]}
Expand Down Expand Up @@ -4355,7 +4334,6 @@ exports[`TextInput renders with a loading indicator 1`] = `
</div>
</span>
<input
aria-required="false"
className="c4"
data-component="input"
onBlur={[Function]}
Expand Down Expand Up @@ -4534,7 +4512,6 @@ exports[`TextInput renders with a loading indicator 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
onBlur={[Function]}
Expand Down Expand Up @@ -4797,7 +4774,6 @@ exports[`TextInput renders with a loading indicator 1`] = `
</div>
</span>
<input
aria-required="false"
className="c5"
data-component="input"
onBlur={[Function]}
Expand Down Expand Up @@ -5060,7 +5036,6 @@ exports[`TextInput renders with a loading indicator 1`] = `
</div>
</span>
<input
aria-required="false"
className="c5"
data-component="input"
onBlur={[Function]}
Expand Down Expand Up @@ -5323,7 +5298,6 @@ exports[`TextInput renders with a loading indicator 1`] = `
</div>
</span>
<input
aria-required="false"
className="c5"
data-component="input"
onBlur={[Function]}
Expand Down Expand Up @@ -5511,7 +5485,6 @@ exports[`TextInput renders with a loading indicator 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
onBlur={[Function]}
Expand Down Expand Up @@ -5774,7 +5747,6 @@ exports[`TextInput renders with a loading indicator 1`] = `
</div>
</span>
<input
aria-required="false"
className="c4"
data-component="input"
onBlur={[Function]}
Expand Down Expand Up @@ -5993,7 +5965,6 @@ exports[`TextInput renders with a loading indicator 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
onBlur={[Function]}
Expand Down Expand Up @@ -6305,7 +6276,6 @@ exports[`TextInput renders with a loading indicator 1`] = `
</div>
</span>
<input
aria-required="false"
className="c5"
data-component="input"
onBlur={[Function]}
Expand Down Expand Up @@ -6608,7 +6578,6 @@ exports[`TextInput renders with a loading indicator 1`] = `
</div>
</span>
<input
aria-required="false"
className="c5"
data-component="input"
onBlur={[Function]}
Expand Down Expand Up @@ -6918,7 +6887,6 @@ exports[`TextInput renders with a loading indicator 1`] = `
</div>
</span>
<input
aria-required="false"
className="c5"
data-component="input"
onBlur={[Function]}
Expand Down Expand Up @@ -7110,7 +7078,6 @@ exports[`TextInput should render a password input 1`] = `
onClick={[Function]}
>
<input
aria-required="false"
className="c2"
data-component="input"
name="password"
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/__snapshots__/Textarea.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ exports[`Textarea renders consistently 1`] = `
>
<textarea
aria-invalid="false"
aria-required="false"
className="c1"
cols={30}
rows={7}
Expand Down

0 comments on commit 4d841b7

Please sign in to comment.