Merge pull request #1160 from 2betop/select

select clearable 逻辑优化
This commit is contained in:
吴多益 2020-12-10 10:18:24 +08:00 committed by GitHub
commit fed65a10b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,6 +109,7 @@ export interface OptionProps {
extractValue?: boolean;
delimiter?: string;
clearable?: boolean;
resetValue: any;
placeholder?: string;
disabled?: boolean;
creatable?: boolean;
@ -362,6 +363,7 @@ export class Select extends React.Component<SelectProps, SelectState> {
placeholder: '请选择',
valueField: 'value',
labelField: 'label',
resetValue: '',
inline: false,
disabled: false,
checkAll: false,
@ -663,7 +665,7 @@ export class Select extends React.Component<SelectProps, SelectState> {
const onChange = this.props.onChange;
e.preventDefault();
e.stopPropagation();
onChange('');
onChange(this.props.resetValue);
}
handleAddClick() {
@ -970,6 +972,7 @@ export class Select extends React.Component<SelectProps, SelectState> {
const selection = this.state.selection;
const inputValue = this.state.inputValue;
const resetValue = this.props.resetValue;
return (
<Downshift
@ -1011,7 +1014,9 @@ export class Select extends React.Component<SelectProps, SelectState> {
<div className={cx(`Select-valueWrap`)}>
{this.renderValue(options)}
</div>
{clearable && !disabled && value && value.length ? (
{clearable &&
!disabled &&
(Array.isArray(value) ? value.length : value !== resetValue) ? (
<a onClick={this.clearValue} className={cx('Select-clear')}>
<Icon icon="close" className="icon" />
</a>