Skip to content

Commit

Permalink
feat(Radio): set correct styles when not using visible label
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptammergard committed May 11, 2023
1 parent 3b3c7f9 commit 8cd1624
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-pigs-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@einride/ui": minor
---

Radio: Set correct styles when not using visible label.
17 changes: 12 additions & 5 deletions packages/einride-ui/src/components/controls/radios/Radio/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,27 @@ export const Radio = forwardRef<HTMLInputElement, RadioProps>(
onChange={(value) => onCheckedChange?.(value.target.checked)}
ref={ref}
/>
<StyledLabel htmlFor={id} {...labelProps}>
{children}
</StyledLabel>
{children && (
<StyledLabel htmlFor={id} {...labelProps}>
{children}
</StyledLabel>
)}
</Wrapper>
)
},
)

const Wrapper = styled.div`
padding-block: ${({ theme }) => 1.5 * theme.spacingBase}rem;
padding-inline: ${({ theme }) => 2 * theme.spacingBase}rem;
padding: ${({ theme }) => 1.5 * theme.spacingBase}rem;
display: flex;
align-items: center;
gap: ${({ theme }) => 2 * theme.spacingBase}rem;
&:has(label) {
padding-inline: ${({ theme }) =>
2 * theme.spacingBase}rem; // increase inline padding when label is present
}
&:has(input:focus-visible) label {
text-decoration: underline;
}
Expand Down Expand Up @@ -87,5 +93,6 @@ const StyledInput = styled.input`
const StyledLabel = styled.label`
font-family: ${({ theme }) => theme.fonts.body};
font-size: ${({ theme }) => theme.fontSizes.md};
line-height: calc(4 / 3);
color: ${({ theme }) => theme.colors.content.primary};
`

0 comments on commit 8cd1624

Please sign in to comment.