Skip to content

Commit 237186a

Browse files
authored
chore(Select): Remove the CSS modules feature flag from the Select component (#6015)
1 parent 2b2b541 commit 237186a

File tree

3 files changed

+17
-126
lines changed

3 files changed

+17
-126
lines changed

.changeset/loose-planes-mix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': minor
3+
---
4+
5+
Remove the CSS modules feature flag from the Select component

packages/react/src/Select/Select.tsx

Lines changed: 12 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,18 @@
11
import React from 'react'
2-
import styled from 'styled-components'
32
import {clsx} from 'clsx'
43
import type {StyledWrapperProps} from '../internal/components/TextInputWrapper'
54
import TextInputWrapper from '../internal/components/TextInputWrapper'
6-
import {toggleStyledComponent} from '../internal/utils/toggleStyledComponent'
7-
import {useFeatureFlag} from '../FeatureFlags'
85
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
96

107
import classes from './Select.module.css'
118

129
export type SelectProps = Omit<
13-
Omit<React.ComponentPropsWithoutRef<'select'>, 'size'> & Omit<StyledWrapperProps, 'variant'>,
10+
Omit<React.ComponentProps<'select'>, 'size'> & Omit<StyledWrapperProps, 'variant'>,
1411
'multiple' | 'hasLeadingVisual' | 'hasTrailingVisual' | 'as'
1512
> & {
1613
placeholder?: string
1714
}
1815

19-
const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_ga'
20-
21-
const arrowRightOffset = '4px'
22-
23-
const StyledSelect = toggleStyledComponent(
24-
CSS_MODULES_FEATURE_FLAG,
25-
'select',
26-
styled.select`
27-
appearance: none;
28-
border-radius: inherit;
29-
border: 0;
30-
color: currentColor;
31-
font-size: inherit;
32-
outline: none;
33-
width: 100%;
34-
35-
/* Firefox hacks: */
36-
/* 1. Makes Firefox's native dropdown menu's background match the theme.
37-
38-
background-color should be 'transparent', but Firefox uses the background-color on
39-
<select> to determine the background color used for the dropdown menu.
40-
41-
2. Adds 1px margins to the <select> so the background color doesn't hide the focus outline created with an inset box-shadow.
42-
*/
43-
background-color: inherit;
44-
margin-top: 1px;
45-
margin-left: 1px;
46-
margin-bottom: 1px;
47-
48-
/* 2. Prevents visible overlap of partially transparent background colors.
49-
50-
'colors.input.disabledBg' happens to be partially transparent in light mode, so we use a
51-
transparent background-color on a disabled <select>. */
52-
&:disabled {
53-
background-color: transparent;
54-
}
55-
56-
/* 3. Maintain dark bg color in Firefox on Windows high-contrast mode
57-
58-
Firefox makes the <select>'s background color white when setting 'background-color: transparent;' */
59-
@media screen and (forced-colors: active) {
60-
&:disabled {
61-
background-color: -moz-combobox;
62-
}
63-
}
64-
`,
65-
)
66-
6716
const ArrowIndicatorSVG: React.FC<React.PropsWithChildren<{className?: string}>> = ({className}) => {
6817
return (
6918
<svg
@@ -79,83 +28,33 @@ const ArrowIndicatorSVG: React.FC<React.PropsWithChildren<{className?: string}>>
7928
)
8029
}
8130

82-
const StyledArrowIndicatorSVG = styled(ArrowIndicatorSVG)`
83-
pointer-events: none;
84-
position: absolute;
85-
right: ${arrowRightOffset};
86-
top: 50%;
87-
transform: translateY(-50%);
88-
`
89-
9031
const ArrowIndicator: React.FC<{className?: string}> = ({className}) => {
91-
const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG)
92-
if (enabled) {
93-
return <ArrowIndicatorSVG className={clsx(classes.ArrowIndicator, className)} />
94-
}
95-
96-
return <StyledArrowIndicatorSVG />
32+
return <ArrowIndicatorSVG className={clsx(classes.ArrowIndicator, className)} />
9733
}
9834

9935
const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
100-
({block, children, contrast, disabled, placeholder, size, required, validationStatus, ...rest}: SelectProps, ref) => {
101-
const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG)
102-
if (enabled) {
103-
return (
104-
<TextInputWrapper
105-
block={block}
106-
contrast={contrast}
107-
disabled={disabled}
108-
size={size}
109-
validationStatus={validationStatus}
110-
className={classes.TextInputWrapper}
111-
sx={rest.sx}
112-
>
113-
<StyledSelect
114-
ref={ref}
115-
required={required}
116-
disabled={disabled}
117-
aria-invalid={validationStatus === 'error' ? 'true' : 'false'}
118-
data-hasplaceholder={Boolean(placeholder)}
119-
defaultValue={placeholder ?? undefined}
120-
className={clsx(classes.Select, disabled && classes.Disabled)}
121-
{...rest}
122-
>
123-
{placeholder && (
124-
<option value="" disabled={required} hidden={required}>
125-
{placeholder}
126-
</option>
127-
)}
128-
{children}
129-
</StyledSelect>
130-
<ArrowIndicator className={classes.ArrowIndicator} />
131-
</TextInputWrapper>
132-
)
133-
}
134-
36+
(
37+
{block, children, contrast, disabled, placeholder, size, required, validationStatus, sx, ...rest}: SelectProps,
38+
ref,
39+
) => {
13540
return (
13641
<TextInputWrapper
137-
sx={{
138-
overflow: 'hidden',
139-
position: 'relative',
140-
'@media screen and (forced-colors: active)': {
141-
svg: {
142-
fill: disabled ? 'GrayText' : 'FieldText',
143-
},
144-
},
145-
}}
14642
block={block}
14743
contrast={contrast}
14844
disabled={disabled}
14945
size={size}
15046
validationStatus={validationStatus}
47+
className={classes.TextInputWrapper}
48+
sx={sx}
15149
>
152-
<StyledSelect
50+
<select
15351
ref={ref}
15452
required={required}
15553
disabled={disabled}
15654
aria-invalid={validationStatus === 'error' ? 'true' : 'false'}
15755
data-hasplaceholder={Boolean(placeholder)}
15856
defaultValue={placeholder ?? undefined}
57+
className={clsx(classes.Select, disabled && classes.Disabled)}
15958
{...rest}
16059
>
16160
{placeholder && (
@@ -164,8 +63,8 @@ const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
16463
</option>
16564
)}
16665
{children}
167-
</StyledSelect>
168-
<ArrowIndicator />
66+
</select>
67+
<ArrowIndicator className={classes.ArrowIndicator} />
16968
</TextInputWrapper>
17069
)
17170
},

packages/react/src/__tests__/Select.test.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react'
22
import {Select} from '..'
33
import {render} from '@testing-library/react'
4-
import {FeatureFlags} from '../FeatureFlags'
54
import userEvent from '@testing-library/user-event'
65

76
describe('Select', () => {
@@ -19,19 +18,7 @@ describe('Select', () => {
1918
</Select>
2019
</>
2120
)
22-
const FeatureFlagElement = () => {
23-
return (
24-
<FeatureFlags
25-
flags={{
26-
primer_react_css_modules_ga: true,
27-
}}
28-
>
29-
<Element />
30-
</FeatureFlags>
31-
)
32-
}
3321
expect(render(<Element />).getAllByTestId('select-default')[0]).toHaveClass('test-class-name')
34-
expect(render(<FeatureFlagElement />).getAllByTestId('select-default')[0]).toHaveClass('test-class-name')
3522
})
3623

3724
it('renders a select input', () => {

0 commit comments

Comments
 (0)