mirror of https://github.com/ElemeFE/element
Select: allows user to choose if select focus triggers menu (#10042)
* Select: Preserves focus after options selected * Select: softFocus: Passing lint Write test * Select: Soft focus: Include input ref * Revert src/index.js * Update select.vue * Select: Default focus on select does not open menu. Added attribute for automatic-dropdown. Includes tests * Select: remove trailing space * Select: Removing incorrectly applied automatic-update props from input elements * Select: Fixed up references to correct focus tests * Select - Checking if automatic dropdown already revealed menu when toggling menu - Updating test: removing timeouts for related test * Update select.vuepull/10727/head
parent
43781c9c5b
commit
25fcfb34d7
|
@ -49,6 +49,7 @@
|
||||||
:disabled="selectDisabled"
|
:disabled="selectDisabled"
|
||||||
:autocomplete="autoComplete"
|
:autocomplete="autoComplete"
|
||||||
@focus="handleFocus"
|
@focus="handleFocus"
|
||||||
|
@blur="softFocus = false"
|
||||||
@click.stop
|
@click.stop
|
||||||
@keyup="managePlaceholder"
|
@keyup="managePlaceholder"
|
||||||
@keydown="resetInputState"
|
@keydown="resetInputState"
|
||||||
|
@ -252,6 +253,7 @@
|
||||||
type: String,
|
type: String,
|
||||||
default: 'off'
|
default: 'off'
|
||||||
},
|
},
|
||||||
|
automaticDropdown: Boolean,
|
||||||
size: String,
|
size: String,
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
clearable: Boolean,
|
clearable: Boolean,
|
||||||
|
@ -309,6 +311,7 @@
|
||||||
previousQuery: null,
|
previousQuery: null,
|
||||||
inputHovering: false,
|
inputHovering: false,
|
||||||
currentPlaceholder: '',
|
currentPlaceholder: '',
|
||||||
|
menuVisibleOnFocus: false,
|
||||||
isOnComposition: false
|
isOnComposition: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -546,6 +549,10 @@
|
||||||
|
|
||||||
handleFocus(event) {
|
handleFocus(event) {
|
||||||
if (!this.softFocus) {
|
if (!this.softFocus) {
|
||||||
|
if (this.automaticDropdown || event.target.className.indexOf('el-select__input') > -1) {
|
||||||
|
this.visible = true;
|
||||||
|
this.menuVisibleOnFocus = true;
|
||||||
|
}
|
||||||
this.$emit('focus', event);
|
this.$emit('focus', event);
|
||||||
} else {
|
} else {
|
||||||
this.softFocus = false;
|
this.softFocus = false;
|
||||||
|
@ -559,6 +566,7 @@
|
||||||
|
|
||||||
handleBlur(event) {
|
handleBlur(event) {
|
||||||
this.$emit('blur', event);
|
this.$emit('blur', event);
|
||||||
|
this.softFocus = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
handleIconClick(event) {
|
handleIconClick(event) {
|
||||||
|
@ -698,7 +706,11 @@
|
||||||
|
|
||||||
toggleMenu() {
|
toggleMenu() {
|
||||||
if (!this.selectDisabled) {
|
if (!this.selectDisabled) {
|
||||||
this.visible = !this.visible;
|
if (this.menuVisibleOnFocus) {
|
||||||
|
this.menuVisibleOnFocus = false;
|
||||||
|
} else {
|
||||||
|
this.visible = !this.visible;
|
||||||
|
}
|
||||||
if (this.visible) {
|
if (this.visible) {
|
||||||
(this.$refs.input || this.$refs.reference).focus();
|
(this.$refs.input || this.$refs.reference).focus();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import Select from 'packages/select';
|
||||||
|
|
||||||
describe('Select', () => {
|
describe('Select', () => {
|
||||||
const getSelectVm = (configs = {}, options) => {
|
const getSelectVm = (configs = {}, options) => {
|
||||||
['multiple', 'clearable', 'filterable', 'allowCreate', 'remote', 'collapseTags'].forEach(config => {
|
['multiple', 'clearable', 'filterable', 'allowCreate', 'remote', 'collapseTags', 'automaticDropdown'].forEach(config => {
|
||||||
configs[config] = configs[config] || false;
|
configs[config] = configs[config] || false;
|
||||||
});
|
});
|
||||||
configs.multipleLimit = configs.multipleLimit || 0;
|
configs.multipleLimit = configs.multipleLimit || 0;
|
||||||
|
@ -46,7 +46,8 @@ describe('Select', () => {
|
||||||
:filterMethod="filterMethod"
|
:filterMethod="filterMethod"
|
||||||
:remote="remote"
|
:remote="remote"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
:remoteMethod="remoteMethod">
|
:remoteMethod="remoteMethod"
|
||||||
|
:automatic-dropdown="automaticDropdown">
|
||||||
<el-option
|
<el-option
|
||||||
v-for="item in options"
|
v-for="item in options"
|
||||||
:label="item.label"
|
:label="item.label"
|
||||||
|
@ -68,6 +69,7 @@ describe('Select', () => {
|
||||||
collapseTags: configs.collapseTags,
|
collapseTags: configs.collapseTags,
|
||||||
allowCreate: configs.allowCreate,
|
allowCreate: configs.allowCreate,
|
||||||
popperClass: configs.popperClass,
|
popperClass: configs.popperClass,
|
||||||
|
automaticDropdown: configs.automaticDropdown,
|
||||||
loading: false,
|
loading: false,
|
||||||
filterMethod: configs.filterMethod && configs.filterMethod(this),
|
filterMethod: configs.filterMethod && configs.filterMethod(this),
|
||||||
remote: configs.remote,
|
remote: configs.remote,
|
||||||
|
@ -668,7 +670,7 @@ describe('Select', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('soft focus', done => {
|
it('should return focus to input inside select after option select', done => {
|
||||||
vm = createVue({
|
vm = createVue({
|
||||||
template: `
|
template: `
|
||||||
<div>
|
<div>
|
||||||
|
@ -701,6 +703,28 @@ describe('Select', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not open popper when automatic-dropdown not set', done => {
|
||||||
|
vm = getSelectVm();
|
||||||
|
|
||||||
|
vm.$refs.select.$refs.reference.$refs.input.focus();
|
||||||
|
|
||||||
|
vm.$nextTick(_ => {
|
||||||
|
expect(vm.$refs.select.visible).to.be.false;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should open popper when automatic-dropdown is set', done => {
|
||||||
|
vm = getSelectVm({ automaticDropdown: true });
|
||||||
|
|
||||||
|
vm.$refs.select.$refs.reference.$refs.input.focus();
|
||||||
|
|
||||||
|
vm.$nextTick(_ => {
|
||||||
|
expect(vm.$refs.select.visible).to.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('focus', done => {
|
it('focus', done => {
|
||||||
vm = createVue({
|
vm = createVue({
|
||||||
template: `
|
template: `
|
||||||
|
|
Loading…
Reference in New Issue