fix: Cascader not found content should be disabled (#28062)

This commit is contained in:
不吃猫的鱼 2020-11-30 11:31:22 +08:00 committed by GitHub
parent 4f811cbe82
commit 73a07d075e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 16 deletions

View File

@ -592,9 +592,10 @@ exports[`Cascader have a notFoundContent that fit trigger input width 1`] = `
<div>
<ul
class="ant-cascader-menu"
style="height: auto;"
>
<li
class="ant-cascader-menu-item"
class="ant-cascader-menu-item ant-cascader-menu-item-disabled"
role="menuitem"
title=""
>
@ -1177,9 +1178,10 @@ exports[`Cascader should show not found content when options.length is 0 1`] = `
<div>
<ul
class="ant-cascader-menu"
style="height: auto; width: 0px;"
>
<li
class="ant-cascader-menu-item"
class="ant-cascader-menu-item ant-cascader-menu-item-disabled"
role="menuitem"
title=""
>

View File

@ -321,6 +321,12 @@ describe('Cascader', () => {
expect(popupWrapper.render()).toMatchSnapshot();
});
it('not found content shoule be disabled', () => {
const wrapper = mount(<Cascader options={[]} />);
wrapper.find('input').simulate('click');
expect(wrapper.find('.ant-cascader-menu-item-disabled').length).toBe(1);
});
describe('limit filtered item count', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

View File

@ -234,6 +234,19 @@ function warningValueNotExist(list: CascaderOptionType[], fieldNames: FieldNames
});
}
function getEmptyNode(
renderEmpty: RenderEmptyHandler,
names: FilledFieldNamesType,
notFoundContent?: React.ReactNode,
) {
return {
[names.value]: 'ANT_CASCADER_NOT_FOUND',
[names.label]: notFoundContent || renderEmpty('Cascader'),
disabled: true,
isEmptyNode: true,
};
}
class Cascader extends React.Component<CascaderProps, CascaderState> {
static defaultProps = {
transitionName: 'slide-up',
@ -442,14 +455,7 @@ class Cascader extends React.Component<CascaderProps, CascaderState> {
} as CascaderOptionType;
});
}
return [
{
[names.value]: 'ANT_CASCADER_NOT_FOUND',
[names.label]: notFoundContent || renderEmpty('Cascader'),
disabled: true,
isEmptyNode: true,
},
];
return [getEmptyNode(renderEmpty, names, notFoundContent)];
}
focus() {
@ -568,12 +574,7 @@ class Cascader extends React.Component<CascaderProps, CascaderState> {
options = this.generateFilteredOptions(prefixCls, renderEmpty);
}
} else {
options = [
{
[names.label]: notFoundContent || renderEmpty('Cascader'),
[names.value]: 'ANT_CASCADER_NOT_FOUND',
},
];
options = [getEmptyNode(renderEmpty, names, notFoundContent)];
}
// Dropdown menu should keep previous status until it is fully closed.
if (!state.popupVisible) {