select: refactoring icon reverse (#12353)

* select: refactoring icon reverse

* select: disable clear icon when select popup is visible

* select: refactoring clear icon
pull/13029/head
firesh 2018-10-11 18:41:18 +08:00 committed by hetech
parent 5beaa67b01
commit c8ce0410f9
2 changed files with 15 additions and 30 deletions

View File

@ -94,10 +94,10 @@
<template slot="prefix" v-if="$slots.prefix"> <template slot="prefix" v-if="$slots.prefix">
<slot name="prefix"></slot> <slot name="prefix"></slot>
</template> </template>
<i slot="suffix" <template slot="suffix">
:class="['el-select__caret', 'el-input__icon', 'el-icon-' + iconClass]" <i v-show="!showClose" :class="['el-select__caret', 'el-input__icon', 'el-icon-' + iconClass]"></i>
@click="handleIconClick" <i v-if="showClose" class="el-select__caret el-input__icon el-icon-circle-close" @click="handleClearClick"></i>
></i> </template>
</el-input> </el-input>
<transition <transition
name="el-zoom-in-top" name="el-zoom-in-top"
@ -143,7 +143,6 @@
import ElScrollbar from 'element-ui/packages/scrollbar'; import ElScrollbar from 'element-ui/packages/scrollbar';
import debounce from 'throttle-debounce/debounce'; import debounce from 'throttle-debounce/debounce';
import Clickoutside from 'element-ui/src/utils/clickoutside'; import Clickoutside from 'element-ui/src/utils/clickoutside';
import { addClass, removeClass, hasClass } from 'element-ui/src/utils/dom';
import { addResizeListener, removeResizeListener } from 'element-ui/src/utils/resize-event'; import { addResizeListener, removeResizeListener } from 'element-ui/src/utils/resize-event';
import { t } from 'element-ui/src/locale'; import { t } from 'element-ui/src/locale';
import scrollIntoView from 'element-ui/src/utils/scroll-into-view'; import scrollIntoView from 'element-ui/src/utils/scroll-into-view';
@ -186,7 +185,7 @@
return !this.filterable || this.multiple || !isIE && !this.visible; return !this.filterable || this.multiple || !isIE && !this.visible;
}, },
iconClass() { showClose() {
let criteria = this.clearable && let criteria = this.clearable &&
!this.selectDisabled && !this.selectDisabled &&
this.inputHovering && this.inputHovering &&
@ -194,7 +193,11 @@
this.value !== undefined && this.value !== undefined &&
this.value !== null && this.value !== null &&
this.value !== ''; this.value !== '';
return criteria ? 'circle-close is-show-close' : (this.remote && this.filterable ? '' : 'arrow-up'); return criteria;
},
iconClass() {
return this.remote && this.filterable ? '' : (this.visible ? 'arrow-up is-reverse' : 'arrow-up');
}, },
debounce() { debounce() {
@ -366,7 +369,6 @@
visible(val) { visible(val) {
if (!val) { if (!val) {
this.handleIconHide();
this.broadcast('ElSelectDropdown', 'destroyPopper'); this.broadcast('ElSelectDropdown', 'destroyPopper');
if (this.$refs.input) { if (this.$refs.input) {
this.$refs.input.blur(); this.$refs.input.blur();
@ -395,7 +397,6 @@
} }
} }
} else { } else {
this.handleIconShow();
this.broadcast('ElSelectDropdown', 'updatePopper'); this.broadcast('ElSelectDropdown', 'updatePopper');
if (this.filterable) { if (this.filterable) {
this.query = this.remote ? '' : this.selectedLabel; this.query = this.remote ? '' : this.selectedLabel;
@ -479,20 +480,6 @@
} }
}, },
handleIconHide() {
let icon = this.$el.querySelector('.el-input__icon');
if (icon) {
removeClass(icon, 'is-reverse');
}
},
handleIconShow() {
let icon = this.$el.querySelector('.el-input__icon');
if (icon && !hasClass(icon, 'el-icon-circle-close')) {
addClass(icon, 'is-reverse');
}
},
scrollToOption(option) { scrollToOption(option) {
const target = Array.isArray(option) && option[0] ? option[0].$el : option.$el; const target = Array.isArray(option) && option[0] ? option[0].$el : option.$el;
if (this.$refs.popper && target) { if (this.$refs.popper && target) {
@ -594,10 +581,8 @@
this.softFocus = false; this.softFocus = false;
}, },
handleIconClick(event) { handleClearClick(event) {
if (this.iconClass.indexOf('circle-close') > -1) { this.deleteSelected(event);
this.deleteSelected(event);
}
}, },
doDestroy() { doDestroy() {

View File

@ -285,9 +285,9 @@ describe('Select', () => {
vm.value = '选项1'; vm.value = '选项1';
select.inputHovering = true; select.inputHovering = true;
setTimeout(() => { setTimeout(() => {
const icon = vm.$el.querySelector('.el-input__icon'); const iconClear = vm.$el.querySelector('.el-input__icon.el-icon-circle-close');
expect(icon.classList.contains('el-icon-circle-close')).to.true; expect(iconClear).to.exist;
icon.click(); iconClear.click();
expect(vm.value).to.equal(''); expect(vm.value).to.equal('');
done(); done();
}, 100); }, 100);