From c9a1590fc4da3da43132128aea5bbb4534fe5626 Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Thu, 7 Aug 2025 16:57:56 +0300 Subject: [PATCH] fix(ui): search in select fields with `filterOptions` (#13397) Fixes https://github.com/payloadcms/payload/issues/13236 --- packages/ui/src/fields/Select/index.tsx | 4 ++-- test/fields/collections/Select/e2e.spec.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/fields/Select/index.tsx b/packages/ui/src/fields/Select/index.tsx index 3e89cd11be..26d27b72d1 100644 --- a/packages/ui/src/fields/Select/index.tsx +++ b/packages/ui/src/fields/Select/index.tsx @@ -112,10 +112,10 @@ const SelectFieldComponent: SelectFieldClientComponent = (props) => { Error={Error} filterOption={ selectFilterOptions - ? ({ value }) => + ? ({ label, value }, search) => selectFilterOptions?.some( (option) => (typeof option === 'string' ? option : option.value) === value, - ) + ) && label.toLowerCase().includes(search.toLowerCase()) : undefined } hasMany={hasMany} diff --git a/test/fields/collections/Select/e2e.spec.ts b/test/fields/collections/Select/e2e.spec.ts index 71823aa1f4..a2f91395a5 100644 --- a/test/fields/collections/Select/e2e.spec.ts +++ b/test/fields/collections/Select/e2e.spec.ts @@ -110,4 +110,16 @@ describe('Select', () => { await field.click({ delay: 100 }) await expect(options.locator('text=One')).toBeHidden() }) + + test('should retain search when reducing options', async () => { + await page.goto(url.create) + const field = page.locator('#field-selectWithFilteredOptions') + await field.click({ delay: 100 }) + const options = page.locator('.rs__option') + await expect(options.locator('text=One')).toBeVisible() + await expect(options.locator('text=Two')).toBeVisible() + await field.locator('input').fill('On') + await expect(options.locator('text=One')).toBeVisible() + await expect(options.locator('text=Two')).toBeHidden() + }) })