Skip to content

Commit

Permalink
fix: Cascader not found content should be disabled (#28062)
Browse files Browse the repository at this point in the history
  • Loading branch information
headwindz authored Nov 30, 2020
1 parent 4f811cb commit 73a07d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
>
Expand Down Expand Up @@ -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=""
>
Expand Down
6 changes: 6 additions & 0 deletions components/cascader/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {});

Expand Down
29 changes: 15 additions & 14 deletions components/cascader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand 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() {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 73a07d0

Please sign in to comment.