Skip to content

Commit 2f4337a

Browse files
authored
fix: Empty should not show value as label (#252)
1 parent c6ecd10 commit 2f4337a

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/OptionList/Column.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Checkbox from './Checkbox';
66
import type { DefaultOptionType, SingleValueType } from '../Cascader';
77
import { SEARCH_MARK } from '../hooks/useSearchOptions';
88

9+
export const FIX_LABEL = '__cascader_fix_label__';
10+
911
export interface ColumnProps {
1012
prefixCls: string;
1113
multiple?: boolean;
@@ -57,7 +59,7 @@ export default function Column({
5759
options.map(option => {
5860
const { disabled } = option;
5961
const searchOptions = option[SEARCH_MARK];
60-
const label = option[fieldNames.label];
62+
const label = option[FIX_LABEL] ?? option[fieldNames.label];
6163
const value = option[fieldNames.value];
6264

6365
const isMergedLeaf = isLeaf(option, fieldNames);

src/OptionList/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
toPathValueStr,
1414
} from '../utils/commonUtil';
1515
import { toPathOptions } from '../utils/treeUtil';
16-
import Column from './Column';
16+
import Column, { FIX_LABEL } from './Column';
1717
import useActive from './useActive';
1818
import useKeyboard from './useKeyboard';
1919

@@ -169,8 +169,8 @@ const RefOptionList = React.forwardRef<RefOptionListProps>((props, ref) => {
169169

170170
const emptyList: DefaultOptionType[] = [
171171
{
172-
[fieldNames.label as 'label']: notFoundContent,
173172
[fieldNames.value as 'value']: '__EMPTY__',
173+
[FIX_LABEL as 'label']: notFoundContent,
174174
disabled: true,
175175
},
176176
];

tests/fieldNames.spec.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,20 @@ describe('Cascader.FieldNames', () => {
119119

120120
expect(wrapper.find('.rc-cascader-menu-item').last().text()).toEqual('little');
121121
});
122+
123+
it('empty should correct when label same as value', () => {
124+
const wrapper = mount(
125+
<Cascader
126+
options={[]}
127+
open
128+
searchValue="not-exist"
129+
fieldNames={{
130+
label: 'same',
131+
value: 'same',
132+
}}
133+
/>,
134+
);
135+
136+
expect(wrapper.find('.rc-cascader-menu-item').last().text()).toEqual('Not Found');
137+
});
122138
});

0 commit comments

Comments
 (0)