From 3eaae1b34a0fb643dc1cdacfc1821f5a02049fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=83=E5=87=9B?= Date: Tue, 25 May 2021 12:20:37 +0800 Subject: [PATCH 1/3] fix: options show when children is empty --- src/Menus.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Menus.tsx b/src/Menus.tsx index 506240b0..c248fbaf 100644 --- a/src/Menus.tsx +++ b/src/Menus.tsx @@ -132,7 +132,8 @@ class Menus extends React.Component { const { options } = this.props; const result = this.getActiveOptions() .map((activeOption) => activeOption[this.getFieldName('children')]) - .filter((activeOption) => !!activeOption); + .filter((activeOption) => !!activeOption) + .filter((activeOption) => activeOption.length > 0); result.unshift(options); return result; } From cbd7db3b4a6bfb1e1614beb2f2724bc5c450ada0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=83=E5=87=9B?= Date: Tue, 25 May 2021 12:29:00 +0800 Subject: [PATCH 2/3] fix --- src/Menus.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Menus.tsx b/src/Menus.tsx index c248fbaf..41074088 100644 --- a/src/Menus.tsx +++ b/src/Menus.tsx @@ -132,8 +132,7 @@ class Menus extends React.Component { const { options } = this.props; const result = this.getActiveOptions() .map((activeOption) => activeOption[this.getFieldName('children')]) - .filter((activeOption) => !!activeOption) - .filter((activeOption) => activeOption.length > 0); + .filter((activeOption) => !!activeOption && activeOption.length > 0); result.unshift(options); return result; } From c2d86e033e30ea8bbba1b8c8efb4ebbccf533178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=83=E5=87=9B?= Date: Tue, 25 May 2021 13:30:48 +0800 Subject: [PATCH 3/3] add test --- tests/index.spec.js | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/tests/index.spec.js b/tests/index.spec.js index 6885997a..dfbd8789 100644 --- a/tests/index.spec.js +++ b/tests/index.spec.js @@ -51,10 +51,7 @@ describe('Cascader', () => { expect(selectedValue).toBeFalsy(); menu1Items.at(0).simulate('click'); expect( - wrapper - .find('.rc-cascader-menu-item') - .first() - .hasClass('rc-cascader-menu-item-active'), + wrapper.find('.rc-cascader-menu-item').first().hasClass('rc-cascader-menu-item-active'), ).toBe(true); menus = wrapper.find('.rc-cascader-menu'); expect(menus.length).toBe(2); @@ -284,6 +281,26 @@ describe('Cascader', () => { expect(menus.length).toBe(0); }); + it('should not display when children is empty', () => { + const wrapper = mount( + + + , + ); + wrapper.find('input').simulate('click'); + const menus = wrapper.find('.rc-cascader-menu'); + expect(menus.length).toBe(1); + }); + it('should be unselectable when option is disabled', () => { const newAddressOptions = [...addressOptions]; newAddressOptions[0] = { @@ -304,10 +321,7 @@ describe('Cascader', () => { menu1Items.at(0).simulate('click'); expect( - wrapper - .find('.rc-cascader-menu-item') - .first() - .hasClass('rc-cascader-menu-item-disabled'), + wrapper.find('.rc-cascader-menu-item').first().hasClass('rc-cascader-menu-item-disabled'), ).toBe(true); menus = wrapper.find('.rc-cascader-menu'); expect(menus.length).toBe(1); @@ -357,7 +371,7 @@ describe('Cascader', () => { { + ref={(node) => { this.cascader = node; }} > @@ -509,10 +523,7 @@ describe('Cascader', () => { expect(wrapper.state().popupVisible).toBeFalsy(); wrapper.find('input').simulate('click'); expect(wrapper.state().popupVisible).toBeTruthy(); - wrapper - .find('li') - .at(0) - .simulate('doubleClick'); + wrapper.find('li').at(0).simulate('doubleClick'); expect(wrapper.state().popupVisible).toBeFalsy(); }); @@ -601,7 +612,7 @@ describe('Cascader', () => { ( + dropdownRender={(menus) => (
{menus}