feat: update select
parent
3c4cc8ea77
commit
4193d246ba
|
@ -33,7 +33,7 @@ describe('Select', () => {
|
||||||
.findAll({ name: 'MenuItem' })
|
.findAll({ name: 'MenuItem' })
|
||||||
.at(0)
|
.at(0)
|
||||||
.text(),
|
.text(),
|
||||||
).toBe('Not Found');
|
).toBe('No Data');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,7 @@ import warning from 'warning';
|
||||||
import omit from 'omit.js';
|
import omit from 'omit.js';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import { Select as VcSelect, Option, OptGroup } from '../vc-select';
|
import { Select as VcSelect, Option, OptGroup } from '../vc-select';
|
||||||
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
import defaultLocale from '../locale-provider/default';
|
|
||||||
import {
|
import {
|
||||||
getComponentFromProp,
|
getComponentFromProp,
|
||||||
getOptionProps,
|
getOptionProps,
|
||||||
|
@ -96,7 +95,7 @@ const Select = {
|
||||||
name: 'ASelect',
|
name: 'ASelect',
|
||||||
props: {
|
props: {
|
||||||
...SelectProps,
|
...SelectProps,
|
||||||
prefixCls: PropTypes.string.def('ant-select'),
|
prefixCls: PropTypes.string,
|
||||||
showSearch: PropTypes.bool.def(false),
|
showSearch: PropTypes.bool.def(false),
|
||||||
transitionName: PropTypes.string.def('slide-up'),
|
transitionName: PropTypes.string.def('slide-up'),
|
||||||
choiceTransitionName: PropTypes.string.def('zoom'),
|
choiceTransitionName: PropTypes.string.def('zoom'),
|
||||||
|
@ -124,21 +123,24 @@ const Select = {
|
||||||
blur() {
|
blur() {
|
||||||
this.$refs.vcSelect.blur();
|
this.$refs.vcSelect.blur();
|
||||||
},
|
},
|
||||||
getNotFoundContent(locale) {
|
getNotFoundContent(renderEmpty) {
|
||||||
|
const h = this.$createElement;
|
||||||
const notFoundContent = getComponentFromProp(this, 'notFoundContent');
|
const notFoundContent = getComponentFromProp(this, 'notFoundContent');
|
||||||
if (this.isCombobox()) {
|
if (notFoundContent !== undefined) {
|
||||||
// AutoComplete don't have notFoundContent defaultly
|
return notFoundContent;
|
||||||
return notFoundContent === undefined ? null : notFoundContent;
|
|
||||||
}
|
}
|
||||||
return notFoundContent === undefined ? locale.notFoundContent : notFoundContent;
|
if (this.isCombobox()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return renderEmpty(h, 'Select');
|
||||||
},
|
},
|
||||||
isCombobox() {
|
isCombobox() {
|
||||||
const { mode } = this;
|
const { mode } = this;
|
||||||
return mode === 'combobox' || mode === SECRET_COMBOBOX_MODE_DO_NOT_USE;
|
return mode === 'combobox' || mode === SECRET_COMBOBOX_MODE_DO_NOT_USE;
|
||||||
},
|
},
|
||||||
|
|
||||||
renderSuffixIcon() {
|
renderSuffixIcon(prefixCls) {
|
||||||
const { prefixCls, loading } = this.$props;
|
const { loading } = this.$props;
|
||||||
let suffixIcon = getComponentFromProp(this, 'suffixIcon');
|
let suffixIcon = getComponentFromProp(this, 'suffixIcon');
|
||||||
suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon;
|
suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon;
|
||||||
if (suffixIcon) {
|
if (suffixIcon) {
|
||||||
|
@ -151,11 +153,24 @@ const Select = {
|
||||||
}
|
}
|
||||||
return <Icon type="down" class={`${prefixCls}-arrow-icon`} />;
|
return <Icon type="down" class={`${prefixCls}-arrow-icon`} />;
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
prefixCls: customizePrefixCls,
|
||||||
|
size,
|
||||||
|
mode,
|
||||||
|
options,
|
||||||
|
getPopupContainer,
|
||||||
|
...restProps
|
||||||
|
} = getOptionProps(this);
|
||||||
|
|
||||||
|
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
|
||||||
|
const renderEmpty = (
|
||||||
|
this.configProvider.renderEmpty &&
|
||||||
|
this.configProvider.renderEmpty()
|
||||||
|
) || ConfigConsumerProps.renderEmpty;
|
||||||
|
const prefixCls = getPrefixCls('select', customizePrefixCls);
|
||||||
|
|
||||||
renderSelect(locale) {
|
|
||||||
const { prefixCls, size, mode, options, getPopupContainer, ...restProps } = getOptionProps(
|
|
||||||
this,
|
|
||||||
);
|
|
||||||
const { getPopupContainer: getContextPopupContainer } = this.configProvider;
|
const { getPopupContainer: getContextPopupContainer } = this.configProvider;
|
||||||
let removeIcon = getComponentFromProp(this, 'removeIcon');
|
let removeIcon = getComponentFromProp(this, 'removeIcon');
|
||||||
removeIcon = Array.isArray(removeIcon) ? removeIcon[0] : removeIcon;
|
removeIcon = Array.isArray(removeIcon) ? removeIcon[0] : removeIcon;
|
||||||
|
@ -208,7 +223,7 @@ const Select = {
|
||||||
|
|
||||||
const selectProps = {
|
const selectProps = {
|
||||||
props: {
|
props: {
|
||||||
inputIcon: this.renderSuffixIcon(),
|
inputIcon: this.renderSuffixIcon(prefixCls),
|
||||||
removeIcon: finalRemoveIcon,
|
removeIcon: finalRemoveIcon,
|
||||||
clearIcon: finalClearIcon,
|
clearIcon: finalClearIcon,
|
||||||
menuItemSelectedIcon: finalMenuItemSelectedIcon,
|
menuItemSelectedIcon: finalMenuItemSelectedIcon,
|
||||||
|
@ -216,7 +231,7 @@ const Select = {
|
||||||
...modeConfig,
|
...modeConfig,
|
||||||
prefixCls,
|
prefixCls,
|
||||||
optionLabelProp: optionLabelProp || 'children',
|
optionLabelProp: optionLabelProp || 'children',
|
||||||
notFoundContent: this.getNotFoundContent(locale),
|
notFoundContent: this.getNotFoundContent(renderEmpty),
|
||||||
maxTagPlaceholder: getComponentFromProp(this, 'maxTagPlaceholder'),
|
maxTagPlaceholder: getComponentFromProp(this, 'maxTagPlaceholder'),
|
||||||
placeholder: getComponentFromProp(this, 'placeholder'),
|
placeholder: getComponentFromProp(this, 'placeholder'),
|
||||||
children: options
|
children: options
|
||||||
|
@ -239,16 +254,6 @@ const Select = {
|
||||||
};
|
};
|
||||||
return <VcSelect {...selectProps} />;
|
return <VcSelect {...selectProps} />;
|
||||||
},
|
},
|
||||||
},
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<LocaleReceiver
|
|
||||||
componentName="Select"
|
|
||||||
defaultLocale={defaultLocale.Select}
|
|
||||||
scopedSlots={{ default: this.renderSelect }}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
|
|
Loading…
Reference in New Issue