[improvement] DropdownMenu: close menu when click outside

This commit is contained in:
陈嘉涵 2019-05-10 16:24:08 +08:00
parent 8558c931c8
commit 12941b05ea
2 changed files with 12 additions and 1 deletions

View File

@ -46,6 +46,7 @@ export default sfc({
return (
<Cell
clickable
key={option.value}
title={option.text}
titleStyle={{ color: active ? activeColor : '' }}
onClick={() => {

View File

@ -1,11 +1,15 @@
import { use } from '../utils';
import { BLUE } from '../utils/color';
import { ParentMixin } from '../mixins/relation';
import { ClickOutsideMixin } from '../mixins/click-outside';
const [sfc, bem] = use('dropdown-menu');
export default sfc({
mixins: [ParentMixin('vanDropdownMenu')],
mixins: [ParentMixin('vanDropdownMenu'), ClickOutsideMixin({
event: 'click',
method: 'onClickOutside'
})],
props: {
overlay: {
@ -45,6 +49,12 @@ export default sfc({
item.toggle(false);
}
});
},
onClickOutside() {
this.children.forEach(item => {
item.toggle(false);
});
}
},