Skip to content

Commit

Permalink
select: refactoring icon reverse (#12353)
Browse files Browse the repository at this point in the history
* select: refactoring icon reverse

* select: disable clear icon when select popup is visible

* select: refactoring clear icon
  • Loading branch information
firesh authored and ziyoung committed Oct 11, 2018
1 parent 5beaa67 commit c8ce041
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
39 changes: 12 additions & 27 deletions packages/select/src/select.vue
Expand Up @@ -94,10 +94,10 @@
<template slot="prefix" v-if="$slots.prefix">
<slot name="prefix"></slot>
</template>
<i slot="suffix"
:class="['el-select__caret', 'el-input__icon', 'el-icon-' + iconClass]"
@click="handleIconClick"
></i>
<template slot="suffix">
<i v-show="!showClose" :class="['el-select__caret', 'el-input__icon', 'el-icon-' + iconClass]"></i>
<i v-if="showClose" class="el-select__caret el-input__icon el-icon-circle-close" @click="handleClearClick"></i>
</template>
</el-input>
<transition
name="el-zoom-in-top"
Expand Down Expand Up @@ -143,7 +143,6 @@
import ElScrollbar from 'element-ui/packages/scrollbar';
import debounce from 'throttle-debounce/debounce';
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 { t } from 'element-ui/src/locale';
import scrollIntoView from 'element-ui/src/utils/scroll-into-view';
Expand Down Expand Up @@ -186,15 +185,19 @@
return !this.filterable || this.multiple || !isIE && !this.visible;
},
iconClass() {
showClose() {
let criteria = this.clearable &&
!this.selectDisabled &&
this.inputHovering &&
!this.multiple &&
this.value !== undefined &&
this.value !== null &&
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() {
Expand Down Expand Up @@ -366,7 +369,6 @@
visible(val) {
if (!val) {
this.handleIconHide();
this.broadcast('ElSelectDropdown', 'destroyPopper');
if (this.$refs.input) {
this.$refs.input.blur();
Expand Down Expand Up @@ -395,7 +397,6 @@
}
}
} else {
this.handleIconShow();
this.broadcast('ElSelectDropdown', 'updatePopper');
if (this.filterable) {
this.query = this.remote ? '' : this.selectedLabel;
Expand Down Expand Up @@ -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) {
const target = Array.isArray(option) && option[0] ? option[0].$el : option.$el;
if (this.$refs.popper && target) {
Expand Down Expand Up @@ -594,10 +581,8 @@
this.softFocus = false;
},
handleIconClick(event) {
if (this.iconClass.indexOf('circle-close') > -1) {
this.deleteSelected(event);
}
handleClearClick(event) {
this.deleteSelected(event);
},
doDestroy() {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/specs/select.spec.js
Expand Up @@ -285,9 +285,9 @@ describe('Select', () => {
vm.value = '选项1';
select.inputHovering = true;
setTimeout(() => {
const icon = vm.$el.querySelector('.el-input__icon');
expect(icon.classList.contains('el-icon-circle-close')).to.true;
icon.click();
const iconClear = vm.$el.querySelector('.el-input__icon.el-icon-circle-close');
expect(iconClear).to.exist;
iconClear.click();
expect(vm.value).to.equal('');
done();
}, 100);
Expand Down

0 comments on commit c8ce041

Please sign in to comment.