Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-virtualized-select-panel-measurement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

SelectPanel: Prevent console warnings when measuring virtualized items
15 changes: 15 additions & 0 deletions packages/react/src/ActionList/Item.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,21 @@ describe('ActionList.Item', () => {
expect(tabs).toHaveLength(3)
})

it('should forward a list-semantic item ref only to the outer list item', () => {
const ref = vi.fn<(node: HTMLLIElement | null) => void>()
const {getByRole} = HTMLRender(
<ActionList role="listbox" aria-label="Projects">
<ActionList.Item ref={ref} role="option">
Primer React
</ActionList.Item>
</ActionList>,
)
const option = getByRole('option')

expect(ref.mock.calls.filter(([node]) => node !== null)).toEqual([[option]])
expect(option.tagName).toBe('LI')
})

it('should preserve consumer ref when tooltip wraps trigger', async () => {
const user = userEvent.setup()

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/ActionList/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ const UnwrappedItem = <As extends React.ElementType = 'li'>(
className={classes.ActionListContent}
data-size={size}
// @ts-ignore: ItemWrapper is polymorphic and the ref type depends on the rendered element ('button' or 'li')
ref={forwardedRef}
ref={listSemantics ? null : forwardedRef}
>
{/* Reset TooltipContext so that child components don't detect
the ConditionalTooltip and suppress their own internal tooltips. */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ describe('FilteredActionList', () => {
).toBeInTheDocument()
})
})

it('does not warn when measuring virtualized items', () => {
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})

try {
const {container} = render(<FilteredActionList items={items} onFilterChange={vi.fn()} virtualized />)

expect(container.querySelector('[data-index]')).toBeInTheDocument()
expect(warnSpy.mock.calls.flat().join(' ')).not.toContain(
"Missing attribute name 'data-index={index}' on measured element.",
)
} finally {
warnSpy.mockRestore()
}
})
})

describe('FilteredActionListBodyLoader', () => {
Expand Down
Loading