Skip to content

Commit 2536b49

Browse files
Update the default value of unsafeDisableTooltip to false and remove redundant props and wrappers (#4702)
* Update the default value of unsafeDisableTooltip to false and remove unncessary props and wrappers * test and lint fix * Create clean-fireants-type.md * update actionbar e2e test selector * disable tooltips in button group stories * update Dialog tests * fix linting * update tests
1 parent 1976ee1 commit 2536b49

File tree

11 files changed

+72
-31
lines changed

11 files changed

+72
-31
lines changed

.changeset/clean-fireants-type.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@primer/react": minor
3+
---
4+
5+
IconButton: Enable tooltips by default in icon buttons by updating the default value of `unsafeDisableTooltip` to `false`.
6+
7+
This is a behaviour change in icon buttons, please upgrade with a caution.
8+

e2e/components/drafts/ActionBar.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ test.describe('ActionBar', () => {
4444
await expect(page.locator(toolbarButtonSelector)).toHaveCount(10)
4545
await page.setViewportSize({width: viewports['primer.breakpoint.xs'], height: 768})
4646
await expect(page.locator(toolbarButtonSelector)).toHaveCount(6)
47-
const moreButtonSelector = `button[aria-label="More Comment box toolbar items"]`
48-
await page.locator(moreButtonSelector).click()
47+
const moreButtonSelector = page.getByLabel('More Comment box toolbar items')
48+
await moreButtonSelector.click()
4949
await expect(page.locator('ul[role="menu"]>li')).toHaveCount(5)
5050
})
5151
})

packages/react/src/ActionBar/ActionBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export const ActionBarIconButton = forwardRef((props: ActionBarIconButtonProps,
299299
const domRect = (ref as MutableRefObject<HTMLElement>).current.getBoundingClientRect()
300300
setChildrenWidth({text, width: domRect.width})
301301
}, [ref, setChildrenWidth])
302-
return <IconButton ref={ref} size={size} {...props} variant="invisible" unsafeDisableTooltip={false} />
302+
return <IconButton ref={ref} size={size} {...props} variant="invisible" />
303303
})
304304

305305
const sizeToHeight = {

packages/react/src/ActionList/TrailingAction.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export const TrailingAction = forwardRef(({as = 'button', icon, label, href = nu
4848
aria-label={label}
4949
icon={icon}
5050
variant="invisible"
51-
unsafeDisableTooltip={false}
5251
tooltipDirection="w"
5352
href={href}
5453
// @ts-expect-error StyledButton wants both Anchor and Button refs

packages/react/src/Button/IconButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const IconButton = forwardRef(
1717
disabled,
1818
tooltipDirection,
1919
// This is planned to be a temporary prop until the default tooltip on icon buttons are fully rolled out.
20-
unsafeDisableTooltip = true,
20+
unsafeDisableTooltip = false,
2121
...props
2222
},
2323
forwardedRef,

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ describe('Button', () => {
131131
const tooltipEl = getByText('Love is all around')
132132
expect(triggerEL).toHaveAttribute('aria-describedby', tooltipEl.id)
133133
})
134-
it('should not render tooltip on an icon button by default', () => {
135-
const {getByRole} = render(<IconButton icon={HeartIcon} aria-label="Heart" />)
134+
it('should render tooltip on an icon button by default', () => {
135+
const {getByRole, getByText} = render(<IconButton icon={HeartIcon} aria-label="Heart" />)
136136
const triggerEl = getByRole('button')
137-
expect(triggerEl).not.toHaveAttribute('aria-labelledby')
138-
expect(triggerEl).toHaveAttribute('aria-label', 'Heart')
137+
const tooltipEl = getByText('Heart')
138+
expect(triggerEl).toHaveAttribute('aria-labelledby', tooltipEl.id)
139+
expect(triggerEl).not.toHaveAttribute('aria-label')
139140
})
140141
})

packages/react/src/ButtonGroup/ButtonGroup.features.stories.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export default {
1111

1212
export const IconButtons = () => (
1313
<ButtonGroup>
14-
<IconButton icon={PlusIcon} aria-label="Add" />
15-
<IconButton icon={DashIcon} aria-label="Subtract" />
14+
{/* We can remove these unsafe props after we resolve https://github.com/primer/react/issues/4129 */}
15+
<IconButton unsafeDisableTooltip={true} icon={PlusIcon} aria-label="Add" />
16+
<IconButton unsafeDisableTooltip={true} icon={DashIcon} aria-label="Subtract" />
1617
</ButtonGroup>
1718
)

packages/react/src/Dialog.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {ComponentProps} from './utils/types'
1111
import {useRefObjectAsForwardedRef} from './hooks/useRefObjectAsForwardedRef'
1212
import {XIcon} from '@primer/octicons-react'
1313

14+
// Dialog v1
1415
const noop = () => null
1516

1617
type StyledDialogBaseProps = {

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, {useState, useRef} from 'react'
2-
import {Dialog, Box, Text} from '..'
3-
import {Button} from '../deprecated'
2+
import {Dialog, Box, Text, Button} from '..'
43
import {render as HTMLRender, fireEvent} from '@testing-library/react'
54
import axe from 'axe-core'
65
import {behavesAsComponent, checkExports} from '../utils/testing'
@@ -71,6 +70,36 @@ const DialogWithCustomFocusRef = () => {
7170
)
7271
}
7372

73+
const DialogWithCustomFocusRefAndReturnFocusRef = () => {
74+
const [isOpen, setIsOpen] = useState(true)
75+
const returnFocusRef = useRef(null)
76+
const buttonRef = useRef(null)
77+
return (
78+
<div>
79+
<Button data-testid="trigger-button" ref={returnFocusRef} onClick={() => setIsOpen(true)}>
80+
Show Dialog
81+
</Button>
82+
<Dialog
83+
returnFocusRef={returnFocusRef}
84+
isOpen={isOpen}
85+
initialFocusRef={buttonRef}
86+
onDismiss={() => setIsOpen(false)}
87+
aria-labelledby="header"
88+
>
89+
<div data-testid="inner">
90+
<Dialog.Header id="header">Title</Dialog.Header>
91+
<Box p={3}>
92+
<Text fontFamily="sans-serif">Some content</Text>
93+
<button data-testid="inner-button" ref={buttonRef}>
94+
hi
95+
</button>
96+
</Box>
97+
</div>
98+
</Dialog>
99+
</div>
100+
)
101+
}
102+
74103
describe('Dialog', () => {
75104
// because Dialog returns a React fragment the as and sx tests fail always, so they are skipped
76105
behavesAsComponent({
@@ -140,7 +169,9 @@ describe('Dialog', () => {
140169
})
141170

142171
it('Returns focus to returnFocusRef on escape', async () => {
143-
const {getByTestId, queryByTestId} = HTMLRender(<Component />)
172+
const {getByTestId, queryByTestId} = HTMLRender(<DialogWithCustomFocusRefAndReturnFocusRef />)
173+
const innerButton = getByTestId('inner-button')
174+
expect(document.activeElement).toEqual(innerButton)
144175

145176
expect(getByTestId('inner')).toBeTruthy()
146177
fireEvent.keyDown(document.body, {key: 'Escape'})

packages/react/src/drafts/MarkdownEditor/_ToolbarButton.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export const ToolbarButton = forwardRef<HTMLButtonElement, IconButtonProps>((pro
1616
onMouseDown={(e: React.MouseEvent) => e.preventDefault()}
1717
{...props}
1818
sx={{color: 'fg.muted', ...props.sx}}
19+
// Keeping the tooltip disable since it is not maintained anymore and its tests were failing.
20+
unsafeDisableTooltip
1921
/>
2022
)
2123
})

packages/react/src/drafts/SelectPanel2/SelectPanel.tsx

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
IconButton,
88
Heading,
99
Box,
10-
Tooltip,
1110
TextInput,
1211
Spinner,
1312
Text,
@@ -401,15 +400,13 @@ const SelectPanelHeader: React.FC<React.PropsWithChildren & {onBack?: () => void
401400
>
402401
<Box sx={{display: 'flex'}}>
403402
{onBack ? (
404-
<Tooltip text="Back" direction="s">
405-
<IconButton
406-
type="button"
407-
variant="invisible"
408-
icon={ArrowLeftIcon}
409-
aria-label="Back"
410-
onClick={() => onBack()}
411-
/>
412-
</Tooltip>
403+
<IconButton
404+
type="button"
405+
variant="invisible"
406+
icon={ArrowLeftIcon}
407+
aria-label="Back"
408+
onClick={() => onBack()}
409+
/>
413410
) : null}
414411

415412
<Box sx={{marginLeft: onBack ? 1 : 2, marginTop: description ? '2px' : 0}}>
@@ -428,15 +425,16 @@ const SelectPanelHeader: React.FC<React.PropsWithChildren & {onBack?: () => void
428425
</Box>
429426

430427
<Box>
431-
{/* Will not need tooltip after https://github.com/primer/react/issues/2008 */}
432428
{onClearSelection ? (
433-
<Tooltip text="Clear selection" direction="s" onClick={onClearSelection}>
434-
<IconButton type="button" variant="invisible" icon={FilterRemoveIcon} aria-label="Clear selection" />
435-
</Tooltip>
429+
<IconButton
430+
type="button"
431+
variant="invisible"
432+
icon={FilterRemoveIcon}
433+
aria-label="Clear selection"
434+
onClick={onClearSelection}
435+
/>
436436
) : null}
437-
<Tooltip text="Close" direction="s">
438-
<IconButton type="button" variant="invisible" icon={XIcon} aria-label="Close" onClick={() => onCancel()} />
439-
</Tooltip>
437+
<IconButton type="button" variant="invisible" icon={XIcon} aria-label="Close" onClick={() => onCancel()} />
440438
</Box>
441439
</Box>
442440

0 commit comments

Comments
 (0)