Browse Source

🐛 Fix Cascader broken when option children is null

close #17735
pull/17756/head
afc163 5 years ago
parent
commit
93e41ed593
No known key found for this signature in database GPG Key ID: 5F00908D72002306
  1. 20
      components/cascader/__tests__/index.test.js
  2. 4
      components/cascader/index.tsx

20
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(<Cascader options={optionsWithChildrenNull} />);
}).not.toThrow();
});
});

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

Loading…
Cancel
Save