Skip to content

Commit 8bb78e1

Browse files
authored
Remove the CSS modules feature flag from the Hidden component (#5683)
* Remove the CSS modules feature flag from the Hidden component * Create violet-ladybugs-melt.md * Remove unused imports
1 parent 51c28f6 commit 8bb78e1

File tree

4 files changed

+29
-47
lines changed

4 files changed

+29
-47
lines changed

.changeset/violet-ladybugs-melt.md

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

packages/react/src/Hidden/Hidden.test.tsx

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import React from 'react'
22
import {render} from '@testing-library/react'
33
import {Hidden} from '.'
44
import MatchMediaMock from 'jest-matchmedia-mock'
5-
import {behavesAsComponent, checkExports, renderStyles, checkStoriesForAxeViolations} from '../utils/testing'
6-
import {mediaQueries} from '../utils/layout'
5+
import {behavesAsComponent, checkExports, checkStoriesForAxeViolations} from '../utils/testing'
76

87
let matchMedia: MatchMediaMock
98
describe('Hidden', () => {
@@ -40,37 +39,31 @@ describe('Hidden', () => {
4039
})
4140

4241
it('renders the styles as expected when a single viewport value is provided as a string via `when` prop', () => {
43-
const expectedStyles = {
44-
// `.replace` is used because renderStyles return the JSON object without a space after the column
45-
[`${mediaQueries.regular.replace(': ', ':')}`]: {
46-
display: 'none',
47-
},
48-
}
49-
expect(
50-
renderStyles(
42+
const hiddenElement = render(
43+
<div data-testid="hidden-regular">
5144
<Hidden when="regular">
5245
<div>This is hidden when regular viewports</div>
53-
</Hidden>,
54-
),
55-
).toEqual(expect.objectContaining(expectedStyles))
46+
</Hidden>
47+
</div>,
48+
)
49+
expect(hiddenElement.getAllByTestId('hidden-regular')[0].firstChild).toHaveAttribute(
50+
'style',
51+
'--hiddenDisplay-regular: none;',
52+
)
5653
})
5754

5855
it('renders the styles as expected when multiple viewport values are provided as an array via `when` prop', () => {
59-
const expectedStyles = {
60-
[`${mediaQueries.narrow.replace(': ', ':')}`]: {
61-
display: 'none',
62-
},
63-
[`${mediaQueries.wide.replace(': ', ':')}`]: {
64-
display: 'none',
65-
},
66-
}
67-
expect(
68-
renderStyles(
56+
const hiddenElement = render(
57+
<div data-testid="hidden-regular">
6958
<Hidden when={['narrow', 'wide']}>
70-
<div>This is hidden when regular and wide viewports</div>
71-
</Hidden>,
72-
),
73-
).toEqual(expect.objectContaining(expectedStyles))
59+
<div>This is hidden when regular viewports</div>
60+
</Hidden>
61+
</div>,
62+
)
63+
expect(hiddenElement.getAllByTestId('hidden-regular')[0].firstChild).toHaveAttribute(
64+
'style',
65+
'--hiddenDisplay-narrow: none; --hiddenDisplay-wide: none;',
66+
)
7467
})
7568
})
7669

packages/react/src/Hidden/Hidden.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import React, {type CSSProperties} from 'react'
22
import {clsx} from 'clsx'
33
import type {ResponsiveValue} from '../hooks/useResponsiveValue'
4-
import {getBreakpointDeclarations} from '../utils/getBreakpointDeclarations'
5-
import Box from '../Box'
6-
import {useFeatureFlag} from '../FeatureFlags'
74
import classes from './Hidden.module.css'
85

9-
const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_staff'
10-
116
type Viewport = 'narrow' | 'regular' | 'wide'
127

138
export type HiddenProps = {
@@ -39,15 +34,11 @@ function normalize(hiddenViewports: Array<Viewport> | Viewport): ResponsiveValue
3934
}
4035

4136
export const Hidden = ({when, className, style, children}: HiddenProps) => {
42-
const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG)
4337
const normalizedStyles = normalize(when)
4438

45-
// Get breakpoint declarations for the normalized ResponsiveValue object
46-
const breakpointSx = getBreakpointDeclarations(normalizedStyles, 'display', () => 'none')
47-
48-
return enabled ? (
39+
return (
4940
<div
50-
className={clsx(className, {[classes.Hidden]: enabled})}
41+
className={clsx(className, classes.Hidden)}
5142
style={
5243
{
5344
'--hiddenDisplay-narrow': normalizedStyles.narrow ? 'none' : undefined,
@@ -59,8 +50,6 @@ export const Hidden = ({when, className, style, children}: HiddenProps) => {
5950
>
6051
{children}
6152
</div>
62-
) : (
63-
<Box sx={breakpointSx}>{children}</Box>
6453
)
6554
}
6655

packages/react/src/Hidden/__snapshots__/Hidden.test.tsx.snap

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Hidden renders \`when\` prop as expected 1`] = `
4-
@media screen and (max-width:calc(768px - 0.02px)) {
5-
.c0 {
6-
display: none;
7-
}
8-
}
9-
104
<div>
115
<div
12-
class="c0"
6+
class="Hidden"
7+
style="--hiddenDisplay-narrow: none;"
138
>
149
<div>
1510
Hidden when narrow

0 commit comments

Comments
 (0)