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/filtered-action-list-item-renderer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

FilteredActionList: Respect item-level custom renderers
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ export function CustomItemRendering() {
<div>Use renderItem to customize how each item is displayed.</div>
<FilteredActionList
aria-label="Labels"
className={classes.FeatureListContainer}
className={classes.FilteredActionListContainer}
items={visibleItems}
onFilterChange={setFilter}
placeholderText="Filter labels"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,51 @@ describe('FilteredActionList', () => {
).toBeInTheDocument()
})
})

describe('custom item rendering', () => {
it('uses an item-level renderer', () => {
const renderItem = vi.fn(() => <li>Custom item</li>)

const {getByText} = render(
<FilteredActionList items={[{id: 1, text: 'Item 1', renderItem}]} onFilterChange={vi.fn()} />,
)

expect(getByText('Custom item')).toBeInTheDocument()
expect(renderItem).toHaveBeenCalled()
})

it('prefers an item-level renderer over the list-level renderer', () => {
const listRenderItem = vi.fn(() => <li>List renderer</li>)
const itemRenderItem = vi.fn(() => <li>Item renderer</li>)

const {getByText} = render(
<FilteredActionList
renderItem={listRenderItem}
items={[{id: 1, text: 'Item 1', renderItem: itemRenderItem}]}
onFilterChange={vi.fn()}
/>,
)

expect(getByText('Item renderer')).toBeInTheDocument()
expect(itemRenderItem).toHaveBeenCalled()
expect(listRenderItem).not.toHaveBeenCalled()
})

it('uses an item-level renderer for grouped items', () => {
const itemRenderItem = vi.fn(() => <li>Item renderer</li>)

const {getByText} = render(
<FilteredActionList
groupMetadata={[{groupId: 'group'}]}
items={[{groupId: 'group', id: 1, text: 'Item 1', renderItem: itemRenderItem}]}
onFilterChange={vi.fn()}
/>,
)

expect(getByText('Item renderer')).toBeInTheDocument()
expect(itemRenderItem).toHaveBeenCalled()
})
})
Comment thread
Copilot marked this conversation as resolved.
})

describe('FilteredActionListBodyLoader', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export function FilteredActionList({
focusPrependedElements,
scrollBehavior,
virtualized = false,
renderItem: listRenderItem,
...listProps
}: FilteredActionListProps): JSX.Element {
if (__DEV__) {
Expand Down Expand Up @@ -449,7 +450,7 @@ export function FilteredActionList({
data-input-focused={isInputFocused ? '' : undefined}
data-first-child={index === firstGroupIndex && itemIndex === 0 ? '' : undefined}
{...item}
renderItem={listProps.renderItem}
renderItem={'renderItem' in item ? item.renderItem : listRenderItem}
/>
)
})}
Expand Down Expand Up @@ -481,7 +482,7 @@ export function FilteredActionList({
transform: `translateY(${virtualItem.start}px)`,
}}
{...item}
renderItem={listProps.renderItem}
renderItem={'renderItem' in item ? item.renderItem : listRenderItem}
/>
)
})
Expand All @@ -496,7 +497,7 @@ export function FilteredActionList({
data-input-focused={isInputFocused ? '' : undefined}
data-first-child={index === 0 ? '' : undefined}
{...item}
renderItem={listProps.renderItem}
renderItem={'renderItem' in item ? item.renderItem : listRenderItem}
/>
)
})
Expand Down
Loading