From 93e41ed5931ba1ab6303795b61772d529b6b0a4b Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 20 Jul 2019 12:20:00 +0800 Subject: [PATCH] :bug: Fix Cascader broken when option children is null close #17735 --- components/cascader/__tests__/index.test.js | 20 ++++++++++++++++++++ components/cascader/index.tsx | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/components/cascader/__tests__/index.test.js b/components/cascader/__tests__/index.test.js index 788d618719..547d5de195 100644 --- a/components/cascader/__tests__/index.test.js +++ b/components/cascader/__tests__/index.test.js @@ -451,4 +451,24 @@ describe('Cascader', () => { ); errorSpy.mockRestore(); }); + + // https://github.com/ant-design/ant-design/issues/17690 + it('should not breaks when children is null', () => { + const optionsWithChildrenNull = [ + { + value: 'zhejiang', + label: 'Zhejiang', + children: [ + { + value: 'hangzhou', + label: 'Hangzhou', + children: null, + }, + ], + }, + ]; + expect(() => { + mount(); + }).not.toThrow(); + }); }); diff --git a/components/cascader/index.tsx b/components/cascader/index.tsx index 745ada08dc..ceffe749fa 100644 --- a/components/cascader/index.tsx +++ b/components/cascader/index.tsx @@ -206,8 +206,8 @@ function flattenTree( const defaultDisplayRender = (label: string[]) => label.join(' / '); -function warningValueNotExist(list: CascaderOptionType[] = [], fieldNames: FieldNamesType = {}) { - list.forEach(item => { +function warningValueNotExist(list: CascaderOptionType[], fieldNames: FieldNamesType = {}) { + (list || []).forEach(item => { const valueFieldName = fieldNames.value || 'value'; warning(valueFieldName in item, 'Cascader', 'Not found `value` in `options`.'); warningValueNotExist(item[fieldNames.children || 'children'], fieldNames);