Skip to content

Commit

Permalink
Dropdown: compatible with 2.6 new v-slot syntax (ElemeFE#14832)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyoung authored and Feng committed Jun 20, 2019
1 parent eaa63a8 commit 18eaa95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
7 changes: 5 additions & 2 deletions packages/dropdown/src/dropdown-menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@
},
mounted() {
this.$parent.popperElm = this.popperElm = this.$el;
this.referenceElm = this.$parent.$el;
this.dropdown.popperElm = this.popperElm = this.$el;
this.referenceElm = this.dropdown.$el;
// compatible with 2.6 new v-slot syntax
// issue link https://github.com/ElemeFE/element/issues/14345
this.dropdown.initDomOperation();
},
watch: {
Expand Down
16 changes: 9 additions & 7 deletions packages/dropdown/src/dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@
mounted() {
this.$on('menu-item-click', this.handleMenuItemClick);
this.initEvent();
this.initAria();
},
watch: {
Expand Down Expand Up @@ -145,7 +143,6 @@
} else if ([9, 27].indexOf(keyCode) > -1) { // tab || esc
this.hide();
}
return;
},
handleItemKeyDown(ev) {
const keyCode = ev.keyCode;
Expand Down Expand Up @@ -174,7 +171,6 @@
this.hide();
this.triggerElm.focus();
}
return;
},
resetTabindex(ele) { // 下次tab时组件聚焦元素
this.removeTabindex();
Expand All @@ -190,8 +186,6 @@
this.dropdownElm.setAttribute('id', this.listId);
this.triggerElm.setAttribute('aria-haspopup', 'list');
this.triggerElm.setAttribute('aria-controls', this.listId);
this.menuItems = this.dropdownElm.querySelectorAll("[tabindex='-1']");
this.menuItemsArray = Array.prototype.slice.call(this.menuItems);
if (!this.splitButton) { // 自定义
this.triggerElm.setAttribute('role', 'button');
Expand All @@ -205,7 +199,7 @@
? this.$refs.trigger.$el
: this.$slots.default[0].elm;
let dropdownElm = this.dropdownElm = this.$slots.dropdown[0].elm;
let dropdownElm = this.dropdownElm;
this.triggerElm.addEventListener('keydown', handleTriggerKeyDown); // triggerElm keydown
dropdownElm.addEventListener('keydown', handleItemKeyDown, true); // item keydown
Expand Down Expand Up @@ -238,6 +232,14 @@
},
focus() {
this.triggerElm.focus && this.triggerElm.focus();
},
initDomOperation() {
this.dropdownElm = this.popperElm;
this.menuItems = this.dropdownElm.querySelectorAll("[tabindex='-1']");
this.menuItemsArray = [].slice.call(this.menuItems);
this.initEvent();
this.initAria();
}
},
Expand Down

0 comments on commit 18eaa95

Please sign in to comment.