feat: update vc-select to 8.9.0
parent
8713210000
commit
1a1411b1d3
|
@ -130,12 +130,17 @@ export default {
|
||||||
}
|
}
|
||||||
const activeKeyProps = {};
|
const activeKeyProps = {};
|
||||||
|
|
||||||
|
let defaultActiveFirst = defaultActiveFirstOption;
|
||||||
let clonedMenuItems = menuItems;
|
let clonedMenuItems = menuItems;
|
||||||
if (selectedKeys.length || firstActiveValue) {
|
if (selectedKeys.length || firstActiveValue) {
|
||||||
if (props.visible && !this.lastVisible) {
|
if (props.visible && !this.lastVisible) {
|
||||||
activeKeyProps.activeKey =
|
activeKeyProps.activeKey =
|
||||||
selectedKeys[0] !== undefined ? selectedKeys[0] : firstActiveValue;
|
selectedKeys[0] !== undefined ? selectedKeys[0] : firstActiveValue;
|
||||||
} else if (!visible) {
|
} else if (!visible) {
|
||||||
|
// Do not trigger auto active since we already have selectedKeys
|
||||||
|
if (selectedKeys[0]) {
|
||||||
|
defaultActiveFirst = false;
|
||||||
|
}
|
||||||
activeKeyProps.activeKey = undefined;
|
activeKeyProps.activeKey = undefined;
|
||||||
}
|
}
|
||||||
let foundFirst = false;
|
let foundFirst = false;
|
||||||
|
@ -180,7 +185,7 @@ export default {
|
||||||
if (inputValue !== this.lastInputValue && (!lastValue || lastValue !== backfillValue)) {
|
if (inputValue !== this.lastInputValue && (!lastValue || lastValue !== backfillValue)) {
|
||||||
activeKeyProps.activeKey = '';
|
activeKeyProps.activeKey = '';
|
||||||
}
|
}
|
||||||
menuProps.props = { ...activeKeyProps, ...menuProps.props };
|
menuProps.props = { ...activeKeyProps, ...menuProps.props, defaultActiveFirst };
|
||||||
return <Menu {...menuProps}>{clonedMenuItems}</Menu>;
|
return <Menu {...menuProps}>{clonedMenuItems}</Menu>;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -82,7 +82,7 @@ const Select = {
|
||||||
showSearch: SelectPropTypes.showSearch.def(true),
|
showSearch: SelectPropTypes.showSearch.def(true),
|
||||||
allowClear: SelectPropTypes.allowClear.def(false),
|
allowClear: SelectPropTypes.allowClear.def(false),
|
||||||
placeholder: SelectPropTypes.placeholder.def(''),
|
placeholder: SelectPropTypes.placeholder.def(''),
|
||||||
showArrow: SelectPropTypes.showArrow.def(true),
|
// showArrow: SelectPropTypes.showArrow.def(true),
|
||||||
dropdownMatchSelectWidth: PropTypes.bool.def(true),
|
dropdownMatchSelectWidth: PropTypes.bool.def(true),
|
||||||
dropdownStyle: SelectPropTypes.dropdownStyle.def({}),
|
dropdownStyle: SelectPropTypes.dropdownStyle.def({}),
|
||||||
dropdownMenuStyle: PropTypes.object.def({}),
|
dropdownMenuStyle: PropTypes.object.def({}),
|
||||||
|
@ -118,6 +118,7 @@ const Select = {
|
||||||
this._focused = false;
|
this._focused = false;
|
||||||
this._mouseDown = false;
|
this._mouseDown = false;
|
||||||
this._options = [];
|
this._options = [];
|
||||||
|
this._empty = false;
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
const props = getOptionProps(this);
|
const props = getOptionProps(this);
|
||||||
|
@ -150,7 +151,11 @@ const Select = {
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.autoFocus && this.focus();
|
// when defaultOpen is true, we should auto focus search input
|
||||||
|
// https://github.com/ant-design/ant-design/issues/14254
|
||||||
|
if(this.autoFocus || this._open) {
|
||||||
|
this.focus();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
@ -257,6 +262,7 @@ const Select = {
|
||||||
value: singleValue,
|
value: singleValue,
|
||||||
label: this.getLabelFromOption(props, option),
|
label: this.getLabelFromOption(props, option),
|
||||||
title: getValue(option, 'title'),
|
title: getValue(option, 'title'),
|
||||||
|
disabled: getValue(option, 'disabled'),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
if (preState) {
|
if (preState) {
|
||||||
|
@ -359,6 +365,7 @@ const Select = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const state = this.$data;
|
const state = this.$data;
|
||||||
|
const isRealOpen = this.getRealOpenState(state);
|
||||||
const keyCode = event.keyCode;
|
const keyCode = event.keyCode;
|
||||||
if (isMultipleOrTags(props) && !event.target.value && keyCode === KeyCode.BACKSPACE) {
|
if (isMultipleOrTags(props) && !event.target.value && keyCode === KeyCode.BACKSPACE) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -378,7 +385,10 @@ const Select = {
|
||||||
} else if (keyCode === KeyCode.ENTER && state._open) {
|
} else if (keyCode === KeyCode.ENTER && state._open) {
|
||||||
// Aviod trigger form submit when select item
|
// Aviod trigger form submit when select item
|
||||||
// https://github.com/ant-design/ant-design/issues/10861
|
// https://github.com/ant-design/ant-design/issues/10861
|
||||||
event.preventDefault();
|
// https://github.com/ant-design/ant-design/issues/14544
|
||||||
|
if (isRealOpen || !props.combobox) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
} else if (keyCode === KeyCode.ESC) {
|
} else if (keyCode === KeyCode.ESC) {
|
||||||
if (state._open) {
|
if (state._open) {
|
||||||
this.setOpenState(false);
|
this.setOpenState(false);
|
||||||
|
@ -388,7 +398,7 @@ const Select = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getRealOpenState(state) && this.selectTriggerRef) {
|
if (isRealOpen && this.selectTriggerRef) {
|
||||||
const menu = this.selectTriggerRef.getInnerMenu();
|
const menu = this.selectTriggerRef.getInnerMenu();
|
||||||
if (menu && menu.onKeyDown(event, this.handleBackfill)) {
|
if (menu && menu.onKeyDown(event, this.handleBackfill)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -413,6 +423,7 @@ const Select = {
|
||||||
value = value.concat([selectedValue]);
|
value = value.concat([selectedValue]);
|
||||||
} else {
|
} else {
|
||||||
if (
|
if (
|
||||||
|
!isCombobox(props) &&
|
||||||
lastValue !== undefined &&
|
lastValue !== undefined &&
|
||||||
lastValue === selectedValue &&
|
lastValue === selectedValue &&
|
||||||
selectedValue !== this.$data._backfillValue
|
selectedValue !== this.$data._backfillValue
|
||||||
|
@ -532,6 +543,10 @@ const Select = {
|
||||||
let value = null;
|
let value = null;
|
||||||
Object.keys(this.$data._optionsInfo).forEach(key => {
|
Object.keys(this.$data._optionsInfo).forEach(key => {
|
||||||
const info = this.$data._optionsInfo[key];
|
const info = this.$data._optionsInfo[key];
|
||||||
|
const { disabled } = info;
|
||||||
|
if (disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const oldLable = toArray(info.label);
|
const oldLable = toArray(info.label);
|
||||||
if (oldLable && oldLable.join('') === label) {
|
if (oldLable && oldLable.join('') === label) {
|
||||||
value = info.value;
|
value = info.value;
|
||||||
|
@ -1040,6 +1055,7 @@ const Select = {
|
||||||
const { children, tags, filterOption, notFoundContent } = this.$props;
|
const { children, tags, filterOption, notFoundContent } = this.$props;
|
||||||
const menuItems = [];
|
const menuItems = [];
|
||||||
const childrenKeys = [];
|
const childrenKeys = [];
|
||||||
|
let empty = false;
|
||||||
let options = this.renderFilterOptionsFromChildren(children, childrenKeys, menuItems);
|
let options = this.renderFilterOptionsFromChildren(children, childrenKeys, menuItems);
|
||||||
if (tags) {
|
if (tags) {
|
||||||
// tags value must be string
|
// tags value must be string
|
||||||
|
@ -1050,6 +1066,12 @@ const Select = {
|
||||||
(!inputValue || String(singleValue).indexOf(String(inputValue)) > -1)
|
(!inputValue || String(singleValue).indexOf(String(inputValue)) > -1)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// sort by length
|
||||||
|
value.sort((val1, val2) => {
|
||||||
|
return val1.length - val2.length;
|
||||||
|
});
|
||||||
|
|
||||||
value.forEach(singleValue => {
|
value.forEach(singleValue => {
|
||||||
const key = singleValue;
|
const key = singleValue;
|
||||||
const menuItem = (
|
const menuItem = (
|
||||||
|
@ -1094,6 +1116,7 @@ const Select = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.length && notFoundContent) {
|
if (!options.length && notFoundContent) {
|
||||||
|
empty = true;
|
||||||
const p = {
|
const p = {
|
||||||
attrs: UNSELECTABLE_ATTRIBUTE,
|
attrs: UNSELECTABLE_ATTRIBUTE,
|
||||||
key: 'NOT_FOUND',
|
key: 'NOT_FOUND',
|
||||||
|
@ -1106,7 +1129,7 @@ const Select = {
|
||||||
};
|
};
|
||||||
options = [<MenuItem {...p}>{notFoundContent}</MenuItem>];
|
options = [<MenuItem {...p}>{notFoundContent}</MenuItem>];
|
||||||
}
|
}
|
||||||
return options;
|
return {empty, options};
|
||||||
},
|
},
|
||||||
|
|
||||||
renderFilterOptionsFromChildren(children = [], childrenKeys, menuItems) {
|
renderFilterOptionsFromChildren(children = [], childrenKeys, menuItems) {
|
||||||
|
@ -1370,15 +1393,16 @@ const Select = {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
renderArrow(multiple) {
|
renderArrow(multiple) {
|
||||||
const { showArrow, loading, prefixCls } = this.$props;
|
// showArrow : Set to true if not multiple by default but keep set value.
|
||||||
|
const { showArrow = !multiple, loading, prefixCls } = this.$props;
|
||||||
const inputIcon = getComponentFromProp(this, 'inputIcon');
|
const inputIcon = getComponentFromProp(this, 'inputIcon');
|
||||||
if (!showArrow) {
|
if (!showArrow && !loading ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// if loading have loading icon
|
// if loading have loading icon
|
||||||
if (multiple && !loading) {
|
// if (multiple && !loading) {
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
const defaultIcon = loading ? (
|
const defaultIcon = loading ? (
|
||||||
<i class={`${prefixCls}-arrow-loading`} />
|
<i class={`${prefixCls}-arrow-loading`} />
|
||||||
) : (
|
) : (
|
||||||
|
@ -1466,14 +1490,19 @@ const Select = {
|
||||||
render() {
|
render() {
|
||||||
const props = this.$props;
|
const props = this.$props;
|
||||||
const multiple = isMultipleOrTags(props);
|
const multiple = isMultipleOrTags(props);
|
||||||
|
// Default set showArrow to true if not set (not set directly in defaultProps to handle multiple case)
|
||||||
|
const { showArrow = true } = props;
|
||||||
const state = this.$data;
|
const state = this.$data;
|
||||||
const { disabled, prefixCls } = props;
|
const { disabled, prefixCls, loading } = props;
|
||||||
const ctrlNode = this.renderTopControlNode();
|
const ctrlNode = this.renderTopControlNode();
|
||||||
const { _open: open, _inputValue: inputValue, _value: value } = this.$data;
|
const { _open: open, _inputValue: inputValue, _value: value } = this.$data;
|
||||||
if (open) {
|
if (open) {
|
||||||
this._options = this.renderFilterOptions();
|
const filterOptions = this.renderFilterOptions();
|
||||||
|
this._empty = filterOptions.empty;
|
||||||
|
this._options = filterOptions.options;
|
||||||
}
|
}
|
||||||
const realOpen = this.getRealOpenState();
|
const realOpen = this.getRealOpenState();
|
||||||
|
const empty = this._empty;
|
||||||
const options = this._options || [];
|
const options = this._options || [];
|
||||||
const { $listeners } = this;
|
const { $listeners } = this;
|
||||||
const { mouseenter = noop, mouseleave = noop, popupScroll = noop } = $listeners;
|
const { mouseenter = noop, mouseleave = noop, popupScroll = noop } = $listeners;
|
||||||
|
@ -1512,7 +1541,8 @@ const Select = {
|
||||||
[`${prefixCls}-disabled`]: disabled,
|
[`${prefixCls}-disabled`]: disabled,
|
||||||
[`${prefixCls}-enabled`]: !disabled,
|
[`${prefixCls}-enabled`]: !disabled,
|
||||||
[`${prefixCls}-allow-clear`]: !!props.allowClear,
|
[`${prefixCls}-allow-clear`]: !!props.allowClear,
|
||||||
[`${prefixCls}-no-arrow`]: !props.showArrow,
|
[`${prefixCls}-no-arrow`]: !showArrow,
|
||||||
|
[`${prefixCls}-loading`]: !!loading,
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<SelectTrigger
|
<SelectTrigger
|
||||||
|
@ -1528,6 +1558,7 @@ const Select = {
|
||||||
combobox={props.combobox}
|
combobox={props.combobox}
|
||||||
showSearch={props.showSearch}
|
showSearch={props.showSearch}
|
||||||
options={options}
|
options={options}
|
||||||
|
empty={empty}
|
||||||
multiple={multiple}
|
multiple={multiple}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
visible={realOpen}
|
visible={realOpen}
|
||||||
|
|
|
@ -42,6 +42,7 @@ export default {
|
||||||
multiple: PropTypes.bool,
|
multiple: PropTypes.bool,
|
||||||
inputValue: PropTypes.string,
|
inputValue: PropTypes.string,
|
||||||
filterOption: PropTypes.any,
|
filterOption: PropTypes.any,
|
||||||
|
empty: PropTypes.bool,
|
||||||
options: PropTypes.any,
|
options: PropTypes.any,
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
popupClassName: PropTypes.string,
|
popupClassName: PropTypes.string,
|
||||||
|
@ -170,12 +171,14 @@ export default {
|
||||||
options,
|
options,
|
||||||
getPopupContainer,
|
getPopupContainer,
|
||||||
showAction,
|
showAction,
|
||||||
|
empty,
|
||||||
} = $props;
|
} = $props;
|
||||||
const { mouseenter, mouseleave, popupFocus, dropdownVisibleChange } = $listeners;
|
const { mouseenter, mouseleave, popupFocus, dropdownVisibleChange } = $listeners;
|
||||||
const dropdownPrefixCls = this.getDropdownPrefixCls();
|
const dropdownPrefixCls = this.getDropdownPrefixCls();
|
||||||
const popupClassName = {
|
const popupClassName = {
|
||||||
[dropdownClassName]: !!dropdownClassName,
|
[dropdownClassName]: !!dropdownClassName,
|
||||||
[`${dropdownPrefixCls}--${multiple ? 'multiple' : 'single'}`]: 1,
|
[`${dropdownPrefixCls}--${multiple ? 'multiple' : 'single'}`]: 1,
|
||||||
|
[`${dropdownPrefixCls}--empty`]: empty,
|
||||||
};
|
};
|
||||||
const popupElement = this.getDropdownElement({
|
const popupElement = this.getDropdownElement({
|
||||||
props: {
|
props: {
|
||||||
|
|
|
@ -77,6 +77,16 @@
|
||||||
left: 50%;
|
left: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// select with arrow or loader
|
||||||
|
&:not(.@{selectPrefixCls}-no-arrow),
|
||||||
|
&-loading {
|
||||||
|
.@{selectPrefixCls}-selection--multiple {
|
||||||
|
.@{selectPrefixCls}-selection__clear {
|
||||||
|
right: 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&-selection {
|
&-selection {
|
||||||
outline: none;
|
outline: none;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// based on vc-select 8.7.0
|
// based on vc-select 8.9.0
|
||||||
import ProxySelect, { Select } from './Select';
|
import ProxySelect, { Select } from './Select';
|
||||||
import Option from './Option';
|
import Option from './Option';
|
||||||
import { SelectPropTypes } from './PropTypes';
|
import { SelectPropTypes } from './PropTypes';
|
||||||
|
|
|
@ -22,7 +22,7 @@ export default {
|
||||||
render() {
|
render() {
|
||||||
const props = { ...this.$props };
|
const props = { ...this.$props };
|
||||||
const listeners = this.$listeners;
|
const listeners = this.$listeners;
|
||||||
const { renderTabBarNode } = this.scopedSlots;
|
const { renderTabBarNode } = this.$scopedSlots;
|
||||||
return (
|
return (
|
||||||
<SaveRef
|
<SaveRef
|
||||||
children={(saveRef, getRef) => (
|
children={(saveRef, getRef) => (
|
||||||
|
|
Loading…
Reference in New Issue