fix: cascader empty data does not work #1701

pull/1710/head
wangxueliang 2020-01-09 22:56:50 +08:00
parent 6cc28eeb62
commit e5c6140a74
2 changed files with 17 additions and 4 deletions

View File

@ -386,6 +386,7 @@ const Cascader = {
disabled,
allowClear,
showSearch = false,
notFoundContent,
...otherProps
} = props;
const getPrefixCls = this.configProvider.getPrefixCls;
@ -441,9 +442,21 @@ const Cascader = {
]);
let options = props.options;
if (inputValue) {
options = this.generateFilteredOptions(prefixCls, renderEmpty);
const names = getFilledFieldNames(this.$props);
if (options && options.length > 0) {
if (inputValue) {
options = this.generateFilteredOptions(prefixCls, renderEmpty);
}
} else {
options = [
{
[names.label]: notFoundContent || renderEmpty(h, 'Cascader'),
[names.value]: 'ANT_CASCADER_NOT_FOUND',
disabled: true,
},
];
}
// Dropdown menu should keep previous status until it is fully closed.
if (!sPopupVisible) {
options = this.cachedOptions;
@ -459,7 +472,7 @@ const Cascader = {
}
// The default value of `matchInputWidth` is `true`
const resultListMatchInputWidth = showSearch.matchInputWidth !== false;
if (resultListMatchInputWidth && inputValue && this.$refs.input) {
if (resultListMatchInputWidth && (inputValue || isNotFound) && this.$refs.input) {
dropdownMenuColumnStyle.width = this.$refs.input.$el.offsetWidth + 'px';
}
// showSearchfocusblurinputref='picker'

View File

@ -12,7 +12,7 @@ import Api from './components/api';
import './components';
import demoBox from './components/demoBox';
import demoContainer from './components/demoContainer';
import Test from '../components/tree/demo/index.vue';
import Test from '../components/empty/demo/index.vue';
import zhCN from './theme/zh-CN';
import enUS from './theme/en-US';
Vue.use(Vuex);