diff --git a/src/OptionList/Column.tsx b/src/OptionList/Column.tsx index cabff06f..a96a767e 100644 --- a/src/OptionList/Column.tsx +++ b/src/OptionList/Column.tsx @@ -6,6 +6,8 @@ import Checkbox from './Checkbox'; import type { DefaultOptionType, SingleValueType } from '../Cascader'; import { SEARCH_MARK } from '../hooks/useSearchOptions'; +export const FIX_LABEL = '__cascader_fix_label__'; + export interface ColumnProps { prefixCls: string; multiple?: boolean; @@ -57,7 +59,7 @@ export default function Column({ options.map(option => { const { disabled } = option; const searchOptions = option[SEARCH_MARK]; - const label = option[fieldNames.label]; + const label = option[FIX_LABEL] ?? option[fieldNames.label]; const value = option[fieldNames.value]; const isMergedLeaf = isLeaf(option, fieldNames); diff --git a/src/OptionList/index.tsx b/src/OptionList/index.tsx index f8e04967..05f24860 100644 --- a/src/OptionList/index.tsx +++ b/src/OptionList/index.tsx @@ -13,7 +13,7 @@ import { toPathValueStr, } from '../utils/commonUtil'; import { toPathOptions } from '../utils/treeUtil'; -import Column from './Column'; +import Column, { FIX_LABEL } from './Column'; import useActive from './useActive'; import useKeyboard from './useKeyboard'; @@ -169,8 +169,8 @@ const RefOptionList = React.forwardRef((props, ref) => { const emptyList: DefaultOptionType[] = [ { - [fieldNames.label as 'label']: notFoundContent, [fieldNames.value as 'value']: '__EMPTY__', + [FIX_LABEL as 'label']: notFoundContent, disabled: true, }, ]; diff --git a/tests/fieldNames.spec.tsx b/tests/fieldNames.spec.tsx index 0ee788c5..864c963d 100644 --- a/tests/fieldNames.spec.tsx +++ b/tests/fieldNames.spec.tsx @@ -119,4 +119,20 @@ describe('Cascader.FieldNames', () => { expect(wrapper.find('.rc-cascader-menu-item').last().text()).toEqual('little'); }); + + it('empty should correct when label same as value', () => { + const wrapper = mount( + , + ); + + expect(wrapper.find('.rc-cascader-menu-item').last().text()).toEqual('Not Found'); + }); });