Skip to content

Commit db13a60

Browse files
authored
fix(ui): list drawer per-page dropdown resets to 10 instead of showing saved limit (#14830)
### What? The per-page dropdown in ListDrawer always shows 10 on open, even when the user has previously saved a different preference (e.g., 5). However, the correct number of items is fetched and displayed, so only the dropdown UI is wrong. ### Why? ListDrawer doesn't use URL query params like regular collection pages. The server correctly uses the saved preference to fetch data and returns `data.limit`, but `query.limit` is always undefined in the ListQueryProvider. When PageControls tries to determine the limit, it falls back to the hardcoded default of 10 because it can't access the actual limit used by the server. ### How? Pass `defaultLimit: data?.limit` in the ListQueryProvider context. This exposes the server's actual limit to PageControls, which then forwards it to the PerPage component. Now the dropdown displays the correct saved preference. Fixes #14760
1 parent 617311a commit db13a60

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

packages/ui/src/providers/ListQuery/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export const ListQueryProvider: React.FC<ListQueryProps> = ({
176176
value={{
177177
collectionSlug,
178178
data,
179+
defaultLimit: data?.limit,
179180
handlePageChange,
180181
handlePerPageChange,
181182
handleSearchChange,

test/admin/e2e/list-view/e2e.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,52 @@ describe('List View', () => {
15981598

15991599
expect(firstPageIds).not.toContain(secondPageIds[0])
16001600
})
1601+
1602+
test('should persist per-page limit in list drawer', async () => {
1603+
await payload.delete({
1604+
collection: listDrawerSlug,
1605+
where: {},
1606+
})
1607+
1608+
await mapAsync([...Array(20)], async (_, i) => {
1609+
await payload.create({
1610+
collection: listDrawerSlug,
1611+
data: {
1612+
title: `List Drawer Item ${i + 1}`,
1613+
description: `Description ${i + 1}`,
1614+
number: i + 1,
1615+
},
1616+
})
1617+
})
1618+
1619+
await page.goto(withListViewUrl.list)
1620+
1621+
// Open the list drawer via the "Select posts" button
1622+
await page.locator('button:has-text("Select posts")').click()
1623+
1624+
const listDrawer = page.locator('.list-drawer.drawer--is-open')
1625+
await expect(listDrawer).toBeVisible()
1626+
1627+
await expect(page.locator('.list-drawer .per-page')).toContainText('Per Page: 10')
1628+
await expect(page.locator('.list-drawer table tbody tr')).toHaveCount(10)
1629+
1630+
// Change per-page to 5
1631+
await page.locator('.list-drawer .per-page .popup-button').click()
1632+
await page.getByRole('button', { name: '5', exact: true }).click()
1633+
1634+
await expect(page.locator('.list-drawer .per-page')).toContainText('Per Page: 5')
1635+
await expect(page.locator('.list-drawer table tbody tr')).toHaveCount(5)
1636+
1637+
await page.locator('.list-drawer .list-drawer__header .close-modal-button').click()
1638+
await expect(listDrawer).toBeHidden()
1639+
1640+
// Reopen the drawer
1641+
await page.locator('button:has-text("Select posts")').click()
1642+
await expect(listDrawer).toBeVisible()
1643+
1644+
await expect(page.locator('.list-drawer .per-page')).toContainText('Per Page: 5')
1645+
await expect(page.locator('.list-drawer table tbody tr')).toHaveCount(5)
1646+
})
16011647
})
16021648

16031649
// TODO: Troubleshoot flaky suite

0 commit comments

Comments
 (0)