Browse Source
Merge pull request #17756 from ant-design/fix-cascader
fix: Cascader broken when option children is null
pull/17759/head
偏右
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
22 additions and
2 deletions
-
components/cascader/__tests__/index.test.js
-
components/cascader/index.tsx
|
|
@ -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(<Cascader options={optionsWithChildrenNull} />); |
|
|
|
}).not.toThrow(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
@ -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); |
|
|
|