Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown: compatible with 2.6 new v-slot syntax #14832

Merged
merged 1 commit into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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