Skip to content

Commit b9051a4

Browse files
authored
fix: should correct render Cascader with same field name of label and value (#263)
1 parent 9d16e4f commit b9051a4

File tree

3 files changed

+121
-4
lines changed

3 files changed

+121
-4
lines changed

src/hooks/useSearchOptions.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { DefaultOptionType, ShowSearchType, InternalFieldNames } from '../Cascader';
22
import * as React from 'react';
3-
import { VALUE_SPLIT } from '../utils/commonUtil';
43

54
export const SEARCH_MARK = '__rc_cascader_search_mark__';
65

@@ -53,9 +52,6 @@ export default (
5352
prefixCls,
5453
fieldNames,
5554
),
56-
[fieldNames.value as 'value']: connectedPathOptions
57-
.map(pathOption => pathOption[fieldNames.value])
58-
.join(VALUE_SPLIT),
5955
[SEARCH_MARK]: connectedPathOptions,
6056
});
6157
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Cascader.Search should correct render Cascader with same field name of label and value 1`] = `
4+
<div
5+
class="rc-cascader rc-cascader-single rc-cascader-show-arrow rc-cascader-open rc-cascader-show-search"
6+
>
7+
<div
8+
class="rc-cascader-selector"
9+
>
10+
<span
11+
class="rc-cascader-selection-search"
12+
>
13+
<input
14+
aria-autocomplete="list"
15+
aria-controls="rc_select_TEST_OR_SSR_list"
16+
aria-expanded="true"
17+
aria-haspopup="listbox"
18+
aria-owns="rc_select_TEST_OR_SSR_list"
19+
autocomplete="off"
20+
class="rc-cascader-selection-search-input"
21+
id="rc_select_TEST_OR_SSR"
22+
role="combobox"
23+
type="search"
24+
value="z"
25+
/>
26+
</span>
27+
<span
28+
class="rc-cascader-selection-placeholder"
29+
style="visibility: hidden;"
30+
/>
31+
</div>
32+
<div>
33+
<div
34+
class="rc-cascader-dropdown"
35+
style="opacity: 0; pointer-events: none; min-width: 0;"
36+
>
37+
<div>
38+
<div
39+
class="rc-cascader-menus"
40+
>
41+
<ul
42+
class="rc-cascader-menu"
43+
role="menu"
44+
>
45+
<li
46+
aria-checked="false"
47+
class="rc-cascader-menu-item"
48+
data-path-key="Zhejiang__RC_CASCADER_SPLIT__Hangzhou__RC_CASCADER_SPLIT__West Lake"
49+
role="menuitemcheckbox"
50+
title="Zhejiang / Hangzhou / West Lake"
51+
>
52+
<div
53+
class="rc-cascader-menu-item-content"
54+
>
55+
Zhejiang / Hangzhou / West Lake
56+
</div>
57+
</li>
58+
<li
59+
aria-checked="false"
60+
class="rc-cascader-menu-item rc-cascader-menu-item-disabled"
61+
data-path-key="Zhejiang__RC_CASCADER_SPLIT__Hangzhou__RC_CASCADER_SPLIT__Xia Sha"
62+
role="menuitemcheckbox"
63+
title="Zhejiang / Hangzhou / Xia Sha"
64+
>
65+
<div
66+
class="rc-cascader-menu-item-content"
67+
>
68+
Zhejiang / Hangzhou / Xia Sha
69+
</div>
70+
</li>
71+
</ul>
72+
</div>
73+
</div>
74+
</div>
75+
</div>
76+
<span
77+
aria-hidden="true"
78+
class="rc-cascader-arrow"
79+
style="user-select: none;"
80+
unselectable="on"
81+
>
82+
<span
83+
class="rc-cascader-arrow-icon"
84+
/>
85+
</span>
86+
</div>
87+
`;

tests/search.spec.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,38 @@ describe('Cascader.Search', () => {
199199
wrapper.find('.rc-cascader-menu-item').first().simulate('click');
200200
doSearch(wrapper, '1');
201201
});
202+
203+
it('should correct render Cascader with same field name of label and value', () => {
204+
const customOptions = [
205+
{
206+
name: 'Zhejiang',
207+
children: [
208+
{
209+
name: 'Hangzhou',
210+
children: [
211+
{
212+
name: 'West Lake',
213+
},
214+
{
215+
name: 'Xia Sha',
216+
disabled: true,
217+
},
218+
],
219+
},
220+
],
221+
},
222+
];
223+
function customFilter(inputValue, path) {
224+
return path.some(option => option.name.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
225+
}
226+
const wrapper = mount(
227+
<Cascader
228+
options={customOptions}
229+
fieldNames={{ label: 'name', value: 'name' }}
230+
showSearch={{ filter: customFilter }}
231+
/>,
232+
);
233+
wrapper.find('input').simulate('change', { target: { value: 'z' } });
234+
expect(wrapper.render()).toMatchSnapshot();
235+
});
202236
});

0 commit comments

Comments
 (0)