Skip to content

Commit 2eeff36

Browse files
authored
Remove BoxWithFallback usage from VisuallyHidden (#6928)
1 parent c5c2053 commit 2eeff36

File tree

11 files changed

+85
-22
lines changed

11 files changed

+85
-22
lines changed

.changeset/tricky-boats-visit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': major
3+
---
4+
5+
Removes `sx` prop from VisuallyHidden component, and as a result also removes `sx` prop from CheckboxGroup.Label and RadioGroup.Label

packages/react/src/CheckboxGroup/CheckboxGroup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import FormControl from '../FormControl'
1010
import Checkbox from '../Checkbox/Checkbox'
1111
import {CheckboxGroupContext} from './CheckboxGroupContext'
1212

13-
type CheckboxGroupProps = {
13+
export type CheckboxGroupProps = {
1414
/**
1515
* An onChange handler that gets called when any of the checkboxes change
1616
*/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export {default, CheckboxGroupContext} from './CheckboxGroup'
1+
export {default, CheckboxGroupContext, type CheckboxGroupProps} from './CheckboxGroup'

packages/react/src/RadioGroup/RadioGroup.docs.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@
8484
"type": "boolean",
8585
"defaultValue": "false",
8686
"description": "If true, the fieldset legend will be visually hidden"
87-
},
88-
{
89-
"name": "sx",
90-
"type": "SystemStyleObject",
91-
"deprecated": true
9287
}
9388
]
9489
},
@@ -132,4 +127,4 @@
132127
]
133128
}
134129
]
135-
}
130+
}

packages/react/src/_VisuallyHidden.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
import classes from './_VisuallyHidden.module.css'
22
import {clsx} from 'clsx'
3-
import {BoxWithFallback} from './internal/components/BoxWithFallback'
4-
import type {SxProp} from './sx'
3+
import type {PolymorphicProps} from './utils/modern-polymorphic'
4+
import type {ElementType} from 'react'
55

6-
interface Props extends React.ComponentPropsWithoutRef<'span'> {
7-
isVisible?: boolean
8-
as?: React.ElementType
9-
}
6+
type VisuallyHiddenProps<As extends ElementType = 'span'> = PolymorphicProps<
7+
As,
8+
'span',
9+
{
10+
isVisible?: boolean
11+
}
12+
>
1013

11-
function VisuallyHidden({isVisible, children, as = 'span', className, ...rest}: Props & SxProp) {
14+
function VisuallyHidden<As extends ElementType = 'span'>({
15+
isVisible,
16+
children,
17+
as,
18+
className,
19+
...rest
20+
}: VisuallyHiddenProps<As>) {
21+
const Component = as || 'span'
1222
return (
13-
<BoxWithFallback as={as} className={clsx(className, {[classes.InternalVisuallyHidden]: !isVisible})} {...rest}>
23+
<Component className={clsx(className, {[classes.InternalVisuallyHidden]: !isVisible})} {...rest}>
1424
{children}
15-
</BoxWithFallback>
25+
</Component>
1626
)
1727
}
1828

packages/react/src/__tests__/__snapshots__/exports.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ exports[`@primer/react > should not update exports without a semver change 1`] =
5151
"type ButtonProps",
5252
"Checkbox",
5353
"CheckboxGroup",
54+
"type CheckboxGroupProps",
5455
"type CheckboxProps",
5556
"CircleBadge",
5657
"type CircleBadgeIconProps",

packages/react/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export {default as ButtonGroup} from './ButtonGroup'
8585
export type {ButtonGroupProps} from './ButtonGroup'
8686
export type {CircleBadgeProps, CircleBadgeIconProps} from './CircleBadge'
8787
export {default as CheckboxGroup} from './CheckboxGroup'
88+
export type {CheckboxGroupProps} from './CheckboxGroup'
8889
export {default as CircleBadge} from './CircleBadge'
8990
export {default as CounterLabel} from './CounterLabel'
9091
export type {CounterLabelProps} from './CounterLabel'

packages/react/src/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupLabel.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react'
22
import VisuallyHidden from '../../../_VisuallyHidden'
3-
import type {SxProp} from '../../../sx'
43
import CheckboxOrRadioGroupContext from './CheckboxOrRadioGroupContext'
54
import classes from './CheckboxOrRadioGroup.module.css'
65
import {Stack} from '../../../Stack'
@@ -13,13 +12,12 @@ export type CheckboxOrRadioGroupLabelProps = {
1312
* Whether to visually hide the fieldset legend
1413
*/
1514
visuallyHidden?: boolean
16-
} & SxProp
15+
}
1716

1817
const CheckboxOrRadioGroupLabel: React.FC<React.PropsWithChildren<CheckboxOrRadioGroupLabelProps>> = ({
1918
children,
2019
className,
2120
visuallyHidden = false,
22-
sx,
2321
}) => {
2422
const {required, disabled} = React.useContext(CheckboxOrRadioGroupContext)
2523

@@ -29,7 +27,6 @@ const CheckboxOrRadioGroupLabel: React.FC<React.PropsWithChildren<CheckboxOrRadi
2927
isVisible={!visuallyHidden}
3028
title={required ? 'required field' : undefined}
3129
data-label-disabled={disabled ? '' : undefined}
32-
sx={sx}
3330
>
3431
{required ? (
3532
<Stack direction="horizontal" gap="none">

packages/styled-react/src/__tests__/primer-react.browser.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ describe('@primer/react', () => {
143143
)
144144
})
145145

146+
test('CheckboxGroup.Label supports `sx` prop', () => {
147+
const {container} = render(<CheckboxGroup.Label data-testid="component" sx={{background: 'red'}} />)
148+
expect(window.getComputedStyle(container.firstElementChild!).backgroundColor).toBe('rgb(255, 0, 0)')
149+
})
150+
146151
test('CircleBadge supports `sx` prop', () => {
147152
render(<CircleBadge data-testid="component" sx={{background: 'red'}} />)
148153
expect(window.getComputedStyle(screen.getByTestId('component')).backgroundColor).toBe('rgb(255, 0, 0)')
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {
2+
Box,
3+
CheckboxGroup as PrimerCheckboxGroup,
4+
type CheckboxGroupProps as PrimerCheckboxGroupProps,
5+
} from '@primer/react'
6+
import React, {type PropsWithChildren} from 'react'
7+
import type {SxProp} from '../sx'
8+
9+
export type CheckboxGroupProps = PropsWithChildren<PrimerCheckboxGroupProps> & SxProp
10+
11+
const CheckboxGroupImpl = (props: CheckboxGroupProps) => {
12+
return <Box as={PrimerCheckboxGroup} {...props} />
13+
}
14+
15+
// Define local types based on the internal component props
16+
type CheckboxOrRadioGroupLabelProps = PropsWithChildren<
17+
{
18+
className?: string
19+
visuallyHidden?: boolean
20+
} & SxProp
21+
>
22+
const CheckboxOrRadioGroupLabel = (props: CheckboxOrRadioGroupLabelProps) => {
23+
return <Box as={PrimerCheckboxGroup.Label} {...props} />
24+
}
25+
26+
type CheckboxOrRadioGroupCaptionProps = PropsWithChildren<
27+
{
28+
className?: string
29+
} & SxProp
30+
>
31+
const CheckboxOrRadioGroupCaption = (props: CheckboxOrRadioGroupCaptionProps) => {
32+
return <Box as={PrimerCheckboxGroup.Caption} {...props} />
33+
}
34+
35+
type CheckboxOrRadioGroupValidationProps = PropsWithChildren<
36+
{
37+
className?: string
38+
variant: 'error' | 'success'
39+
} & SxProp
40+
>
41+
const CheckboxOrRadioGroupValidation = (props: CheckboxOrRadioGroupValidationProps) => {
42+
return <Box as={PrimerCheckboxGroup.Validation} {...props} />
43+
}
44+
45+
export const CheckboxGroup = Object.assign(CheckboxGroupImpl, {
46+
Label: CheckboxOrRadioGroupLabel,
47+
Caption: CheckboxOrRadioGroupCaption,
48+
Validation: CheckboxOrRadioGroupValidation,
49+
})

0 commit comments

Comments
 (0)