From 82234c18f7c8da80eb298ae86a19cfcc1a65430f Mon Sep 17 00:00:00 2001 From: zhengjihao <2714499297@qq.com> Date: Fri, 23 Jan 2026 15:52:46 +0800 Subject: [PATCH 1/2] fix: optionRender usage for empty search results --- src/OptionList/Column.tsx | 2 +- tests/search.spec.tsx | 64 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/OptionList/Column.tsx b/src/OptionList/Column.tsx index fbc0c38e..8b79bd80 100644 --- a/src/OptionList/Column.tsx +++ b/src/OptionList/Column.tsx @@ -223,7 +223,7 @@ export default function Column )}
- {optionRender ? optionRender(option) : label} + {optionRender && value !== '__EMPTY__' ? optionRender(option) : label}
{!isLoading && expandIcon && !isMergedLeaf && (
{expandIcon}
diff --git a/tests/search.spec.tsx b/tests/search.spec.tsx index ce443b7a..1ac6591e 100644 --- a/tests/search.spec.tsx +++ b/tests/search.spec.tsx @@ -444,4 +444,68 @@ describe('Cascader.Search', () => { fireEvent.click(document.querySelector('.rc-cascader-checkbox') as HTMLElement); expect(inputNode).toHaveValue('little'); }); + + it('should display notFoundContent when search has no results with optionRender', () => { + const { container } = render( + `${option.label} - custom render`} + notFoundContent="未找到相关内容" + />, + ); + + // Search for something that doesn't exist + doSearch(container, 'nonexistent'); + const itemList = container.querySelectorAll('.rc-cascader-menu-item'); + expect(itemList).toHaveLength(1); + // Should display notFoundContent, not use optionRender + expect(itemList[0].textContent).toEqual('未找到相关内容'); + expect(itemList[0].querySelector('.rc-cascader-menu-item-content')?.textContent).toEqual( + '未找到相关内容', + ); + }); + + it('should use optionRender for search results when both optionRender and notFoundContent are provided', () => { + const { container } = render( + `${option.label} - custom render`} + notFoundContent="未找到相关内容" + />, + ); + + // Search for something that exists + doSearch(container, 'toy'); + const itemList = container.querySelectorAll('.rc-cascader-menu-item'); + expect(itemList.length).toBeGreaterThan(0); + + // Should use optionRender for actual options + const firstItemContent = itemList[0].querySelector('.rc-cascader-menu-item-content'); + expect(firstItemContent?.textContent).toContain('custom render'); + expect(firstItemContent?.textContent).not.toEqual('未找到相关内容'); + }); + + it('should display notFoundContent when options array is empty with optionRender', () => { + const { container } = render( + `${option.label} - custom render`} + notFoundContent="空列表" + />, + ); + + const itemList = container.querySelectorAll('.rc-cascader-menu-item'); + expect(itemList).toHaveLength(1); + // Should display notFoundContent, not use optionRender + expect(itemList[0].textContent).toEqual('空列表'); + expect(itemList[0].querySelector('.rc-cascader-menu-item-content')?.textContent).toEqual( + '空列表', + ); + }); }); From 7d5f2494a93fd76306c4985ce02b7a2342a0d6c8 Mon Sep 17 00:00:00 2001 From: zhengjihao <2714499297@qq.com> Date: Tue, 27 Jan 2026 10:11:32 +0800 Subject: [PATCH 2/2] fix: type for empty options array in search test --- tests/search.spec.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/search.spec.tsx b/tests/search.spec.tsx index 1ac6591e..fb5e4a84 100644 --- a/tests/search.spec.tsx +++ b/tests/search.spec.tsx @@ -2,7 +2,7 @@ import { fireEvent, render } from '@testing-library/react'; import KeyCode from '@rc-component/util/lib/KeyCode'; import { resetWarned } from '@rc-component/util/lib/warning'; import React from 'react'; -import Cascader from '../src'; +import Cascader, { type DefaultOptionType } from '../src'; import { optionsForActiveMenuItems } from './demoOptions'; import { expectOpen, doSearch, keyDown } from './util'; @@ -492,7 +492,7 @@ describe('Cascader.Search', () => { it('should display notFoundContent when options array is empty with optionRender', () => { const { container } = render( `${option.label} - custom render`}