Skip to content

Commit 096c6f5

Browse files
committed
🐛 Fix Cascader title cannot be reset to empty
close ant-design/ant-design#18713
1 parent 5194fdf commit 096c6f5

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-cascader",
3-
"version": "0.17.4",
3+
"version": "0.17.5",
44
"description": "cascade select ui component for react",
55
"keywords": [
66
"react",

src/Menus.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ class Menus extends React.Component {
6262
menuItemCls += ` ${prefixCls}-menu-item-loading`;
6363
loadingIconNode = loadingIcon || null;
6464
}
65+
6566
let title = '';
66-
if (option.title) {
67+
if ('title' in option) {
6768
title = option.title;
6869
} else if (typeof option[this.getFieldName('label')] === 'string') {
6970
title = option[this.getFieldName('label')];
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Cascader should not show title when title is falsy 1`] = `
4+
<ul
5+
className="rc-cascader-menu"
6+
key="0"
7+
>
8+
<li
9+
className="rc-cascader-menu-item"
10+
key="1"
11+
onClick={[Function]}
12+
onDoubleClick={[Function]}
13+
onMouseDown={[Function]}
14+
role="menuitem"
15+
title=""
16+
>
17+
1
18+
</li>
19+
<li
20+
className="rc-cascader-menu-item"
21+
key="2"
22+
onClick={[Function]}
23+
onDoubleClick={[Function]}
24+
onMouseDown={[Function]}
25+
role="menuitem"
26+
>
27+
2
28+
</li>
29+
<li
30+
className="rc-cascader-menu-item"
31+
key="3"
32+
onClick={[Function]}
33+
onDoubleClick={[Function]}
34+
onMouseDown={[Function]}
35+
role="menuitem"
36+
title="3"
37+
>
38+
3
39+
</li>
40+
<li
41+
className="rc-cascader-menu-item"
42+
key="4"
43+
onClick={[Function]}
44+
onDoubleClick={[Function]}
45+
onMouseDown={[Function]}
46+
role="menuitem"
47+
title="title"
48+
>
49+
4
50+
</li>
51+
</ul>
52+
`;

tests/index.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,4 +562,36 @@ describe('Cascader', () => {
562562
expect(onFocus).toHaveBeenCalledTimes(1);
563563
expect(onBlur).toHaveBeenCalledTimes(0);
564564
});
565+
566+
// https://github.com/ant-design/ant-design/issues/18713
567+
it('should not show title when title is falsy', () => {
568+
const options = [
569+
{
570+
value: '1',
571+
label: '1',
572+
title: '',
573+
},
574+
{
575+
value: '2',
576+
label: '2',
577+
title: undefined,
578+
},
579+
{
580+
value: '3',
581+
label: '3',
582+
},
583+
{
584+
value: '4',
585+
label: '4',
586+
title: 'title',
587+
},
588+
];
589+
const wrapper = mount(
590+
<Cascader options={options} popupVisible>
591+
<input readOnly />
592+
</Cascader>,
593+
);
594+
const menus = wrapper.find('.rc-cascader-menu');
595+
expect(menus).toMatchSnapshot();
596+
});
565597
});

0 commit comments

Comments
 (0)