Cascader: close when option clicked (#11623)

* Cascader: close when option clicked in hover mode

* update menu.vue
pull/11631/head
hetech 2018-06-14 17:50:10 +08:00 committed by 杨奕
parent 25ffe8c97e
commit 7bee91a517
3 changed files with 79 additions and 2 deletions

View File

@ -389,8 +389,8 @@ export default {
ev.stopPropagation();
this.handlePick([], true);
},
handleClickoutside() {
if (this.menuVisible) {
handleClickoutside(pickFinished = false) {
if (this.menuVisible && !pickFinished) {
this.needFocus = false;
}
this.menuVisible = false;

View File

@ -238,6 +238,13 @@
});
};
events.on[triggerEvent] = triggerHandler;
if (triggerEvent === 'mouseenter' && this.changeOnSelect) {
events.on.click = () => {
if (this.activeValue.indexOf(item.value) !== -1) {
this.$emit('closeInside', true);
}
};
}
events.on['mousedown'] = () => {
this.clicking = true;
};

View File

@ -538,6 +538,76 @@ describe('Cascader', () => {
});
}, 300);
});
it('hover and select', done => {
vm = createVue({
template: `
<el-cascader
ref="cascader"
placeholder="请选择"
:options="options"
expand-trigger="hover"
change-on-select
v-model="selectedOptions"
></el-cascader>
`,
data() {
return {
options: [{
value: 'zhejiang',
label: 'Zhejiang',
children: [{
value: 'hangzhou',
label: 'Hangzhou',
children: [{
value: 'xihu',
label: 'West Lake'
}]
}, {
value: 'ningbo',
label: 'NingBo',
children: [{
value: 'jiangbei',
label: 'Jiang Bei'
}]
}]
}, {
value: 'jiangsu',
label: 'Jiangsu',
children: [{
value: 'nanjing',
label: 'Nanjing',
children: [{
value: 'zhonghuamen',
label: 'Zhong Hua Men'
}]
}]
}],
selectedOptions: []
};
}
}, true);
vm.$el.click();
vm.$nextTick(() => {
const menu = vm.$refs.cascader.menu;
const menuElm = menu.$el;
const item1 = menuElm.querySelector('.el-cascader-menu__item');
triggerEvent(item1, 'mouseenter');
menu.$nextTick(() => {
expect(vm.selectedOptions[0]).to.be.equal('zhejiang');
const spy = sinon.spy();
menu.$on('closeInside', spy);
item1.click();
menu.$nextTick(() => {
expect(spy.calledWith(true)).to.be.true;
expect(menu.visible).to.be.false;
done();
});
});
});
});
it('filterable', done => {
vm = createVue({
template: `