Skip to content

Commit e5c6140

Browse files
committed
fix: cascader empty data does not work #1701
1 parent 6cc28ee commit e5c6140

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

components/cascader/index.jsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ const Cascader = {
386386
disabled,
387387
allowClear,
388388
showSearch = false,
389+
notFoundContent,
389390
...otherProps
390391
} = props;
391392
const getPrefixCls = this.configProvider.getPrefixCls;
@@ -441,9 +442,21 @@ const Cascader = {
441442
]);
442443

443444
let options = props.options;
444-
if (inputValue) {
445-
options = this.generateFilteredOptions(prefixCls, renderEmpty);
445+
const names = getFilledFieldNames(this.$props);
446+
if (options && options.length > 0) {
447+
if (inputValue) {
448+
options = this.generateFilteredOptions(prefixCls, renderEmpty);
449+
}
450+
} else {
451+
options = [
452+
{
453+
[names.label]: notFoundContent || renderEmpty(h, 'Cascader'),
454+
[names.value]: 'ANT_CASCADER_NOT_FOUND',
455+
disabled: true,
456+
},
457+
];
446458
}
459+
447460
// Dropdown menu should keep previous status until it is fully closed.
448461
if (!sPopupVisible) {
449462
options = this.cachedOptions;
@@ -459,7 +472,7 @@ const Cascader = {
459472
}
460473
// The default value of `matchInputWidth` is `true`
461474
const resultListMatchInputWidth = showSearch.matchInputWidth !== false;
462-
if (resultListMatchInputWidth && inputValue && this.$refs.input) {
475+
if (resultListMatchInputWidth && (inputValue || isNotFound) && this.$refs.input) {
463476
dropdownMenuColumnStyle.width = this.$refs.input.$el.offsetWidth + 'px';
464477
}
465478
// showSearch时,focus、blur在input上触发,反之在ref='picker'上触发

site/dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Api from './components/api';
1212
import './components';
1313
import demoBox from './components/demoBox';
1414
import demoContainer from './components/demoContainer';
15-
import Test from '../components/tree/demo/index.vue';
15+
import Test from '../components/empty/demo/index.vue';
1616
import zhCN from './theme/zh-CN';
1717
import enUS from './theme/en-US';
1818
Vue.use(Vuex);

0 commit comments

Comments
 (0)