Skip to content

Commit 6556f51

Browse files
committed
fix: handle React 19 popover target warnings
1 parent d9dde66 commit 6556f51

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

packages/react/src/AnchoredOverlay/AnchoredOverlay.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import classes from './AnchoredOverlay.module.css'
1616
import {clsx} from 'clsx'
1717
import {useFeatureFlag} from '../FeatureFlags'
1818
import {widthMap} from '../Overlay/constants'
19+
import {reactMajorVersion} from '../utils/environment'
1920

2021
interface AnchoredOverlayPropsWithAnchor {
2122
/**
@@ -290,6 +291,11 @@ export const AnchoredOverlay: React.FC<React.PropsWithChildren<AnchoredOverlayPr
290291
})
291292

292293
const popoverId = useId()
294+
const popoverTargetProps = shouldRenderAsPopover
295+
? reactMajorVersion >= 19
296+
? {popoverTarget: popoverId}
297+
: {popovertarget: popoverId}
298+
: {}
293299
const id = popoverId.replaceAll(':', '_') // popoverId can contain colons which are invalid in CSS custom property names, so we replace them with underscores
294300
const anchorName = `--anchored-overlay-anchor-${id}`
295301

@@ -406,7 +412,7 @@ export const AnchoredOverlay: React.FC<React.PropsWithChildren<AnchoredOverlayPr
406412
tabIndex: 0,
407413
onClick: onAnchorClick,
408414
onKeyDown: onAnchorKeyDown,
409-
...(shouldRenderAsPopover ? {popovertarget: popoverId} : {}),
415+
...popoverTargetProps,
410416
})}
411417
{open ? (
412418
<Overlay

packages/react/src/SelectPanel/SelectPanel.test.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ export function getLiveRegion(): LiveRegionElement {
4444
throw new Error('No live-region found')
4545
}
4646

47-
const renderWithProp = (element: React.ReactElement, flag?: boolean) => {
47+
const getFocusManagement = (flag?: boolean) => {
4848
// true = 'use roving tabindex'
4949
// false = 'use aria-activedescendant'
50-
const focusManagement = flag ? 'roving-tabindex' : 'active-descendant'
51-
return render(React.cloneElement(element, {_PrivateFocusManagement: focusManagement}))
50+
return flag ? 'roving-tabindex' : 'active-descendant'
51+
}
52+
53+
const renderWithProp = (element: React.ReactElement, flag?: boolean) => {
54+
return render(React.cloneElement(element, {_PrivateFocusManagement: getFocusManagement(flag)}))
5255
}
5356

5457
const items: SelectPanelProps['items'] = [
@@ -160,12 +163,11 @@ for (const usingRemoveActiveDescendant of [false, true]) {
160163
it('should close the select panel when clicking outside of the select panel', async () => {
161164
const user = userEvent.setup()
162165

163-
renderWithProp(
166+
render(
164167
<>
165168
<button type="button">outer button</button>
166-
<BasicSelectPanel />
169+
<BasicSelectPanel _PrivateFocusManagement={getFocusManagement(usingRemoveActiveDescendant)} />
167170
</>,
168-
usingRemoveActiveDescendant,
169171
)
170172

171173
await user.click(screen.getByText('Select items'))

0 commit comments

Comments
 (0)