🐛 Fix Cascader broken when option children is null

close #17735
This commit is contained in:
afc163 2019-07-20 12:20:00 +08:00
parent 32f1e333ca
commit 93e41ed593
No known key found for this signature in database
GPG Key ID: 5F00908D72002306
2 changed files with 22 additions and 2 deletions

View File

@ -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();
});
});

View File

@ -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);