Skip to content

Commit

Permalink
fix(FormControl): remove label equality check (#2509)
Browse files Browse the repository at this point in the history
* fix(FormControl): remove label equality check

* chore: add changeset

* test: update snapshots
  • Loading branch information
joshblack committed Nov 1, 2022
1 parent daabc08 commit cbcc022
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-eels-mix.md
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Update FormControl to correctly render Checkbox labels
4 changes: 1 addition & 3 deletions src/FormControl/FormControl.tsx
Expand Up @@ -182,9 +182,7 @@ const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
{slots.LeadingVisual}
</Box>
)}
{(React.isValidElement(slots.Label) &&
slots.Label.type === FormControlLabel &&
!(slots.Label.props as FormControlLabelProps).visuallyHidden) ||
{(React.isValidElement(slots.Label) && !(slots.Label.props as FormControlLabelProps).visuallyHidden) ||
slots.Caption ? (
<Box display="flex" flexDirection="column" ml={2}>
{slots.Label}
Expand Down
52 changes: 39 additions & 13 deletions src/__tests__/__snapshots__/CheckboxGroup.test.tsx.snap
Expand Up @@ -24,12 +24,23 @@ exports[`CheckboxGroup renders consistently 1`] = `
margin-right: 0;
}
.c7 {
margin-left: 8px;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.c2 {
display: block;
font-size: 16px;
}
.c7 {
.c8 {
font-weight: 600;
font-size: 14px;
display: block;
Expand Down Expand Up @@ -114,12 +125,17 @@ exports[`CheckboxGroup renders consistently 1`] = `
value="one"
/>
</div>
<label
<div
className="c7"
htmlFor="react-aria-2"
display="flex"
>
Choice one
</label>
<label
className="c8"
htmlFor="react-aria-2"
>
Choice one
</label>
</div>
</div>
<div
className="c4"
Expand All @@ -141,12 +157,17 @@ exports[`CheckboxGroup renders consistently 1`] = `
value="two"
/>
</div>
<label
<div
className="c7"
htmlFor="react-aria-3"
display="flex"
>
Choice two
</label>
<label
className="c8"
htmlFor="react-aria-3"
>
Choice two
</label>
</div>
</div>
<div
className="c4"
Expand All @@ -168,12 +189,17 @@ exports[`CheckboxGroup renders consistently 1`] = `
value="three"
/>
</div>
<label
<div
className="c7"
htmlFor="react-aria-4"
display="flex"
>
Choice three
</label>
<label
className="c8"
htmlFor="react-aria-4"
>
Choice three
</label>
</div>
</div>
</div>
</fieldset>
Expand Down
52 changes: 39 additions & 13 deletions src/__tests__/__snapshots__/CheckboxOrRadioGroup.test.tsx.snap
Expand Up @@ -24,12 +24,23 @@ exports[`CheckboxOrRadioGroup renders consistently 1`] = `
margin-right: 0;
}
.c7 {
margin-left: 8px;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.c2 {
display: block;
font-size: 16px;
}
.c7 {
.c8 {
font-weight: 600;
font-size: 14px;
display: block;
Expand Down Expand Up @@ -114,12 +125,17 @@ exports[`CheckboxOrRadioGroup renders consistently 1`] = `
value="choiceOne"
/>
</div>
<label
<div
className="c7"
htmlFor="react-aria-2"
display="flex"
>
Choice one
</label>
<label
className="c8"
htmlFor="react-aria-2"
>
Choice one
</label>
</div>
</div>
<div
className="c4"
Expand All @@ -141,12 +157,17 @@ exports[`CheckboxOrRadioGroup renders consistently 1`] = `
value="choiceTwo"
/>
</div>
<label
<div
className="c7"
htmlFor="react-aria-3"
display="flex"
>
Choice two
</label>
<label
className="c8"
htmlFor="react-aria-3"
>
Choice two
</label>
</div>
</div>
<div
className="c4"
Expand All @@ -168,12 +189,17 @@ exports[`CheckboxOrRadioGroup renders consistently 1`] = `
value="choiceThree"
/>
</div>
<label
<div
className="c7"
htmlFor="react-aria-4"
display="flex"
>
Choice three
</label>
<label
className="c8"
htmlFor="react-aria-4"
>
Choice three
</label>
</div>
</div>
</div>
</fieldset>
Expand Down
52 changes: 39 additions & 13 deletions src/__tests__/__snapshots__/RadioGroup.test.tsx.snap
Expand Up @@ -24,12 +24,23 @@ exports[`RadioGroup renders consistently 1`] = `
margin-right: 0;
}
.c7 {
margin-left: 8px;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.c2 {
display: block;
font-size: 16px;
}
.c7 {
.c8 {
font-weight: 600;
font-size: 14px;
display: block;
Expand Down Expand Up @@ -114,12 +125,17 @@ exports[`RadioGroup renders consistently 1`] = `
value="one"
/>
</div>
<label
<div
className="c7"
htmlFor="react-aria-2"
display="flex"
>
Choice one
</label>
<label
className="c8"
htmlFor="react-aria-2"
>
Choice one
</label>
</div>
</div>
<div
className="c4"
Expand All @@ -141,12 +157,17 @@ exports[`RadioGroup renders consistently 1`] = `
value="two"
/>
</div>
<label
<div
className="c7"
htmlFor="react-aria-3"
display="flex"
>
Choice two
</label>
<label
className="c8"
htmlFor="react-aria-3"
>
Choice two
</label>
</div>
</div>
<div
className="c4"
Expand All @@ -168,12 +189,17 @@ exports[`RadioGroup renders consistently 1`] = `
value="three"
/>
</div>
<label
<div
className="c7"
htmlFor="react-aria-4"
display="flex"
>
Choice three
</label>
<label
className="c8"
htmlFor="react-aria-4"
>
Choice three
</label>
</div>
</div>
</div>
</fieldset>
Expand Down

0 comments on commit cbcc022

Please sign in to comment.