Skip to content

Let aria-required be undefined if not passed #4058

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

Merged
merged 4 commits into from
Dec 14, 2023
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
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}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We still use aria-required={required ? 'true' : 'false'} on Radio and Checkbox. Should we update those as well? Or are we worried this could also break tests in dotcom?

Copy link
Member

Choose a reason for hiding this comment

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

What are the broken tests?? 👀

Copy link
Member

Choose a reason for hiding this comment

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

There are some tests in dotcom that compare the dom, so any additional props even when false fail CI 🤦

Ideally they should not depend on attributes from within primer components, but it's common :(

Copy link
Member

@siddharthkp siddharthkp Dec 14, 2023

Choose a reason for hiding this comment

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

Or are we worried this could also break tests in dotcom?

Only one way to find out, going to run the integration tests for this PR

Update: Seems like there are no new errors 🎉 https://github.com/github/github/actions/runs/7208501227/job/19637623263

Copy link
Member

Choose a reason for hiding this comment

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

Just a quick question do we want to have aria-required="false" if required is passed but as false? (Example usage)

Or do we only want to have aria-required when it is only true?

Copy link
Member

@siddharthkp siddharthkp Dec 14, 2023

Choose a reason for hiding this comment

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

Or do we only want to have aria-required when it is only true?

yes :)

I asked Mike to create this PR because I found some snapshot tests in dotcom that compare the dom, so any additional props, even when false fail integration tests 🤦

{...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