Skip to content

Commit 602b29a

Browse files
Revert "Clean up the feature flag for primer_react_segmented_control_tooltip" (#6412)
1 parent 897374d commit 602b29a

File tree

4 files changed

+83
-33
lines changed

4 files changed

+83
-33
lines changed

.changeset/strong-mangos-rest.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/react/src/FeatureFlags/DefaultFeatureFlags.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const DefaultFeatureFlags = FeatureFlagScope.create({
55
primer_react_action_list_item_as_button: false,
66
primer_react_select_panel_with_modern_action_list: false,
77
primer_react_overlay_overflow: false,
8+
primer_react_segmented_control_tooltip: false,
89
primer_react_select_panel_fullscreen_on_narrow: false,
910
primer_react_select_panel_order_selected_at_top: false,
1011
})

packages/react/src/SegmentedControl/SegmentedControl.test.tsx

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {describe, expect, it, vi} from 'vitest'
55
import BaseStyles from '../BaseStyles'
66
import theme from '../theme'
77
import ThemeProvider from '../ThemeProvider'
8+
import {FeatureFlags} from '../FeatureFlags'
89
import {SegmentedControl} from '../SegmentedControl'
910

1011
const segmentData = [
@@ -143,13 +144,19 @@ describe('SegmentedControl', () => {
143144
}
144145
})
145146

146-
it('renders icon button with tooltip as label', () => {
147+
it('renders icon button with tooltip as label when feature flag is enabled', () => {
147148
const {getByRole, getByText} = render(
148-
<SegmentedControl aria-label="File view">
149-
{segmentData.map(({label, icon}) => (
150-
<SegmentedControl.IconButton icon={icon} aria-label={label} key={label} />
151-
))}
152-
</SegmentedControl>,
149+
<FeatureFlags
150+
flags={{
151+
primer_react_segmented_control_tooltip: true,
152+
}}
153+
>
154+
<SegmentedControl aria-label="File view">
155+
{segmentData.map(({label, icon}) => (
156+
<SegmentedControl.IconButton icon={icon} aria-label={label} key={label} />
157+
))}
158+
</SegmentedControl>
159+
</FeatureFlags>,
153160
)
154161

155162
for (const datum of segmentData) {
@@ -160,13 +167,19 @@ describe('SegmentedControl', () => {
160167
}
161168
})
162169

163-
it('renders icon button with tooltip description', () => {
170+
it('renders icon button with tooltip description when feature flag is enabled', () => {
164171
const {getByRole, getByText} = render(
165-
<SegmentedControl aria-label="File view">
166-
{segmentData.map(({label, icon, description}) => (
167-
<SegmentedControl.IconButton icon={icon} aria-label={label} description={description} key={label} />
168-
))}
169-
</SegmentedControl>,
172+
<FeatureFlags
173+
flags={{
174+
primer_react_segmented_control_tooltip: true,
175+
}}
176+
>
177+
<SegmentedControl aria-label="File view">
178+
{segmentData.map(({label, icon, description}) => (
179+
<SegmentedControl.IconButton icon={icon} aria-label={label} description={description} key={label} />
180+
))}
181+
</SegmentedControl>
182+
</FeatureFlags>,
170183
)
171184

172185
for (const datum of segmentData) {
@@ -178,6 +191,21 @@ describe('SegmentedControl', () => {
178191
}
179192
})
180193

194+
it('renders icon button with aria-label and no tooltip', () => {
195+
const {getByRole} = render(
196+
<SegmentedControl aria-label="File view">
197+
{segmentData.map(({label, icon}) => (
198+
<SegmentedControl.IconButton icon={icon} aria-label={label} key={label} />
199+
))}
200+
</SegmentedControl>,
201+
)
202+
203+
for (const datum of segmentData) {
204+
const labelledButton = getByRole('button', {name: datum.label})
205+
expect(labelledButton).toHaveAttribute('aria-label', datum.label)
206+
}
207+
})
208+
181209
it('calls onChange with index of clicked segment button', async () => {
182210
const user = userEvent.setup()
183211
const handleChange = vi.fn()

packages/react/src/SegmentedControl/SegmentedControlIconButton.tsx

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type React from 'react'
33
import type {IconProps} from '@primer/octicons-react'
44
import type {SxProp} from '../sx'
55
import {isElement} from 'react-is'
6+
import {useFeatureFlag} from '../FeatureFlags'
67
import type {TooltipDirection} from '../TooltipV2'
78
import classes from './SegmentedControl.module.css'
89
import {clsx} from 'clsx'
@@ -34,31 +35,56 @@ export const SegmentedControlIconButton: React.FC<React.PropsWithChildren<Segmen
3435
tooltipDirection,
3536
...rest
3637
}) => {
37-
return (
38-
<BoxWithFallback
39-
as="li"
40-
sx={sxProp}
41-
className={clsx(classes.Item, className)}
42-
data-selected={selected || undefined}
43-
>
44-
<Tooltip
45-
type={description ? undefined : 'label'}
46-
text={description ? description : ariaLabel}
47-
direction={tooltipDirection}
38+
const tooltipFlagEnabled = useFeatureFlag('primer_react_segmented_control_tooltip')
39+
if (tooltipFlagEnabled) {
40+
return (
41+
<BoxWithFallback
42+
as="li"
43+
sx={sxProp}
44+
className={clsx(classes.Item, className)}
45+
data-selected={selected || undefined}
46+
>
47+
<Tooltip
48+
type={description ? undefined : 'label'}
49+
text={description ? description : ariaLabel}
50+
direction={tooltipDirection}
51+
>
52+
<BoxWithFallback
53+
as="button"
54+
aria-current={selected}
55+
// If description is provided, we will use the tooltip to describe the button, so we need to keep the aria-label to label the button.
56+
aria-label={description ? ariaLabel : undefined}
57+
className={clsx(classes.Button, classes.IconButton)}
58+
{...rest}
59+
>
60+
<span className={clsx(classes.Content, 'segmentedControl-content')}>
61+
{isElement(Icon) ? Icon : <Icon />}
62+
</span>
63+
</BoxWithFallback>
64+
</Tooltip>
65+
</BoxWithFallback>
66+
)
67+
} else {
68+
// This can be removed when primer_react_segmented_control_tooltip feature flag is GA-ed.
69+
return (
70+
<BoxWithFallback
71+
as="li"
72+
sx={sxProp}
73+
className={clsx(classes.Item, className)}
74+
data-selected={selected || undefined}
4875
>
4976
<BoxWithFallback
5077
as="button"
78+
aria-label={ariaLabel}
5179
aria-current={selected}
52-
// If description is provided, we will use the tooltip to describe the button, so we need to keep the aria-label to label the button.
53-
aria-label={description ? ariaLabel : undefined}
5480
className={clsx(classes.Button, classes.IconButton)}
5581
{...rest}
5682
>
5783
<span className={clsx(classes.Content, 'segmentedControl-content')}>{isElement(Icon) ? Icon : <Icon />}</span>
5884
</BoxWithFallback>
59-
</Tooltip>
60-
</BoxWithFallback>
61-
)
85+
</BoxWithFallback>
86+
)
87+
}
6288
}
6389

6490
export default SegmentedControlIconButton

0 commit comments

Comments
 (0)