Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/wet-apples-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Correctly pass styled system typography and common props to the `Box` component in the `Text` component when the CSS modules feature flag is enabled.
13 changes: 9 additions & 4 deletions packages/react/src/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,21 @@ const StyledText = styled.span<StyledTextProps>`
${sx};
`

const includesSystemProps = (props: StyledTextProps) => {
return (
props.sx ||
Object.keys(props).some(prop => Object.keys(TYPOGRAPHY).includes(prop) || Object.keys(COMMON).includes(prop))
)
}
Comment thread
jonrohan marked this conversation as resolved.

const Text = forwardRef(({as: Component = 'span', className, size, weight, ...props}, forwardedRef) => {
const enabled = useFeatureFlag('primer_react_css_modules_ga')

const innerRef = React.useRef<HTMLElement>(null)
useRefObjectAsForwardedRef(forwardedRef, innerRef)

if (enabled) {
if (props.sx) {
// If props includes TYPOGRAPHY or COMMON props, pass them to the Box component
if (includesSystemProps(props)) {
return (
// @ts-ignore shh
<Box
Expand All @@ -81,7 +88,6 @@ const Text = forwardRef(({as: Component = 'span', className, size, weight, ...pr
}

return (
// @ts-ignore shh
<Component
className={clsx(className, classes.Text)}
data-size={size}
Expand All @@ -94,7 +100,6 @@ const Text = forwardRef(({as: Component = 'span', className, size, weight, ...pr
}

return (
// @ts-ignore shh
<StyledText
as={Component}
className={className}
Expand Down