Skip to content

bugfix(Spinner): Spinner component size get's large when passing sx and size props #5236

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 5 commits into from
Nov 6, 2024
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
5 changes: 5 additions & 0 deletions .changeset/forty-rats-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Update Spinner component to correctly use the `size` prop when both `sx` and `size` are provided
2 changes: 1 addition & 1 deletion packages/react/src/Spinner/Spinner.dev.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export default {
component: Spinner,
} as Meta<typeof Spinner>

export const Default = () => <Spinner sx={{border: '1px solid red'}} />
export const Default = () => <Spinner sx={{border: '1px solid red'}} size="small" />
14 changes: 9 additions & 5 deletions packages/react/src/Spinner/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {HTMLDataAttributes} from '../internal/internal-types'
import {useId} from '../hooks'
import {useFeatureFlag} from '../FeatureFlags'
import classes from './Spinner.module.css'
import Box from '../Box'
import {clsx} from 'clsx'

const sizeMap = {
small: '16px',
Expand Down Expand Up @@ -87,17 +87,21 @@ const StyledComponentSpinner = styled(Spinner)`
${sx}
`

function StyledSpinner({sx, ...props}: SpinnerProps) {
const StyledBaseSpinner = styled.div`
${sx}
`

function StyledSpinner({sx, className, ...props}: SpinnerProps) {
const enabled = useFeatureFlag('primer_react_css_modules_team')
if (enabled) {
if (sx) {
return <Box sx={sx} as={Spinner} className={classes.SpinnerAnimation} {...props} />
return <StyledBaseSpinner sx={sx} as={Spinner} className={clsx(className, classes.SpinnerAnimation)} {...props} />
}

return <Spinner className={classes.SpinnerAnimation} {...props} />
return <Spinner className={clsx(className, classes.SpinnerAnimation)} {...props} />
Copy link
Member Author

Choose a reason for hiding this comment

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

Not related to the bug, but was pointed out that className was overwriting the CSS modules classname when being passed in, so I added this

}

return <StyledComponentSpinner sx={sx} {...props} />
return <StyledComponentSpinner sx={sx} className={className} {...props} />
}

StyledSpinner.displayName = 'Spinner'
Expand Down
Loading