Skip to content

Commit b55025c

Browse files
authoredJan 8, 2025··
chore(Radio): Remove CSS modules feature flag from Radio (#5463)
* Remove CSS modules feature flag from Radio * Skip As test * Create two-apples-juggle.md
1 parent b1e5699 commit b55025c

File tree

3 files changed

+35
-52
lines changed

3 files changed

+35
-52
lines changed
 

‎.changeset/two-apples-juggle.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": minor
3+
---
4+
5+
Remove CSS modules feature flag from Radio

‎packages/react/src/Radio/Radio.tsx

+29-51
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
import styled from 'styled-components'
21
import type {ChangeEventHandler, InputHTMLAttributes, ReactElement} from 'react'
32
import React, {useContext} from 'react'
43
import type {SxProp} from '../sx'
5-
import sx from '../sx'
64
import type {FormValidationStatus} from '../utils/types/FormValidationStatus'
75
import {RadioGroupContext} from '../RadioGroup/RadioGroup'
8-
import getGlobalFocusStyles from '../internal/utils/getGlobalFocusStyles'
9-
import {get} from '../constants'
10-
import {sharedCheckboxAndRadioStyles} from '../internal/utils/sharedCheckboxAndRadioStyles'
11-
import {toggleStyledComponent} from '../internal/utils/toggleStyledComponent'
12-
import {useFeatureFlag} from '../FeatureFlags'
136
import {clsx} from 'clsx'
147
import classes from './Radio.module.css'
158
import sharedClasses from '../Checkbox/shared.module.css'
9+
import {defaultSxProp} from '../utils/defaultSxProp'
10+
import Box from '../Box'
1611

1712
export type RadioProps = {
1813
/**
@@ -47,42 +42,6 @@ export type RadioProps = {
4742
} & InputHTMLAttributes<HTMLInputElement> &
4843
SxProp
4944

50-
const StyledRadio = toggleStyledComponent(
51-
'primer_react_css_modules_ga',
52-
'input',
53-
styled.input`
54-
${sharedCheckboxAndRadioStyles};
55-
border-radius: var(--borderRadius-full, 100vh);
56-
transition:
57-
background-color,
58-
border-color 80ms cubic-bezier(0.33, 1, 0.68, 1); /* checked -> unchecked - add 120ms delay to fully see animation-out */
59-
60-
&:checked {
61-
border-width: var(--base-size-4, 4px);
62-
border-color: var(
63-
--control-checked-bgColor-rest,
64-
${get('colors.accent.fg')}
65-
); /* using bgColor here to avoid a border change in dark high contrast */
66-
background-color: var(--control-checked-fgColor-rest, ${get('colors.fg.onEmphasis')});
67-
68-
&:disabled {
69-
cursor: not-allowed;
70-
border-color: ${get('colors.fg.muted')};
71-
background-color: ${get('colors.fg.muted')};
72-
}
73-
}
74-
75-
${getGlobalFocusStyles()};
76-
77-
@media (forced-colors: active) {
78-
background-color: canvastext;
79-
border-color: canvastext;
80-
}
81-
82-
${sx}
83-
`,
84-
)
85-
8645
/**
8746
* An accessible, native radio component for selecting one option from a list.
8847
*/
@@ -93,7 +52,7 @@ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
9352
disabled,
9453
name: nameProp,
9554
onChange,
96-
sx: sxProp,
55+
sx: sxProp = defaultSxProp,
9756
required,
9857
validationStatus,
9958
value,
@@ -103,7 +62,6 @@ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
10362
ref,
10463
): ReactElement => {
10564
const radioGroupContext = useContext(RadioGroupContext)
106-
const enabled = useFeatureFlag('primer_react_css_modules_ga')
10765
const handleOnChange: ChangeEventHandler<HTMLInputElement> = e => {
10866
radioGroupContext?.onChange && radioGroupContext.onChange(e)
10967
onChange && onChange(e)
@@ -117,8 +75,32 @@ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
11775
)
11876
}
11977

78+
if (sxProp !== defaultSxProp) {
79+
return (
80+
// eslint-disable-next-line github/a11y-role-supports-aria-props
81+
<Box
82+
as="input"
83+
sx={sxProp}
84+
type="radio"
85+
value={value}
86+
name={name}
87+
ref={ref}
88+
disabled={disabled}
89+
checked={checked}
90+
aria-checked={checked ? 'true' : 'false'}
91+
required={required}
92+
aria-required={required ? 'true' : 'false'}
93+
aria-invalid={validationStatus === 'error' ? 'true' : 'false'}
94+
onChange={handleOnChange}
95+
className={clsx(className, sharedClasses.Input, classes.Radio)}
96+
{...rest}
97+
/>
98+
)
99+
}
100+
120101
return (
121-
<StyledRadio
102+
// eslint-disable-next-line github/a11y-role-supports-aria-props
103+
<input
122104
type="radio"
123105
value={value}
124106
name={name}
@@ -129,12 +111,8 @@ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
129111
required={required}
130112
aria-required={required ? 'true' : 'false'}
131113
aria-invalid={validationStatus === 'error' ? 'true' : 'false'}
132-
sx={sxProp}
133114
onChange={handleOnChange}
134-
className={clsx(className, {
135-
[sharedClasses.Input]: enabled,
136-
[classes.Radio]: enabled,
137-
})}
115+
className={clsx(className, sharedClasses.Input, classes.Radio)}
138116
{...rest}
139117
/>
140118
)

‎packages/react/src/__tests__/Radio.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('Radio', () => {
1414
jest.resetAllMocks()
1515
})
1616

17-
behavesAsComponent({Component: Radio, toRender: () => <Radio {...defaultProps} />})
17+
behavesAsComponent({options: {skipAs: true}, Component: Radio, toRender: () => <Radio {...defaultProps} />})
1818

1919
checkExports('Radio', {
2020
default: Radio,

0 commit comments

Comments
 (0)
Please sign in to comment.