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

View File

@ -12,7 +12,7 @@ import Api from './components/api';
import './components'; import './components';
import demoBox from './components/demoBox'; import demoBox from './components/demoBox';
import demoContainer from './components/demoContainer'; 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 zhCN from './theme/zh-CN';
import enUS from './theme/en-US'; import enUS from './theme/en-US';
Vue.use(Vuex); Vue.use(Vuex);