2020-07-03 22:53:50 +08:00
|
|
|
|
import { TransitionGroup } from 'vue';
|
2019-01-12 11:33:27 +08:00
|
|
|
|
import KeyCode from '../_util/KeyCode';
|
|
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
import classes from 'component-classes';
|
|
|
|
|
import { Item as MenuItem, ItemGroup as MenuItemGroup } from '../vc-menu';
|
|
|
|
|
import warning from 'warning';
|
|
|
|
|
import Option from './Option';
|
|
|
|
|
import OptGroup from './OptGroup';
|
|
|
|
|
import {
|
|
|
|
|
hasProp,
|
|
|
|
|
getPropsData,
|
|
|
|
|
getValueByProp as getValue,
|
2020-06-28 23:11:31 +08:00
|
|
|
|
getComponent,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getEvents,
|
|
|
|
|
getOptionProps,
|
2020-06-30 18:31:58 +08:00
|
|
|
|
getSlot,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
} from '../_util/props-util';
|
|
|
|
|
import getTransitionProps from '../_util/getTransitionProps';
|
|
|
|
|
import { cloneElement } from '../_util/vnode';
|
|
|
|
|
import BaseMixin from '../_util/BaseMixin';
|
|
|
|
|
import SelectTrigger from './SelectTrigger';
|
2018-02-07 18:56:58 +08:00
|
|
|
|
import {
|
2019-01-04 23:00:09 +08:00
|
|
|
|
defaultFilterFn,
|
|
|
|
|
findFirstMenuItem,
|
|
|
|
|
findIndexInValueBySingleValue,
|
|
|
|
|
generateUUID,
|
|
|
|
|
getLabelFromPropsValue,
|
|
|
|
|
getMapKey,
|
2018-02-07 18:56:58 +08:00
|
|
|
|
getPropValue,
|
|
|
|
|
getValuePropValue,
|
2019-01-04 23:00:09 +08:00
|
|
|
|
includesSeparators,
|
2018-02-07 18:56:58 +08:00
|
|
|
|
isCombobox,
|
|
|
|
|
isMultipleOrTags,
|
|
|
|
|
isMultipleOrTagsOrCombobox,
|
|
|
|
|
isSingleMode,
|
2019-01-04 23:00:09 +08:00
|
|
|
|
preventDefaultEvent,
|
|
|
|
|
saveRef,
|
|
|
|
|
splitBySeparators,
|
2018-02-07 18:56:58 +08:00
|
|
|
|
toArray,
|
2019-01-04 23:00:09 +08:00
|
|
|
|
toTitle,
|
2018-02-07 18:56:58 +08:00
|
|
|
|
UNSELECTABLE_ATTRIBUTE,
|
|
|
|
|
UNSELECTABLE_STYLE,
|
|
|
|
|
validateOptionValue,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
} from './util';
|
|
|
|
|
import { SelectPropTypes } from './PropTypes';
|
2020-03-07 19:45:13 +08:00
|
|
|
|
import contains from '../vc-util/Dom/contains';
|
2019-09-28 18:00:24 +08:00
|
|
|
|
import { isIE, isEdge } from '../_util/env';
|
2018-02-07 18:56:58 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const SELECT_EMPTY_VALUE_KEY = 'RC_SELECT_EMPTY_VALUE_KEY';
|
2018-11-09 14:23:19 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const noop = () => null;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
|
2020-03-07 19:45:13 +08:00
|
|
|
|
// Where el is the DOM element you'd like to test for visibility
|
|
|
|
|
function isHidden(node) {
|
|
|
|
|
return !node || node.offsetParent === null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
function chaining(...fns) {
|
|
|
|
|
return function(...args) {
|
|
|
|
|
// eslint-disable-line
|
2018-02-07 18:56:58 +08:00
|
|
|
|
// eslint-disable-line
|
|
|
|
|
for (let i = 0; i < fns.length; i++) {
|
|
|
|
|
if (fns[i] && typeof fns[i] === 'function') {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
fns[i].apply(chaining, args);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
const Select = {
|
2018-05-06 20:37:39 +08:00
|
|
|
|
inheritAttrs: false,
|
2019-01-04 23:00:09 +08:00
|
|
|
|
Option,
|
|
|
|
|
OptGroup,
|
2018-02-07 18:56:58 +08:00
|
|
|
|
name: 'Select',
|
|
|
|
|
mixins: [BaseMixin],
|
2020-06-28 17:50:33 +08:00
|
|
|
|
inheritAttrs: false,
|
2018-02-07 18:56:58 +08:00
|
|
|
|
props: {
|
|
|
|
|
...SelectPropTypes,
|
|
|
|
|
prefixCls: SelectPropTypes.prefixCls.def('rc-select'),
|
|
|
|
|
defaultOpen: PropTypes.bool.def(false),
|
|
|
|
|
labelInValue: SelectPropTypes.labelInValue.def(false),
|
|
|
|
|
defaultActiveFirstOption: SelectPropTypes.defaultActiveFirstOption.def(true),
|
|
|
|
|
showSearch: SelectPropTypes.showSearch.def(true),
|
|
|
|
|
allowClear: SelectPropTypes.allowClear.def(false),
|
|
|
|
|
placeholder: SelectPropTypes.placeholder.def(''),
|
2019-03-04 15:45:21 +08:00
|
|
|
|
// showArrow: SelectPropTypes.showArrow.def(true),
|
2018-02-07 18:56:58 +08:00
|
|
|
|
dropdownMatchSelectWidth: PropTypes.bool.def(true),
|
2020-03-07 19:45:13 +08:00
|
|
|
|
dropdownStyle: SelectPropTypes.dropdownStyle.def(() => ({})),
|
|
|
|
|
dropdownMenuStyle: PropTypes.object.def(() => ({})),
|
2018-02-07 18:56:58 +08:00
|
|
|
|
optionFilterProp: SelectPropTypes.optionFilterProp.def('value'),
|
|
|
|
|
optionLabelProp: SelectPropTypes.optionLabelProp.def('value'),
|
2018-02-11 18:04:31 +08:00
|
|
|
|
notFoundContent: PropTypes.any.def('Not Found'),
|
2018-02-07 18:56:58 +08:00
|
|
|
|
backfill: PropTypes.bool.def(false),
|
|
|
|
|
showAction: SelectPropTypes.showAction.def(['click']),
|
2018-02-07 23:03:47 +08:00
|
|
|
|
combobox: PropTypes.bool.def(false),
|
2018-03-14 10:36:52 +08:00
|
|
|
|
tokenSeparators: PropTypes.arrayOf(PropTypes.string).def([]),
|
2018-09-05 21:28:54 +08:00
|
|
|
|
autoClearSearchValue: PropTypes.bool.def(true),
|
2019-01-04 23:00:09 +08:00
|
|
|
|
tabIndex: PropTypes.any.def(0),
|
|
|
|
|
dropdownRender: PropTypes.func.def(menu => menu),
|
2018-02-07 18:56:58 +08:00
|
|
|
|
// onChange: noop,
|
|
|
|
|
// onFocus: noop,
|
|
|
|
|
// onBlur: noop,
|
|
|
|
|
// onSelect: noop,
|
|
|
|
|
// onSearch: noop,
|
|
|
|
|
// onDeselect: noop,
|
|
|
|
|
// onInputKeydown: noop,
|
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
created() {
|
|
|
|
|
this.saveInputRef = saveRef(this, 'inputRef');
|
|
|
|
|
this.saveInputMirrorRef = saveRef(this, 'inputMirrorRef');
|
|
|
|
|
this.saveTopCtrlRef = saveRef(this, 'topCtrlRef');
|
|
|
|
|
this.saveSelectTriggerRef = saveRef(this, 'selectTriggerRef');
|
|
|
|
|
this.saveRootRef = saveRef(this, 'rootRef');
|
|
|
|
|
this.saveSelectionRef = saveRef(this, 'selectionRef');
|
|
|
|
|
this._focused = false;
|
|
|
|
|
this._mouseDown = false;
|
|
|
|
|
this._options = [];
|
2019-03-04 15:45:21 +08:00
|
|
|
|
this._empty = false;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
data() {
|
|
|
|
|
const props = getOptionProps(this);
|
|
|
|
|
const optionsInfo = this.getOptionsInfoFromProps(props);
|
2018-09-05 21:28:54 +08:00
|
|
|
|
warning(
|
|
|
|
|
this.__propsSymbol__,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
'Replace slots.default with props.children and pass props.__propsSymbol__',
|
|
|
|
|
);
|
2020-03-07 19:45:13 +08:00
|
|
|
|
if (props.tags && typeof props.filterOption !== 'function') {
|
|
|
|
|
const isDisabledExist = Object.keys(optionsInfo).some(key => optionsInfo[key].disabled);
|
|
|
|
|
warning(
|
|
|
|
|
!isDisabledExist,
|
|
|
|
|
'Please avoid setting option to disabled in tags mode since user can always type text as tag.',
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-12-25 12:00:39 +08:00
|
|
|
|
const state = {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
_value: this.getValueFromProps(props, true), // true: use default value
|
2019-01-12 11:33:27 +08:00
|
|
|
|
_inputValue: props.combobox
|
|
|
|
|
? this.getInputValueForCombobox(
|
|
|
|
|
props,
|
|
|
|
|
optionsInfo,
|
|
|
|
|
true, // use default value
|
|
|
|
|
)
|
|
|
|
|
: '',
|
2018-09-05 21:28:54 +08:00
|
|
|
|
_open: props.defaultOpen,
|
|
|
|
|
_optionsInfo: optionsInfo,
|
2019-01-04 23:00:09 +08:00
|
|
|
|
_backfillValue: '',
|
2018-09-05 21:28:54 +08:00
|
|
|
|
// a flag for aviod redundant getOptionsInfoFromProps call
|
|
|
|
|
_skipBuildOptionsInfo: true,
|
2019-01-08 23:03:13 +08:00
|
|
|
|
_ariaId: generateUUID(),
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2018-12-25 12:00:39 +08:00
|
|
|
|
return {
|
|
|
|
|
...state,
|
2020-07-03 22:53:50 +08:00
|
|
|
|
// _mirrorInputValue: state._inputValue, // https://github.com/vueComponent/ant-design-vue/issues/1458
|
2020-05-16 22:18:53 +08:00
|
|
|
|
...this.getDerivedState(props, state),
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2018-09-05 21:28:54 +08:00
|
|
|
|
},
|
2018-02-22 22:09:03 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
mounted() {
|
2018-02-07 18:56:58 +08:00
|
|
|
|
this.$nextTick(() => {
|
2019-03-04 15:45:21 +08:00
|
|
|
|
// when defaultOpen is true, we should auto focus search input
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/14254
|
2019-05-28 11:37:38 +08:00
|
|
|
|
if (this.autoFocus || this._open) {
|
2019-03-04 15:45:21 +08:00
|
|
|
|
this.focus();
|
|
|
|
|
}
|
2019-06-30 21:56:24 +08:00
|
|
|
|
// this.setState({
|
|
|
|
|
// _ariaId: generateUUID(),
|
|
|
|
|
// });
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
2018-02-07 23:03:47 +08:00
|
|
|
|
watch: {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
__propsSymbol__() {
|
2020-05-16 22:18:53 +08:00
|
|
|
|
Object.assign(this.$data, this.getDerivedState(getOptionProps(this), this.$data));
|
2018-02-07 23:03:47 +08:00
|
|
|
|
},
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
updated() {
|
2018-02-07 18:56:58 +08:00
|
|
|
|
this.$nextTick(() => {
|
2020-07-03 22:53:50 +08:00
|
|
|
|
this.updateInputWidth();
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.forcePopupAlign();
|
|
|
|
|
});
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
2020-06-11 16:13:09 +08:00
|
|
|
|
beforeUnmount() {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.clearFocusTime();
|
|
|
|
|
this.clearBlurTime();
|
2020-03-07 19:45:13 +08:00
|
|
|
|
this.clearComboboxTime();
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (this.dropdownContainer) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
document.body.removeChild(this.dropdownContainer);
|
|
|
|
|
this.dropdownContainer = null;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2020-07-03 22:53:50 +08:00
|
|
|
|
updateInputWidth() {
|
|
|
|
|
if (isMultipleOrTags(this.$props)) {
|
|
|
|
|
const inputNode = this.getInputDOMNode();
|
|
|
|
|
const mirrorNode = this.getInputMirrorDOMNode();
|
|
|
|
|
if (inputNode && inputNode.value && mirrorNode) {
|
|
|
|
|
inputNode.style.width = '';
|
|
|
|
|
inputNode.style.width = `${mirrorNode.clientWidth + 10}px`;
|
|
|
|
|
} else if (inputNode) {
|
|
|
|
|
inputNode.style.width = '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-05-16 22:18:53 +08:00
|
|
|
|
getDerivedState(nextProps, prevState) {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
const optionsInfo = prevState._skipBuildOptionsInfo
|
|
|
|
|
? prevState._optionsInfo
|
2019-01-12 11:33:27 +08:00
|
|
|
|
: this.getOptionsInfoFromProps(nextProps, prevState);
|
2018-02-23 11:28:43 +08:00
|
|
|
|
|
2018-09-05 21:28:54 +08:00
|
|
|
|
const newState = {
|
|
|
|
|
_optionsInfo: optionsInfo,
|
|
|
|
|
_skipBuildOptionsInfo: false,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2018-09-05 21:28:54 +08:00
|
|
|
|
|
|
|
|
|
if ('open' in nextProps) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
newState._open = nextProps.open;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ('value' in nextProps) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const value = this.getValueFromProps(nextProps);
|
|
|
|
|
newState._value = value;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (nextProps.combobox) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
newState._inputValue = this.getInputValueForCombobox(nextProps, optionsInfo);
|
2018-02-22 17:19:47 +08:00
|
|
|
|
}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return newState;
|
2018-02-22 15:09:03 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getOptionsFromChildren(children = [], options = []) {
|
2019-01-04 23:00:09 +08:00
|
|
|
|
children.forEach(child => {
|
2020-06-30 18:31:58 +08:00
|
|
|
|
if (!child) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
2020-06-29 18:43:43 +08:00
|
|
|
|
if (child.type?.isSelectOptGroup) {
|
2020-06-30 18:31:58 +08:00
|
|
|
|
this.getOptionsFromChildren(getSlot(child), options);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
options.push(child);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
|
|
|
|
return options;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getInputValueForCombobox(props, optionsInfo, useDefaultValue) {
|
|
|
|
|
let value = [];
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if ('value' in props && !useDefaultValue) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
value = toArray(props.value);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
|
|
|
|
if ('defaultValue' in props && useDefaultValue) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
value = toArray(props.defaultValue);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
|
|
|
|
if (value.length) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
value = value[0];
|
2019-01-04 23:00:09 +08:00
|
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return '';
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
let label = value;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (props.labelInValue) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
label = value.label;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
} else if (optionsInfo[getMapKey(value)]) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
label = optionsInfo[getMapKey(value)].label;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
|
|
|
|
if (label === undefined) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
label = '';
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return label;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getLabelFromOption(props, option) {
|
|
|
|
|
return getPropValue(option, props.optionLabelProp);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getOptionsInfoFromProps(props, preState) {
|
|
|
|
|
const options = this.getOptionsFromChildren(this.$props.children);
|
|
|
|
|
const optionsInfo = {};
|
|
|
|
|
options.forEach(option => {
|
|
|
|
|
const singleValue = getValuePropValue(option);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
optionsInfo[getMapKey(singleValue)] = {
|
|
|
|
|
option,
|
|
|
|
|
value: singleValue,
|
|
|
|
|
label: this.getLabelFromOption(props, option),
|
|
|
|
|
title: getValue(option, 'title'),
|
2019-03-04 15:45:21 +08:00
|
|
|
|
disabled: getValue(option, 'disabled'),
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
|
|
|
|
});
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (preState) {
|
|
|
|
|
// keep option info in pre state value.
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const oldOptionsInfo = preState._optionsInfo;
|
|
|
|
|
const value = preState._value;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (value) {
|
|
|
|
|
value.forEach(v => {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const key = getMapKey(v);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (!optionsInfo[key] && oldOptionsInfo[key] !== undefined) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
optionsInfo[key] = oldOptionsInfo[key];
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return optionsInfo;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getValueFromProps(props, useDefaultValue) {
|
|
|
|
|
let value = [];
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if ('value' in props && !useDefaultValue) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
value = toArray(props.value);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
|
|
|
|
if ('defaultValue' in props && useDefaultValue) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
value = toArray(props.defaultValue);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
|
|
|
|
if (props.labelInValue) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
value = value.map(v => {
|
|
|
|
|
return v.key;
|
|
|
|
|
});
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return value;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
},
|
2018-11-09 14:23:19 +08:00
|
|
|
|
|
2019-11-15 18:21:50 +08:00
|
|
|
|
onInputChange(e) {
|
2020-07-03 22:53:50 +08:00
|
|
|
|
const { value: val } = e.target;
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const { tokenSeparators } = this.$props;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (
|
|
|
|
|
isMultipleOrTags(this.$props) &&
|
2019-01-12 11:33:27 +08:00
|
|
|
|
tokenSeparators.length &&
|
|
|
|
|
includesSeparators(val, tokenSeparators)
|
2018-02-07 18:56:58 +08:00
|
|
|
|
) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const nextValue = this.getValueByInput(val);
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (nextValue !== undefined) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.fireChange(nextValue);
|
2018-09-05 21:28:54 +08:00
|
|
|
|
}
|
2020-03-07 19:45:13 +08:00
|
|
|
|
this.setOpenState(false, { needFocus: true });
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.setInputValue('', false);
|
|
|
|
|
return;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.setInputValue(val);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
this.setState({
|
2018-09-05 21:28:54 +08:00
|
|
|
|
_open: true,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (isCombobox(this.$props)) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.fireChange([val]);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
onDropdownVisibleChange(open) {
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (open && !this._focused) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.clearBlurTime();
|
|
|
|
|
this.timeoutFocus();
|
|
|
|
|
this._focused = true;
|
|
|
|
|
this.updateFocusClassName();
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.setOpenState(open);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// combobox ignore
|
2019-01-12 11:33:27 +08:00
|
|
|
|
onKeyDown(event) {
|
|
|
|
|
const { _open: open } = this.$data;
|
|
|
|
|
const { disabled } = this.$props;
|
2018-11-09 14:23:19 +08:00
|
|
|
|
if (disabled) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const keyCode = event.keyCode;
|
2018-11-09 14:23:19 +08:00
|
|
|
|
if (open && !this.getInputDOMNode()) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.onInputKeydown(event);
|
|
|
|
|
} else if (keyCode === KeyCode.ENTER || keyCode === KeyCode.DOWN) {
|
2019-08-30 18:48:51 +08:00
|
|
|
|
// vue state是同步更新,onKeyDown在onMenuSelect后会再次调用,单选时不在调用setOpenState
|
|
|
|
|
// https://github.com/vueComponent/ant-design-vue/issues/1142
|
|
|
|
|
if (keyCode === KeyCode.ENTER && !isMultipleOrTags(this.$props)) {
|
|
|
|
|
this.maybeFocus(true);
|
|
|
|
|
} else if (!open) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.setOpenState(true);
|
2018-09-05 21:28:54 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
event.preventDefault();
|
2018-11-09 14:23:19 +08:00
|
|
|
|
} else if (keyCode === KeyCode.SPACE) {
|
|
|
|
|
// Not block space if popup is shown
|
|
|
|
|
if (!open) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.setOpenState(true);
|
|
|
|
|
event.preventDefault();
|
2018-11-09 14:23:19 +08:00
|
|
|
|
}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
onInputKeydown(event) {
|
2020-03-07 19:45:13 +08:00
|
|
|
|
const { disabled, combobox, defaultActiveFirstOption } = this.$props;
|
|
|
|
|
if (disabled) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const state = this.$data;
|
2019-03-04 15:45:21 +08:00
|
|
|
|
const isRealOpen = this.getRealOpenState(state);
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const keyCode = event.keyCode;
|
2020-03-07 19:45:13 +08:00
|
|
|
|
if (isMultipleOrTags(this.$props) && !event.target.value && keyCode === KeyCode.BACKSPACE) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
const { _value: value } = state;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (value.length) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.removeSelected(value[value.length - 1]);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
if (keyCode === KeyCode.DOWN) {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (!state._open) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.openIfHasChildren();
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
return;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
} else if (keyCode === KeyCode.ENTER && state._open) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
// Aviod trigger form submit when select item
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/10861
|
2019-03-04 15:45:21 +08:00
|
|
|
|
// https://github.com/ant-design/ant-design/issues/14544
|
2020-03-18 14:52:02 +08:00
|
|
|
|
if (isRealOpen || !combobox) {
|
2019-03-04 15:45:21 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
}
|
2020-03-07 19:45:13 +08:00
|
|
|
|
// Hard close popup to avoid lock of non option in combobox mode
|
|
|
|
|
if (isRealOpen && combobox && defaultActiveFirstOption === false) {
|
|
|
|
|
this.comboboxTimer = setTimeout(() => {
|
|
|
|
|
this.setOpenState(false);
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
} else if (keyCode === KeyCode.ESC) {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (state._open) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.setOpenState(false);
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 15:45:21 +08:00
|
|
|
|
if (isRealOpen && this.selectTriggerRef) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const menu = this.selectTriggerRef.getInnerMenu();
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (menu && menu.onKeyDown(event, this.handleBackfill)) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
onMenuSelect({ item }) {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (!item) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
let value = this.$data._value;
|
|
|
|
|
const props = this.$props;
|
|
|
|
|
const selectedValue = getValuePropValue(item);
|
|
|
|
|
const lastValue = value[value.length - 1];
|
2020-03-07 19:45:13 +08:00
|
|
|
|
let skipTrigger = false;
|
|
|
|
|
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (isMultipleOrTags(props)) {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (findIndexInValueBySingleValue(value, selectedValue) !== -1) {
|
2020-03-07 19:45:13 +08:00
|
|
|
|
skipTrigger = true;
|
|
|
|
|
} else {
|
|
|
|
|
value = value.concat([selectedValue]);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
if (
|
2019-03-04 15:45:21 +08:00
|
|
|
|
!isCombobox(props) &&
|
2019-01-12 11:33:27 +08:00
|
|
|
|
lastValue !== undefined &&
|
|
|
|
|
lastValue === selectedValue &&
|
|
|
|
|
selectedValue !== this.$data._backfillValue
|
|
|
|
|
) {
|
2020-03-07 19:45:13 +08:00
|
|
|
|
this.setOpenState(false, { needFocus: true, fireSearch: false });
|
|
|
|
|
skipTrigger = true;
|
|
|
|
|
} else {
|
|
|
|
|
value = [selectedValue];
|
|
|
|
|
this.setOpenState(false, { needFocus: true, fireSearch: false });
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-07 19:45:13 +08:00
|
|
|
|
if (!skipTrigger) {
|
|
|
|
|
this.fireChange(value);
|
|
|
|
|
}
|
|
|
|
|
if (!skipTrigger) {
|
|
|
|
|
this.fireSelect(selectedValue);
|
|
|
|
|
const inputValue = isCombobox(props) ? getPropValue(item, props.optionLabelProp) : '';
|
2019-01-04 23:00:09 +08:00
|
|
|
|
|
2020-03-07 19:45:13 +08:00
|
|
|
|
if (props.autoClearSearchValue) {
|
|
|
|
|
this.setInputValue(inputValue, false);
|
|
|
|
|
}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
onMenuDeselect({ item, domEvent }) {
|
2018-11-09 14:23:19 +08:00
|
|
|
|
if (domEvent.type === 'keydown' && domEvent.keyCode === KeyCode.ENTER) {
|
2020-03-07 19:45:13 +08:00
|
|
|
|
const menuItemDomNode = item.$el;
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/20465#issuecomment-569033796
|
|
|
|
|
if (!isHidden(menuItemDomNode)) {
|
|
|
|
|
this.removeSelected(getValuePropValue(item));
|
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2018-11-09 14:23:19 +08:00
|
|
|
|
}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (domEvent.type === 'click') {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.removeSelected(getValuePropValue(item));
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (this.autoClearSearchValue) {
|
2020-03-07 19:45:13 +08:00
|
|
|
|
this.setInputValue('');
|
2018-09-05 21:28:54 +08:00
|
|
|
|
}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
onArrowClick(e) {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
e.preventDefault();
|
2019-09-27 18:44:11 +08:00
|
|
|
|
this.clearBlurTime();
|
2018-02-09 18:42:19 +08:00
|
|
|
|
if (!this.disabled) {
|
2020-03-07 19:45:13 +08:00
|
|
|
|
this.setOpenState(!this.$data._open, { needFocus: !this.$data._open });
|
2018-02-09 18:42:19 +08:00
|
|
|
|
}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-02-01 17:23:00 +08:00
|
|
|
|
onPlaceholderClick() {
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (this.getInputDOMNode() && this.getInputDOMNode()) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.getInputDOMNode().focus();
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
onPopupFocus() {
|
|
|
|
|
// fix ie scrollbar, focus element again
|
|
|
|
|
this.maybeFocus(true, true);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
onClearSelection(event) {
|
|
|
|
|
const props = this.$props;
|
|
|
|
|
const state = this.$data;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (props.disabled) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const { _inputValue: inputValue, _value: value } = state;
|
|
|
|
|
event.stopPropagation();
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (inputValue || value.length) {
|
|
|
|
|
if (value.length) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.fireChange([]);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2020-03-07 19:45:13 +08:00
|
|
|
|
this.setOpenState(false, { needFocus: true });
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (inputValue) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.setInputValue('');
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
onChoiceAnimationLeave() {
|
|
|
|
|
this.forcePopupAlign();
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
2018-09-05 21:28:54 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getOptionInfoBySingleValue(value, optionsInfo) {
|
|
|
|
|
let info;
|
|
|
|
|
optionsInfo = optionsInfo || this.$data._optionsInfo;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (optionsInfo[getMapKey(value)]) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
info = optionsInfo[getMapKey(value)];
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (info) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return info;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
let defaultLabel = value;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (this.$props.labelInValue) {
|
2020-03-07 19:45:13 +08:00
|
|
|
|
const valueLabel = getLabelFromPropsValue(this.$props.value, value);
|
|
|
|
|
const defaultValueLabel = getLabelFromPropsValue(this.$props.defaultValue, value);
|
|
|
|
|
if (valueLabel !== undefined) {
|
|
|
|
|
defaultLabel = valueLabel;
|
|
|
|
|
} else if (defaultValueLabel !== undefined) {
|
|
|
|
|
defaultLabel = defaultValueLabel;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
}
|
|
|
|
|
const defaultInfo = {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
option: (
|
|
|
|
|
<Option value={value} key={value}>
|
|
|
|
|
{value}
|
|
|
|
|
</Option>
|
|
|
|
|
),
|
2018-09-05 21:28:54 +08:00
|
|
|
|
value,
|
|
|
|
|
label: defaultLabel,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
|
|
|
|
return defaultInfo;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getOptionBySingleValue(value) {
|
|
|
|
|
const { option } = this.getOptionInfoBySingleValue(value);
|
|
|
|
|
return option;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getOptionsBySingleValue(values) {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
return values.map(value => {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return this.getOptionBySingleValue(value);
|
|
|
|
|
});
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
2018-11-09 14:23:19 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getValueByLabel(label) {
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (label === undefined) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return null;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
let value = null;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
Object.keys(this.$data._optionsInfo).forEach(key => {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const info = this.$data._optionsInfo[key];
|
2019-03-04 15:45:21 +08:00
|
|
|
|
const { disabled } = info;
|
|
|
|
|
if (disabled) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const oldLable = toArray(info.label);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (oldLable && oldLable.join('') === label) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
value = info.value;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
|
|
|
|
return value;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
2018-11-09 14:23:19 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getVLBySingleValue(value) {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (this.$props.labelInValue) {
|
|
|
|
|
return {
|
|
|
|
|
key: value,
|
|
|
|
|
label: this.getLabelBySingleValue(value),
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2018-02-24 20:54:55 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return value;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getVLForOnChange(vlsS) {
|
|
|
|
|
let vls = vlsS;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (vls !== undefined) {
|
|
|
|
|
if (!this.labelInValue) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
vls = vls.map(v => v);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
} else {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
vls = vls.map(vl => ({
|
|
|
|
|
key: vl,
|
|
|
|
|
label: this.getLabelBySingleValue(vl),
|
2019-01-12 11:33:27 +08:00
|
|
|
|
}));
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return isMultipleOrTags(this.$props) ? vls : vls[0];
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return vls;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getLabelBySingleValue(value, optionsInfo) {
|
|
|
|
|
const { label } = this.getOptionInfoBySingleValue(value, optionsInfo);
|
|
|
|
|
return label;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getDropdownContainer() {
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (!this.dropdownContainer) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.dropdownContainer = document.createElement('div');
|
|
|
|
|
document.body.appendChild(this.dropdownContainer);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return this.dropdownContainer;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getPlaceholderElement() {
|
|
|
|
|
const { $props: props, $data: state } = this;
|
|
|
|
|
let hidden = false;
|
2020-07-03 22:53:50 +08:00
|
|
|
|
if (state._inputValue) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
hidden = true;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const value = state._value;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (value.length) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
hidden = true;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2020-07-03 22:53:50 +08:00
|
|
|
|
if (isCombobox(props) && value.length === 1 && state._value && !state._value[0]) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
hidden = false;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const placeholder = props.placeholder;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (placeholder) {
|
2018-02-07 23:03:47 +08:00
|
|
|
|
const p = {
|
2020-06-28 23:11:31 +08:00
|
|
|
|
onMousedown: preventDefaultEvent,
|
|
|
|
|
onClick: this.onPlaceholderClick,
|
|
|
|
|
...UNSELECTABLE_ATTRIBUTE,
|
2018-02-07 23:03:47 +08:00
|
|
|
|
style: {
|
|
|
|
|
display: hidden ? 'none' : 'block',
|
|
|
|
|
...UNSELECTABLE_STYLE,
|
|
|
|
|
},
|
2018-09-05 21:28:54 +08:00
|
|
|
|
class: `${props.prefixCls}-selection__placeholder`,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
|
|
|
|
return <div {...p}>{placeholder}</div>;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return null;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
inputClick(e) {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (this.$data._open) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.clearBlurTime();
|
|
|
|
|
e.stopPropagation();
|
2018-02-26 22:19:48 +08:00
|
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this._focused = false;
|
2018-02-08 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2019-07-30 19:51:49 +08:00
|
|
|
|
inputBlur(e) {
|
2019-08-14 18:41:49 +08:00
|
|
|
|
const target = e.relatedTarget || document.activeElement;
|
2019-09-28 18:00:24 +08:00
|
|
|
|
|
|
|
|
|
// https://github.com/vueComponent/ant-design-vue/issues/999
|
|
|
|
|
// https://github.com/vueComponent/ant-design-vue/issues/1223
|
2019-07-30 19:51:49 +08:00
|
|
|
|
if (
|
2019-09-28 18:00:24 +08:00
|
|
|
|
(isIE || isEdge) &&
|
|
|
|
|
(e.relatedTarget === this.$refs.arrow ||
|
|
|
|
|
(target &&
|
|
|
|
|
this.selectTriggerRef &&
|
|
|
|
|
this.selectTriggerRef.getInnerMenu() &&
|
|
|
|
|
this.selectTriggerRef.getInnerMenu().$el === target) ||
|
|
|
|
|
contains(e.target, target))
|
2019-07-30 19:51:49 +08:00
|
|
|
|
) {
|
|
|
|
|
e.target.focus();
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.clearBlurTime();
|
2018-02-11 18:04:31 +08:00
|
|
|
|
if (this.disabled) {
|
2019-07-30 19:51:49 +08:00
|
|
|
|
e.preventDefault();
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2018-02-11 18:04:31 +08:00
|
|
|
|
}
|
2018-02-08 21:58:43 +08:00
|
|
|
|
this.blurTimer = setTimeout(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this._focused = false;
|
|
|
|
|
this.updateFocusClassName();
|
|
|
|
|
const props = this.$props;
|
|
|
|
|
let { _value: value } = this.$data;
|
|
|
|
|
const { _inputValue: inputValue } = this.$data;
|
2018-02-11 18:04:31 +08:00
|
|
|
|
if (
|
|
|
|
|
isSingleMode(props) &&
|
2019-01-12 11:33:27 +08:00
|
|
|
|
props.showSearch &&
|
|
|
|
|
inputValue &&
|
|
|
|
|
props.defaultActiveFirstOption
|
2018-02-11 18:04:31 +08:00
|
|
|
|
) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const options = this._options || [];
|
2018-02-11 18:04:31 +08:00
|
|
|
|
if (options.length) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const firstOption = findFirstMenuItem(options);
|
2018-02-11 18:04:31 +08:00
|
|
|
|
if (firstOption) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
value = [getValuePropValue(firstOption)];
|
|
|
|
|
this.fireChange(value);
|
2018-02-11 18:04:31 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (isMultipleOrTags(props) && inputValue) {
|
2018-11-09 14:23:19 +08:00
|
|
|
|
if (this._mouseDown) {
|
|
|
|
|
// need update dropmenu when not blur
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.setInputValue('');
|
2018-11-09 14:23:19 +08:00
|
|
|
|
} else {
|
|
|
|
|
// why not use setState?
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.$data._inputValue = '';
|
2019-06-30 21:56:24 +08:00
|
|
|
|
if (this.getInputDOMNode && this.getInputDOMNode()) {
|
|
|
|
|
this.getInputDOMNode().value = '';
|
|
|
|
|
}
|
2018-11-09 14:23:19 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const tmpValue = this.getValueByInput(inputValue);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (tmpValue !== undefined) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
value = tmpValue;
|
|
|
|
|
this.fireChange(value);
|
2018-09-05 21:28:54 +08:00
|
|
|
|
}
|
2018-02-08 21:58:43 +08:00
|
|
|
|
}
|
2018-11-09 14:23:19 +08:00
|
|
|
|
// if click the rest space of Select in multiple mode
|
|
|
|
|
if (isMultipleOrTags(props) && this._mouseDown) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.maybeFocus(true, true);
|
|
|
|
|
this._mouseDown = false;
|
|
|
|
|
return;
|
2018-11-09 14:23:19 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.setOpenState(false);
|
|
|
|
|
this.$emit('blur', this.getVLForOnChange(value));
|
2019-09-27 18:44:11 +08:00
|
|
|
|
}, 200);
|
2018-02-08 18:56:58 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
inputFocus(e) {
|
2018-11-09 14:23:19 +08:00
|
|
|
|
if (this.$props.disabled) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
return;
|
2018-11-09 14:23:19 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.clearBlurTime();
|
2020-03-07 19:45:13 +08:00
|
|
|
|
|
|
|
|
|
// In IE11, onOuterFocus will be trigger twice when focus input
|
|
|
|
|
// First one: e.target is div
|
|
|
|
|
// Second one: e.target is input
|
|
|
|
|
// other browser only trigger second one
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/15942
|
|
|
|
|
// Here we ignore the first one when e.target is div
|
|
|
|
|
const inputNode = this.getInputDOMNode();
|
|
|
|
|
if (inputNode && e.target === this.rootRef) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!isMultipleOrTagsOrCombobox(this.$props) && e.target === inputNode) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2018-11-09 14:23:19 +08:00
|
|
|
|
}
|
|
|
|
|
if (this._focused) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2018-11-09 14:23:19 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this._focused = true;
|
|
|
|
|
this.updateFocusClassName();
|
2018-11-09 14:23:19 +08:00
|
|
|
|
// only effect multiple or tag mode
|
|
|
|
|
if (!isMultipleOrTags(this.$props) || !this._mouseDown) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.timeoutFocus();
|
2018-11-09 14:23:19 +08:00
|
|
|
|
}
|
2018-02-09 18:42:19 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
_getInputElement() {
|
|
|
|
|
const props = this.$props;
|
2020-07-03 22:53:50 +08:00
|
|
|
|
const { _inputValue: inputValue } = this.$data;
|
2020-06-29 18:43:43 +08:00
|
|
|
|
const attrs = this.$attrs;
|
2020-07-03 22:53:50 +08:00
|
|
|
|
const defaultInput = (
|
|
|
|
|
<input {...(attrs.id !== undefined ? { id: attrs.id } : {})} autoComplete="off" />
|
|
|
|
|
);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const inputElement = props.getInputElement ? props.getInputElement() : defaultInput;
|
2020-06-29 18:43:43 +08:00
|
|
|
|
const inputCls = classnames(inputElement.class, {
|
2018-02-07 18:56:58 +08:00
|
|
|
|
[`${props.prefixCls}-search__field`]: true,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
|
|
|
|
const inputEvents = getEvents(inputElement);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
// https://github.com/ant-design/ant-design/issues/4992#issuecomment-281542159
|
|
|
|
|
// Add space to the end of the inputValue as the width measurement tolerance
|
|
|
|
|
return (
|
2018-03-01 12:34:31 +08:00
|
|
|
|
<div class={`${props.prefixCls}-search__field__wrap`} onClick={this.inputClick}>
|
2018-02-07 18:56:58 +08:00
|
|
|
|
{cloneElement(inputElement, {
|
2020-06-28 23:11:31 +08:00
|
|
|
|
disabled: props.disabled,
|
2020-06-29 18:43:43 +08:00
|
|
|
|
...(inputElement.props || {}),
|
2020-06-28 23:11:31 +08:00
|
|
|
|
disabled: props.disabled,
|
|
|
|
|
value: inputValue,
|
2018-02-07 18:56:58 +08:00
|
|
|
|
class: inputCls,
|
2020-06-28 23:11:31 +08:00
|
|
|
|
ref: this.saveInputRef,
|
2020-06-29 18:43:43 +08:00
|
|
|
|
// directives: [
|
|
|
|
|
// {
|
|
|
|
|
// name: 'ant-input',
|
|
|
|
|
// },
|
|
|
|
|
// ],
|
2020-06-28 23:11:31 +08:00
|
|
|
|
onInput: this.onInputChange,
|
|
|
|
|
onKeydown: chaining(
|
|
|
|
|
this.onInputKeydown,
|
|
|
|
|
inputEvents.onKeydown,
|
|
|
|
|
this.$attrs.onInputKeydown,
|
|
|
|
|
),
|
|
|
|
|
onFocus: chaining(this.inputFocus, inputEvents.onFocus),
|
|
|
|
|
onBlur: chaining(this.inputBlur, inputEvents.onBlur),
|
2018-02-07 18:56:58 +08:00
|
|
|
|
})}
|
2020-06-28 23:11:31 +08:00
|
|
|
|
<span ref={this.saveInputMirrorRef} class={`${props.prefixCls}-search__field__mirror`}>
|
2020-07-03 22:53:50 +08:00
|
|
|
|
{inputValue}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getInputDOMNode() {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
return this.topCtrlRef
|
|
|
|
|
? this.topCtrlRef.querySelector('input,textarea,div[contentEditable]')
|
2019-01-12 11:33:27 +08:00
|
|
|
|
: this.inputRef;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getInputMirrorDOMNode() {
|
|
|
|
|
return this.inputMirrorRef;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getPopupDOMNode() {
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (this.selectTriggerRef) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return this.selectTriggerRef.getPopupDOMNode();
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getPopupMenuComponent() {
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (this.selectTriggerRef) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return this.selectTriggerRef.getInnerMenu();
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2020-03-07 19:45:13 +08:00
|
|
|
|
setOpenState(open, config = {}) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const { $props: props, $data: state } = this;
|
2020-03-07 19:45:13 +08:00
|
|
|
|
const { needFocus, fireSearch } = config;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (state._open === open) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.maybeFocus(open, !!needFocus);
|
|
|
|
|
return;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.__emit('dropdownVisibleChange', open);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
const nextState = {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
_open: open,
|
2019-01-04 23:00:09 +08:00
|
|
|
|
_backfillValue: '',
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2018-02-07 18:56:58 +08:00
|
|
|
|
// clear search input value when open is false in singleMode.
|
|
|
|
|
if (!open && isSingleMode(props) && props.showSearch) {
|
2020-03-07 19:45:13 +08:00
|
|
|
|
this.setInputValue('', fireSearch);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
if (!open) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.maybeFocus(open, !!needFocus);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
this.setState(nextState, () => {
|
|
|
|
|
if (open) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.maybeFocus(open, !!needFocus);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
setInputValue(inputValue, fireSearch = true) {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (inputValue !== this.$data._inputValue) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.setState(
|
|
|
|
|
{
|
|
|
|
|
_inputValue: inputValue,
|
|
|
|
|
},
|
|
|
|
|
this.forcePopupAlign,
|
|
|
|
|
);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (fireSearch) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.$emit('search', inputValue);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getValueByInput(str) {
|
|
|
|
|
const { multiple, tokenSeparators } = this.$props;
|
|
|
|
|
let nextValue = this.$data._value;
|
|
|
|
|
let hasNewValue = false;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
splitBySeparators(str, tokenSeparators).forEach(label => {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const selectedValue = [label];
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (multiple) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const value = this.getValueByLabel(label);
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (value && findIndexInValueBySingleValue(nextValue, value) === -1) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
nextValue = nextValue.concat(value);
|
|
|
|
|
hasNewValue = true;
|
|
|
|
|
this.fireSelect(value);
|
2018-09-05 21:28:54 +08:00
|
|
|
|
}
|
2019-01-04 23:00:09 +08:00
|
|
|
|
} else if (findIndexInValueBySingleValue(nextValue, label) === -1) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
nextValue = nextValue.concat(selectedValue);
|
|
|
|
|
hasNewValue = true;
|
|
|
|
|
this.fireSelect(label);
|
2018-03-14 10:36:52 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
|
|
|
|
return hasNewValue ? nextValue : undefined;
|
2018-03-14 10:36:52 +08:00
|
|
|
|
},
|
2018-02-07 18:56:58 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
getRealOpenState(state) {
|
|
|
|
|
const { open: _open } = this.$props;
|
2018-11-09 14:23:19 +08:00
|
|
|
|
if (typeof _open === 'boolean') {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return _open;
|
2018-11-09 14:23:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
let open = (state || this.$data)._open;
|
|
|
|
|
const options = this._options || [];
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (isMultipleOrTagsOrCombobox(this.$props) || !this.$props.showSearch) {
|
|
|
|
|
if (open && !options.length) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
open = false;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return open;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
focus() {
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (isSingleMode(this.$props) && this.selectionRef) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.selectionRef.focus();
|
2019-01-04 23:00:09 +08:00
|
|
|
|
} else if (this.getInputDOMNode()) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.getInputDOMNode().focus();
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
blur() {
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (isSingleMode(this.$props) && this.selectionRef) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.selectionRef.blur();
|
2019-01-04 23:00:09 +08:00
|
|
|
|
} else if (this.getInputDOMNode()) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.getInputDOMNode().blur();
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
markMouseDown() {
|
|
|
|
|
this._mouseDown = true;
|
2018-11-09 14:23:19 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
markMouseLeave() {
|
|
|
|
|
this._mouseDown = false;
|
2018-11-09 14:23:19 +08:00
|
|
|
|
},
|
2018-02-07 18:56:58 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
handleBackfill(item) {
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (!this.backfill || !(isSingleMode(this.$props) || isCombobox(this.$props))) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const key = getValuePropValue(item);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
|
|
|
|
|
if (isCombobox(this.$props)) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.setInputValue(key, false);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setState({
|
2018-09-05 21:28:54 +08:00
|
|
|
|
_value: [key],
|
|
|
|
|
_backfillValue: key,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
_filterOption(input, child, defaultFilter = defaultFilterFn) {
|
|
|
|
|
const { _value: value, _backfillValue: backfillValue } = this.$data;
|
|
|
|
|
const lastValue = value[value.length - 1];
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (!input || (lastValue && lastValue === backfillValue)) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return true;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
let filterFn = this.$props.filterOption;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (hasProp(this, 'filterOption')) {
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (filterFn === true) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
filterFn = defaultFilter.bind(this);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
filterFn = defaultFilter.bind(this);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
if (!filterFn) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return true;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
} else if (typeof filterFn === 'function') {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return filterFn.call(this, input, child);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
} else if (getValue(child, 'disabled')) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return false;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return true;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
timeoutFocus() {
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (this.focusTimer) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.clearFocusTime();
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-04 23:00:09 +08:00
|
|
|
|
this.focusTimer = window.setTimeout(() => {
|
2018-11-09 14:23:19 +08:00
|
|
|
|
// this._focused = true
|
|
|
|
|
// this.updateFocusClassName()
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.$emit('focus');
|
|
|
|
|
}, 10);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
clearFocusTime() {
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (this.focusTimer) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
clearTimeout(this.focusTimer);
|
|
|
|
|
this.focusTimer = null;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
clearBlurTime() {
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (this.blurTimer) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
clearTimeout(this.blurTimer);
|
|
|
|
|
this.blurTimer = null;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2020-03-07 19:45:13 +08:00
|
|
|
|
clearComboboxTime() {
|
|
|
|
|
if (this.comboboxTimer) {
|
|
|
|
|
clearTimeout(this.comboboxTimer);
|
|
|
|
|
this.comboboxTimer = null;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
updateFocusClassName() {
|
|
|
|
|
const { rootRef, prefixCls } = this;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
// avoid setState and its side effect
|
|
|
|
|
if (this._focused) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
classes(rootRef).add(`${prefixCls}-focused`);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
classes(rootRef).remove(`${prefixCls}-focused`);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
maybeFocus(open, needFocus) {
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (needFocus || open) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const input = this.getInputDOMNode();
|
|
|
|
|
const { activeElement } = document;
|
2018-02-07 23:03:47 +08:00
|
|
|
|
if (input && (open || isMultipleOrTagsOrCombobox(this.$props))) {
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (activeElement !== input) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
input.focus();
|
|
|
|
|
this._focused = true;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-04 23:00:09 +08:00
|
|
|
|
} else if (activeElement !== this.selectionRef && this.selectionRef) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.selectionRef.focus();
|
|
|
|
|
this._focused = true;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
removeSelected(selectedKey, e) {
|
|
|
|
|
const props = this.$props;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (props.disabled || this.isChildDisabled(selectedKey)) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
// Do not trigger Trigger popup
|
|
|
|
|
if (e && e.stopPropagation) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
e.stopPropagation();
|
2018-09-05 21:28:54 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const oldValue = this.$data._value;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
const value = oldValue.filter(singleValue => {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return singleValue !== selectedKey;
|
|
|
|
|
});
|
|
|
|
|
const canMultiple = isMultipleOrTags(props);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
|
|
|
|
|
if (canMultiple) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
let event = selectedKey;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (props.labelInValue) {
|
|
|
|
|
event = {
|
|
|
|
|
key: selectedKey,
|
2018-09-05 21:28:54 +08:00
|
|
|
|
label: this.getLabelBySingleValue(selectedKey),
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.$emit('deselect', event, this.getOptionBySingleValue(selectedKey));
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.fireChange(value);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
openIfHasChildren() {
|
|
|
|
|
const { $props } = this;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (($props.children && $props.children.length) || isSingleMode($props)) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.setOpenState(true);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
fireSelect(value) {
|
|
|
|
|
this.$emit('select', this.getVLBySingleValue(value), this.getOptionBySingleValue(value));
|
2018-02-12 11:47:57 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
fireChange(value) {
|
2018-02-12 18:10:51 +08:00
|
|
|
|
if (!hasProp(this, 'value')) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.setState(
|
|
|
|
|
{
|
|
|
|
|
_value: value,
|
|
|
|
|
},
|
|
|
|
|
this.forcePopupAlign,
|
|
|
|
|
);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const vls = this.getVLForOnChange(value);
|
|
|
|
|
const options = this.getOptionsBySingleValue(value);
|
|
|
|
|
this._valueOptions = options;
|
2020-06-29 18:43:43 +08:00
|
|
|
|
this.$emit('update:value', vls);
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.$emit('change', vls, isMultipleOrTags(this.$props) ? options : options[0]);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
isChildDisabled(key) {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
return (this.$props.children || []).some(child => {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const childValue = getValuePropValue(child);
|
|
|
|
|
return childValue === key && getValue(child, 'disabled');
|
|
|
|
|
});
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
forcePopupAlign() {
|
2018-11-09 14:23:19 +08:00
|
|
|
|
if (!this.$data._open) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2018-11-09 14:23:19 +08:00
|
|
|
|
}
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (this.selectTriggerRef && this.selectTriggerRef.triggerRef) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.selectTriggerRef.triggerRef.forcePopupAlign();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
renderFilterOptions() {
|
|
|
|
|
const { _inputValue: inputValue } = this.$data;
|
2020-03-18 14:52:02 +08:00
|
|
|
|
const { children, tags, notFoundContent } = this.$props;
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const menuItems = [];
|
|
|
|
|
const childrenKeys = [];
|
2019-03-04 15:45:21 +08:00
|
|
|
|
let empty = false;
|
2019-01-12 11:33:27 +08:00
|
|
|
|
let options = this.renderFilterOptionsFromChildren(children, childrenKeys, menuItems);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (tags) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
// tags value must be string
|
|
|
|
|
let value = this.$data._value;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
value = value.filter(singleValue => {
|
|
|
|
|
return (
|
2018-09-05 21:28:54 +08:00
|
|
|
|
childrenKeys.indexOf(singleValue) === -1 &&
|
2019-01-12 11:33:27 +08:00
|
|
|
|
(!inputValue || String(singleValue).indexOf(String(inputValue)) > -1)
|
|
|
|
|
);
|
|
|
|
|
});
|
2019-03-04 15:45:21 +08:00
|
|
|
|
|
|
|
|
|
// sort by length
|
|
|
|
|
value.sort((val1, val2) => {
|
|
|
|
|
return val1.length - val2.length;
|
|
|
|
|
});
|
|
|
|
|
|
2018-02-07 18:56:58 +08:00
|
|
|
|
value.forEach(singleValue => {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const key = singleValue;
|
2019-03-16 09:14:55 +08:00
|
|
|
|
const attrs = {
|
|
|
|
|
...UNSELECTABLE_ATTRIBUTE,
|
|
|
|
|
role: 'option',
|
|
|
|
|
};
|
2018-02-07 18:56:58 +08:00
|
|
|
|
const menuItem = (
|
2020-06-28 23:11:31 +08:00
|
|
|
|
<MenuItem style={UNSELECTABLE_STYLE} {...attrs} value={key} key={key}>
|
2018-02-07 18:56:58 +08:00
|
|
|
|
{key}
|
|
|
|
|
</MenuItem>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
|
|
|
|
options.push(menuItem);
|
|
|
|
|
menuItems.push(menuItem);
|
|
|
|
|
});
|
2020-03-07 19:45:13 +08:00
|
|
|
|
// ref: https://github.com/ant-design/ant-design/issues/14090
|
|
|
|
|
if (inputValue && menuItems.every(option => getValuePropValue(option) !== inputValue)) {
|
|
|
|
|
const p = {
|
2020-06-28 23:11:31 +08:00
|
|
|
|
...UNSELECTABLE_ATTRIBUTE,
|
2020-03-07 19:45:13 +08:00
|
|
|
|
key: inputValue,
|
2020-06-28 23:11:31 +08:00
|
|
|
|
value: inputValue,
|
|
|
|
|
role: 'option',
|
2020-03-07 19:45:13 +08:00
|
|
|
|
style: UNSELECTABLE_STYLE,
|
|
|
|
|
};
|
|
|
|
|
options.unshift(<MenuItem {...p}>{inputValue}</MenuItem>);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!options.length && notFoundContent) {
|
2019-03-04 15:45:21 +08:00
|
|
|
|
empty = true;
|
2018-02-07 23:03:47 +08:00
|
|
|
|
const p = {
|
2020-06-28 23:11:31 +08:00
|
|
|
|
...UNSELECTABLE_ATTRIBUTE,
|
2018-02-07 23:03:47 +08:00
|
|
|
|
key: 'NOT_FOUND',
|
2020-06-28 23:11:31 +08:00
|
|
|
|
value: 'NOT_FOUND',
|
|
|
|
|
disabled: true,
|
|
|
|
|
role: 'option',
|
2018-02-07 23:03:47 +08:00
|
|
|
|
style: UNSELECTABLE_STYLE,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
|
|
|
|
options = [<MenuItem {...p}>{notFoundContent}</MenuItem>];
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-05-28 11:37:38 +08:00
|
|
|
|
return { empty, options };
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
renderFilterOptionsFromChildren(children = [], childrenKeys, menuItems) {
|
|
|
|
|
const sel = [];
|
|
|
|
|
const props = this.$props;
|
|
|
|
|
const { _inputValue: inputValue } = this.$data;
|
|
|
|
|
const tags = props.tags;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
children.forEach(child => {
|
2020-06-29 18:43:43 +08:00
|
|
|
|
if (!child) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2020-06-29 18:43:43 +08:00
|
|
|
|
const type = child.type;
|
|
|
|
|
if (type?.isSelectOptGroup) {
|
2020-06-28 23:11:31 +08:00
|
|
|
|
let label = getComponent(child, 'label');
|
2019-01-12 11:33:27 +08:00
|
|
|
|
let key = child.key;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (!key && typeof label === 'string') {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
key = label;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
} else if (!label && key) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
label = key;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
2020-06-28 23:11:31 +08:00
|
|
|
|
let childChildren = getComponent(child);
|
|
|
|
|
childChildren = Array.isArray(childChildren) ? childChildren : [childChildren];
|
2019-01-04 23:00:09 +08:00
|
|
|
|
// Match option group label
|
|
|
|
|
if (inputValue && this._filterOption(inputValue, child)) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const innerItems = childChildren.map(subChild => {
|
|
|
|
|
const childValueSub = getValuePropValue(subChild) || subChild.key;
|
|
|
|
|
return (
|
2020-06-28 23:11:31 +08:00
|
|
|
|
<MenuItem key={childValueSub} value={childValueSub} {...subChild.props}>
|
2020-06-30 18:31:58 +08:00
|
|
|
|
{...getSlot(subChild)}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
</MenuItem>
|
|
|
|
|
);
|
|
|
|
|
});
|
2019-01-04 23:00:09 +08:00
|
|
|
|
|
2018-02-07 18:56:58 +08:00
|
|
|
|
sel.push(
|
2020-07-03 22:53:50 +08:00
|
|
|
|
<MenuItemGroup key={key} title={label} class={child.props && child.props.class}>
|
2020-06-29 18:43:43 +08:00
|
|
|
|
{...innerItems}
|
2019-01-04 23:00:09 +08:00
|
|
|
|
</MenuItemGroup>,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
// Not match
|
2019-01-04 23:00:09 +08:00
|
|
|
|
} else {
|
|
|
|
|
const innerItems = this.renderFilterOptionsFromChildren(
|
|
|
|
|
childChildren,
|
|
|
|
|
childrenKeys,
|
|
|
|
|
menuItems,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
if (innerItems.length) {
|
|
|
|
|
sel.push(
|
2020-06-28 23:11:31 +08:00
|
|
|
|
<MenuItemGroup key={key} title={label} {...child.props}>
|
2020-06-29 18:43:43 +08:00
|
|
|
|
{...innerItems}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
</MenuItemGroup>,
|
|
|
|
|
);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-04 23:00:09 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2020-06-29 18:43:43 +08:00
|
|
|
|
warning(
|
|
|
|
|
typeof type === 'object' && type.isSelectOption,
|
|
|
|
|
'the children of `Select` should be `Select.Option` or `Select.OptGroup`, ',
|
|
|
|
|
);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const childValue = getValuePropValue(child);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
validateOptionValue(childValue, this.$props);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (this._filterOption(inputValue, child)) {
|
2018-02-07 23:03:47 +08:00
|
|
|
|
const p = {
|
2020-06-28 23:11:31 +08:00
|
|
|
|
...UNSELECTABLE_ATTRIBUTE,
|
2018-02-07 23:03:47 +08:00
|
|
|
|
key: childValue,
|
2020-06-28 23:11:31 +08:00
|
|
|
|
value: childValue,
|
|
|
|
|
...getPropsData(child),
|
|
|
|
|
role: 'option',
|
2018-02-07 23:03:47 +08:00
|
|
|
|
style: UNSELECTABLE_STYLE,
|
2020-06-28 23:11:31 +08:00
|
|
|
|
class: child?.class,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2020-06-30 18:31:58 +08:00
|
|
|
|
const menuItem = <MenuItem {...p}>{getSlot(child)}</MenuItem>;
|
2019-01-12 11:33:27 +08:00
|
|
|
|
sel.push(menuItem);
|
|
|
|
|
menuItems.push(menuItem);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (tags) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
childrenKeys.push(childValue);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2018-02-07 18:56:58 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return sel;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
renderTopControlNode() {
|
|
|
|
|
const { $props: props } = this;
|
|
|
|
|
const { _value: value, _inputValue: inputValue, _open: open } = this.$data;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
const {
|
|
|
|
|
choiceTransitionName,
|
|
|
|
|
prefixCls,
|
|
|
|
|
maxTagTextLength,
|
|
|
|
|
maxTagCount,
|
|
|
|
|
maxTagPlaceholder,
|
|
|
|
|
showSearch,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
} = props;
|
2020-06-28 23:11:31 +08:00
|
|
|
|
const removeIcon = getComponent(this, 'removeIcon');
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const className = `${prefixCls}-selection__rendered`;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
// search input is inside topControlNode in single, multiple & combobox. 2016/04/13
|
2019-01-12 11:33:27 +08:00
|
|
|
|
let innerNode = null;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (isSingleMode(props)) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
let selectedValue = null;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (value.length) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
let showSelectedValue = false;
|
|
|
|
|
let opacity = 1;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (!showSearch) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
showSelectedValue = true;
|
2018-11-09 14:23:19 +08:00
|
|
|
|
} else if (open) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
showSelectedValue = !inputValue;
|
2018-11-09 14:23:19 +08:00
|
|
|
|
if (showSelectedValue) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
opacity = 0.4;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2018-11-09 14:23:19 +08:00
|
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
showSelectedValue = true;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const singleValue = value[0];
|
|
|
|
|
const { label, title } = this.getOptionInfoBySingleValue(singleValue);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
selectedValue = (
|
|
|
|
|
<div
|
2019-01-12 11:33:27 +08:00
|
|
|
|
key="value"
|
2018-02-07 18:56:58 +08:00
|
|
|
|
class={`${prefixCls}-selection-selected-value`}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
title={toTitle(title || label)}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
style={{
|
|
|
|
|
display: showSelectedValue ? 'block' : 'none',
|
|
|
|
|
opacity,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2018-09-05 21:28:54 +08:00
|
|
|
|
{label}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
</div>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
if (!showSearch) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
innerNode = [selectedValue];
|
2018-02-07 18:56:58 +08:00
|
|
|
|
} else {
|
|
|
|
|
innerNode = [
|
|
|
|
|
selectedValue,
|
|
|
|
|
<div
|
|
|
|
|
class={`${prefixCls}-search ${prefixCls}-search--inline`}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
key="input"
|
2018-02-07 18:56:58 +08:00
|
|
|
|
style={{
|
2018-09-05 21:28:54 +08:00
|
|
|
|
display: open ? 'block' : 'none',
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{this._getInputElement()}
|
|
|
|
|
</div>,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
];
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
let selectedValueNodes = [];
|
|
|
|
|
let limitedCountValue = value;
|
|
|
|
|
let maxTagPlaceholderEl;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (maxTagCount !== undefined && value.length > maxTagCount) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
limitedCountValue = limitedCountValue.slice(0, maxTagCount);
|
|
|
|
|
const omittedValues = this.getVLForOnChange(value.slice(maxTagCount, value.length));
|
|
|
|
|
let content = `+ ${value.length - maxTagCount} ...`;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (maxTagPlaceholder) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
content =
|
|
|
|
|
typeof maxTagPlaceholder === 'function'
|
|
|
|
|
? maxTagPlaceholder(omittedValues)
|
|
|
|
|
: maxTagPlaceholder;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-03-16 09:14:55 +08:00
|
|
|
|
const attrs = {
|
|
|
|
|
...UNSELECTABLE_ATTRIBUTE,
|
|
|
|
|
role: 'presentation',
|
|
|
|
|
title: toTitle(content),
|
|
|
|
|
};
|
2019-01-12 11:33:27 +08:00
|
|
|
|
maxTagPlaceholderEl = (
|
|
|
|
|
<li
|
|
|
|
|
style={UNSELECTABLE_STYLE}
|
2020-06-28 23:11:31 +08:00
|
|
|
|
{...attrs}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
onMousedown={preventDefaultEvent}
|
|
|
|
|
class={`${prefixCls}-selection__choice ${prefixCls}-selection__choice__disabled`}
|
|
|
|
|
key="maxTagPlaceholder"
|
|
|
|
|
>
|
|
|
|
|
<div class={`${prefixCls}-selection__choice__content`}>{content}</div>
|
|
|
|
|
</li>
|
|
|
|
|
);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
if (isMultipleOrTags(props)) {
|
|
|
|
|
selectedValueNodes = limitedCountValue.map(singleValue => {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const info = this.getOptionInfoBySingleValue(singleValue);
|
|
|
|
|
let content = info.label;
|
|
|
|
|
const title = info.title || content;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (
|
|
|
|
|
maxTagTextLength &&
|
2019-01-12 11:33:27 +08:00
|
|
|
|
typeof content === 'string' &&
|
|
|
|
|
content.length > maxTagTextLength
|
2018-02-07 18:56:58 +08:00
|
|
|
|
) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
content = `${content.slice(0, maxTagTextLength)}...`;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const disabled = this.isChildDisabled(singleValue);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
const choiceClassName = disabled
|
|
|
|
|
? `${prefixCls}-selection__choice ${prefixCls}-selection__choice__disabled`
|
2019-01-12 11:33:27 +08:00
|
|
|
|
: `${prefixCls}-selection__choice`;
|
2019-03-16 09:14:55 +08:00
|
|
|
|
// attrs 放在一起,避免动态title混乱问题,很奇怪的问题 https://github.com/vueComponent/ant-design-vue/issues/588
|
|
|
|
|
const attrs = {
|
|
|
|
|
...UNSELECTABLE_ATTRIBUTE,
|
|
|
|
|
role: 'presentation',
|
|
|
|
|
title: toTitle(title),
|
|
|
|
|
};
|
2018-02-07 18:56:58 +08:00
|
|
|
|
return (
|
|
|
|
|
<li
|
|
|
|
|
style={UNSELECTABLE_STYLE}
|
2020-06-28 23:11:31 +08:00
|
|
|
|
{...attrs}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
onMousedown={preventDefaultEvent}
|
|
|
|
|
class={choiceClassName}
|
2018-11-09 14:23:19 +08:00
|
|
|
|
key={singleValue || SELECT_EMPTY_VALUE_KEY}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
<div class={`${prefixCls}-selection__choice__content`}>{content}</div>
|
2018-02-07 18:56:58 +08:00
|
|
|
|
{disabled ? null : (
|
|
|
|
|
<span
|
2019-01-12 11:33:27 +08:00
|
|
|
|
onClick={event => {
|
|
|
|
|
this.removeSelected(singleValue, event);
|
2018-09-05 21:28:54 +08:00
|
|
|
|
}}
|
2018-11-09 14:23:19 +08:00
|
|
|
|
class={`${prefixCls}-selection__choice__remove`}
|
|
|
|
|
>
|
|
|
|
|
{removeIcon || <i class={`${prefixCls}-selection__choice__remove-icon`}>×</i>}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
</span>
|
|
|
|
|
)}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
</li>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
|
|
|
|
});
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
if (maxTagPlaceholderEl) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
selectedValueNodes.push(maxTagPlaceholderEl);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
selectedValueNodes.push(
|
2019-01-12 11:33:27 +08:00
|
|
|
|
<li class={`${prefixCls}-search ${prefixCls}-search--inline`} key="__input">
|
2018-02-07 18:56:58 +08:00
|
|
|
|
{this._getInputElement()}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
</li>,
|
|
|
|
|
);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
|
|
|
|
|
if (isMultipleOrTags(props) && choiceTransitionName) {
|
|
|
|
|
const transitionProps = getTransitionProps(choiceTransitionName, {
|
|
|
|
|
tag: 'ul',
|
2020-06-29 18:43:43 +08:00
|
|
|
|
onAfterLeave: this.onChoiceAnimationLeave,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2020-07-03 22:53:50 +08:00
|
|
|
|
innerNode = <TransitionGroup {...transitionProps}>{selectedValueNodes}</TransitionGroup>;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
innerNode = <ul>{selectedValueNodes}</ul>;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return (
|
2020-06-28 23:11:31 +08:00
|
|
|
|
<div class={className} ref={this.saveTopCtrlRef} onClick={this.topCtrlContainerClick}>
|
2018-02-07 18:56:58 +08:00
|
|
|
|
{this.getPlaceholderElement()}
|
|
|
|
|
{innerNode}
|
|
|
|
|
</div>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
renderArrow(multiple) {
|
2019-03-04 15:45:21 +08:00
|
|
|
|
// showArrow : Set to true if not multiple by default but keep set value.
|
|
|
|
|
const { showArrow = !multiple, loading, prefixCls } = this.$props;
|
2020-06-28 23:11:31 +08:00
|
|
|
|
const inputIcon = getComponent(this, 'inputIcon');
|
2019-05-28 11:37:38 +08:00
|
|
|
|
if (!showArrow && !loading) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return null;
|
2019-01-04 23:00:09 +08:00
|
|
|
|
}
|
|
|
|
|
// if loading have loading icon
|
|
|
|
|
const defaultIcon = loading ? (
|
|
|
|
|
<i class={`${prefixCls}-arrow-loading`} />
|
|
|
|
|
) : (
|
|
|
|
|
<i class={`${prefixCls}-arrow-icon`} />
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
return (
|
|
|
|
|
<span
|
2019-01-12 11:33:27 +08:00
|
|
|
|
key="arrow"
|
2019-01-04 23:00:09 +08:00
|
|
|
|
class={`${prefixCls}-arrow`}
|
|
|
|
|
style={UNSELECTABLE_STYLE}
|
2020-06-28 23:11:31 +08:00
|
|
|
|
{...UNSELECTABLE_ATTRIBUTE}
|
2019-01-04 23:00:09 +08:00
|
|
|
|
onClick={this.onArrowClick}
|
2019-09-27 18:44:11 +08:00
|
|
|
|
ref="arrow"
|
2019-01-04 23:00:09 +08:00
|
|
|
|
>
|
|
|
|
|
{inputIcon || defaultIcon}
|
|
|
|
|
</span>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2019-01-04 23:00:09 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
topCtrlContainerClick(e) {
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (this.$data._open && !isSingleMode(this.$props)) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
e.stopPropagation();
|
2018-02-12 14:45:26 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
renderClear() {
|
|
|
|
|
const { prefixCls, allowClear } = this.$props;
|
|
|
|
|
const { _value: value, _inputValue: inputValue } = this.$data;
|
2020-06-28 23:11:31 +08:00
|
|
|
|
const clearIcon = getComponent(this, 'clearIcon');
|
2018-02-07 18:56:58 +08:00
|
|
|
|
const clear = (
|
|
|
|
|
<span
|
2019-01-12 11:33:27 +08:00
|
|
|
|
key="clear"
|
2018-11-09 14:23:19 +08:00
|
|
|
|
class={`${prefixCls}-selection__clear`}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
onMousedown={preventDefaultEvent}
|
|
|
|
|
style={UNSELECTABLE_STYLE}
|
2020-06-28 23:11:31 +08:00
|
|
|
|
{...UNSELECTABLE_ATTRIBUTE}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
onClick={this.onClearSelection}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
>
|
|
|
|
|
{clearIcon || <i class={`${prefixCls}-selection__clear-icon`}>×</i>}
|
|
|
|
|
</span>
|
|
|
|
|
);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
if (!allowClear) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return null;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
|
|
|
|
if (isCombobox(this.$props)) {
|
|
|
|
|
if (inputValue) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return clear;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return null;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (inputValue || value.length) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return clear;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
return null;
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
2018-11-09 14:23:19 +08:00
|
|
|
|
|
2020-03-18 14:52:02 +08:00
|
|
|
|
selectionRefClick() {
|
2019-07-30 19:51:49 +08:00
|
|
|
|
//e.stopPropagation();
|
2018-02-09 18:42:19 +08:00
|
|
|
|
if (!this.disabled) {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const input = this.getInputDOMNode();
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (this._focused && this.$data._open) {
|
2019-07-30 19:51:49 +08:00
|
|
|
|
// this._focused = false;
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.setOpenState(false, false);
|
|
|
|
|
input && input.blur();
|
2018-02-09 18:42:19 +08:00
|
|
|
|
} else {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.clearBlurTime();
|
2019-07-30 19:51:49 +08:00
|
|
|
|
//this._focused = true;
|
2019-01-12 11:33:27 +08:00
|
|
|
|
this.setOpenState(true, true);
|
|
|
|
|
input && input.focus();
|
2018-02-09 18:42:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-06-30 18:31:58 +08:00
|
|
|
|
selectionRefFocus() {
|
|
|
|
|
if (this.getInputDOMNode() && this.getInputDOMNode()) {
|
|
|
|
|
this.getInputDOMNode().focus();
|
2018-02-11 18:50:23 +08:00
|
|
|
|
}
|
2020-06-30 18:31:58 +08:00
|
|
|
|
// if (this._focused || this.disabled || isMultipleOrTagsOrCombobox(this.$props)) {
|
|
|
|
|
// e.preventDefault();
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// this._focused = true;
|
|
|
|
|
// this.updateFocusClassName();
|
|
|
|
|
// this.$emit('focus');
|
2018-02-11 18:50:23 +08:00
|
|
|
|
},
|
2019-07-30 19:51:49 +08:00
|
|
|
|
selectionRefBlur(e) {
|
|
|
|
|
if (isMultipleOrTagsOrCombobox(this.$props)) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.inputBlur(e);
|
2018-02-26 18:44:06 +08:00
|
|
|
|
},
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
render() {
|
|
|
|
|
const props = this.$props;
|
2020-06-28 23:11:31 +08:00
|
|
|
|
const { class: className, style } = this.$attrs;
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const multiple = isMultipleOrTags(props);
|
2019-03-04 15:45:21 +08:00
|
|
|
|
// Default set showArrow to true if not set (not set directly in defaultProps to handle multiple case)
|
|
|
|
|
const { showArrow = true } = props;
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const state = this.$data;
|
2019-03-04 15:45:21 +08:00
|
|
|
|
const { disabled, prefixCls, loading } = props;
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const { _open: open, _inputValue: inputValue, _value: value } = this.$data;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
if (open) {
|
2019-03-04 15:45:21 +08:00
|
|
|
|
const filterOptions = this.renderFilterOptions();
|
|
|
|
|
this._empty = filterOptions.empty;
|
|
|
|
|
this._options = filterOptions.options;
|
2018-09-05 21:28:54 +08:00
|
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const realOpen = this.getRealOpenState();
|
2019-03-04 15:45:21 +08:00
|
|
|
|
const empty = this._empty;
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const options = this._options || [];
|
2018-02-11 18:04:31 +08:00
|
|
|
|
const selectionProps = {
|
2020-06-28 23:11:31 +08:00
|
|
|
|
role: 'combobox',
|
|
|
|
|
'aria-autocomplete': 'list',
|
|
|
|
|
'aria-haspopup': 'true',
|
|
|
|
|
'aria-expanded': realOpen,
|
|
|
|
|
'aria-controls': this.$data._ariaId,
|
2018-02-11 18:04:31 +08:00
|
|
|
|
class: `${prefixCls}-selection ${prefixCls}-selection--${multiple ? 'multiple' : 'single'}`,
|
|
|
|
|
key: 'selection',
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2019-08-14 18:41:49 +08:00
|
|
|
|
//if (!isMultipleOrTagsOrCombobox(props)) {
|
2019-08-15 22:24:53 +08:00
|
|
|
|
// selectionProps.on.keydown = this.onKeyDown;
|
|
|
|
|
// selectionProps.on.focus = this.selectionRefFocus;
|
|
|
|
|
// selectionProps.on.blur = this.selectionRefBlur;
|
|
|
|
|
// selectionProps.attrs.tabIndex = props.disabled ? -1 : props.tabIndex;
|
2019-08-14 18:41:49 +08:00
|
|
|
|
//}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
const rootCls = {
|
2020-06-28 23:11:31 +08:00
|
|
|
|
[className]: className,
|
2018-02-26 18:44:06 +08:00
|
|
|
|
[prefixCls]: true,
|
2018-09-05 21:28:54 +08:00
|
|
|
|
[`${prefixCls}-open`]: open,
|
|
|
|
|
[`${prefixCls}-focused`]: open || !!this._focused,
|
2018-02-07 18:56:58 +08:00
|
|
|
|
[`${prefixCls}-combobox`]: isCombobox(props),
|
|
|
|
|
[`${prefixCls}-disabled`]: disabled,
|
|
|
|
|
[`${prefixCls}-enabled`]: !disabled,
|
|
|
|
|
[`${prefixCls}-allow-clear`]: !!props.allowClear,
|
2019-03-04 15:45:21 +08:00
|
|
|
|
[`${prefixCls}-no-arrow`]: !showArrow,
|
|
|
|
|
[`${prefixCls}-loading`]: !!loading,
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2018-02-07 18:56:58 +08:00
|
|
|
|
return (
|
|
|
|
|
<SelectTrigger
|
|
|
|
|
dropdownAlign={props.dropdownAlign}
|
2018-02-28 19:07:04 +08:00
|
|
|
|
dropdownClassName={props.dropdownClassName}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
dropdownMatchSelectWidth={props.dropdownMatchSelectWidth}
|
|
|
|
|
defaultActiveFirstOption={props.defaultActiveFirstOption}
|
|
|
|
|
dropdownMenuStyle={props.dropdownMenuStyle}
|
|
|
|
|
transitionName={props.transitionName}
|
|
|
|
|
animation={props.animation}
|
|
|
|
|
prefixCls={props.prefixCls}
|
|
|
|
|
dropdownStyle={props.dropdownStyle}
|
|
|
|
|
combobox={props.combobox}
|
|
|
|
|
showSearch={props.showSearch}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
options={options}
|
2019-03-04 15:45:21 +08:00
|
|
|
|
empty={empty}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
multiple={multiple}
|
|
|
|
|
disabled={disabled}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
visible={realOpen}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
inputValue={inputValue}
|
2018-09-05 21:28:54 +08:00
|
|
|
|
value={value}
|
|
|
|
|
backfillValue={state._backfillValue}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
firstActiveValue={props.firstActiveValue}
|
|
|
|
|
onDropdownVisibleChange={this.onDropdownVisibleChange}
|
|
|
|
|
getPopupContainer={props.getPopupContainer}
|
|
|
|
|
onMenuSelect={this.onMenuSelect}
|
|
|
|
|
onMenuDeselect={this.onMenuDeselect}
|
2020-06-28 23:11:31 +08:00
|
|
|
|
onPopupScroll={this.$attrs.onPopupScroll}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
onPopupFocus={this.onPopupFocus}
|
2020-06-28 23:11:31 +08:00
|
|
|
|
onMouseenter={this.$attrs.onMouseenter}
|
|
|
|
|
onMouseleave={this.$attrs.onMouseleave}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
showAction={props.showAction}
|
2020-06-28 23:11:31 +08:00
|
|
|
|
menuItemSelectedIcon={getComponent(this, 'menuItemSelectedIcon')}
|
2020-06-28 17:50:33 +08:00
|
|
|
|
ref={this.saveSelectTriggerRef}
|
2019-01-04 23:00:09 +08:00
|
|
|
|
dropdownRender={props.dropdownRender}
|
2019-01-08 23:03:13 +08:00
|
|
|
|
ariaId={this.$data._ariaId}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
>
|
|
|
|
|
<div
|
2020-06-28 23:11:31 +08:00
|
|
|
|
ref={chaining(this.saveRootRef, this.saveSelectionRef)}
|
|
|
|
|
style={style}
|
2018-02-12 11:47:57 +08:00
|
|
|
|
class={classnames(rootCls)}
|
2018-11-09 14:23:19 +08:00
|
|
|
|
onMousedown={this.markMouseDown}
|
|
|
|
|
onMouseup={this.markMouseLeave}
|
|
|
|
|
onMouseout={this.markMouseLeave}
|
2019-08-14 18:41:49 +08:00
|
|
|
|
tabIndex={props.disabled ? -1 : props.tabIndex}
|
2019-07-30 19:51:49 +08:00
|
|
|
|
onBlur={this.selectionRefBlur}
|
|
|
|
|
onFocus={this.selectionRefFocus}
|
|
|
|
|
onClick={this.selectionRefClick}
|
2019-08-14 18:41:49 +08:00
|
|
|
|
onKeydown={isMultipleOrTagsOrCombobox(props) ? noop : this.onKeyDown}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
>
|
2018-02-11 18:04:31 +08:00
|
|
|
|
<div {...selectionProps}>
|
2020-06-28 23:11:31 +08:00
|
|
|
|
{this.renderTopControlNode()}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
{this.renderClear()}
|
2019-01-04 23:00:09 +08:00
|
|
|
|
{this.renderArrow(!!multiple)}
|
2018-02-07 18:56:58 +08:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</SelectTrigger>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2018-02-07 18:56:58 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
|
|
|
|
export { Select };
|
2020-06-28 23:11:31 +08:00
|
|
|
|
export default Select;
|