Skip to content

Commit 210aaa6

Browse files
authored
Clean up the feature flag for primer_react_segmented_control_tooltip (#6307)
1 parent b831e20 commit 210aaa6

File tree

4 files changed

+33
-83
lines changed

4 files changed

+33
-83
lines changed

.changeset/strong-mangos-rest.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 feature flag for `primer_react_segmented_control_tooltip` and GA tootip by default behavior.

packages/react/src/FeatureFlags/DefaultFeatureFlags.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ 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,
98
primer_react_select_panel_fullscreen_on_narrow: false,
109
primer_react_select_panel_order_selected_at_top: false,
1110
})

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

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ 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'
98
import {SegmentedControl} from '../SegmentedControl'
109

1110
const segmentData = [
@@ -144,19 +143,13 @@ describe('SegmentedControl', () => {
144143
}
145144
})
146145

147-
it('renders icon button with tooltip as label when feature flag is enabled', () => {
146+
it('renders icon button with tooltip as label', () => {
148147
const {getByRole, getByText} = render(
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>,
148+
<SegmentedControl aria-label="File view">
149+
{segmentData.map(({label, icon}) => (
150+
<SegmentedControl.IconButton icon={icon} aria-label={label} key={label} />
151+
))}
152+
</SegmentedControl>,
160153
)
161154

162155
for (const datum of segmentData) {
@@ -167,41 +160,20 @@ describe('SegmentedControl', () => {
167160
}
168161
})
169162

170-
it('renders icon button with tooltip description when feature flag is enabled', () => {
163+
it('renders icon button with tooltip description', () => {
171164
const {getByRole, getByText} = render(
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>,
183-
)
184-
185-
for (const datum of segmentData) {
186-
const labelledButton = getByRole('button', {name: datum.label})
187-
const tooltipElement = getByText(datum.description)
188-
expect(labelledButton).toHaveAttribute('aria-describedby', tooltipElement.id)
189-
expect(labelledButton).toHaveAccessibleName(datum.label)
190-
expect(labelledButton).toHaveAttribute('aria-label', datum.label)
191-
}
192-
})
193-
194-
it('renders icon button with aria-label and no tooltip', () => {
195-
const {getByRole} = render(
196165
<SegmentedControl aria-label="File view">
197-
{segmentData.map(({label, icon}) => (
198-
<SegmentedControl.IconButton icon={icon} aria-label={label} key={label} />
166+
{segmentData.map(({label, icon, description}) => (
167+
<SegmentedControl.IconButton icon={icon} aria-label={label} description={description} key={label} />
199168
))}
200169
</SegmentedControl>,
201170
)
202171

203172
for (const datum of segmentData) {
204173
const labelledButton = getByRole('button', {name: datum.label})
174+
const tooltipElement = getByText(datum.description)
175+
expect(labelledButton).toHaveAttribute('aria-describedby', tooltipElement.id)
176+
expect(labelledButton).toHaveAccessibleName(datum.label)
205177
expect(labelledButton).toHaveAttribute('aria-label', datum.label)
206178
}
207179
})

packages/react/src/SegmentedControl/SegmentedControlIconButton.tsx

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ 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'
76
import type {TooltipDirection} from '../TooltipV2'
87
import classes from './SegmentedControl.module.css'
98
import {clsx} from 'clsx'
@@ -35,56 +34,31 @@ export const SegmentedControlIconButton: React.FC<React.PropsWithChildren<Segmen
3534
tooltipDirection,
3635
...rest
3736
}) => {
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}
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}
7548
>
7649
<BoxWithFallback
7750
as="button"
78-
aria-label={ariaLabel}
7951
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}
8054
className={clsx(classes.Button, classes.IconButton)}
8155
{...rest}
8256
>
8357
<span className={clsx(classes.Content, 'segmentedControl-content')}>{isElement(Icon) ? Icon : <Icon />}</span>
8458
</BoxWithFallback>
85-
</BoxWithFallback>
86-
)
87-
}
59+
</Tooltip>
60+
</BoxWithFallback>
61+
)
8862
}
8963

9064
export default SegmentedControlIconButton

0 commit comments

Comments
 (0)