|
@@ -1,5 +1,6 @@
|
|
|
<script>
|
|
|
import { isDef } from 'element-ui/src/utils/shared';
|
|
|
+ import scrollIntoView from 'element-ui/src/utils/scroll-into-view';
|
|
|
|
|
|
export default {
|
|
|
name: 'ElCascaderMenu',
|
|
@@ -94,6 +95,19 @@
|
|
|
} else {
|
|
|
this.$emit('activeItemChange', this.activeValue);
|
|
|
}
|
|
|
+ },
|
|
|
+ scrollMenu(menu) {
|
|
|
+ scrollIntoView(menu, menu.getElementsByClassName('is-active')[0]);
|
|
|
+ },
|
|
|
+ handleMenuEnter() {
|
|
|
+ this.$nextTick(() => this.getMenus().forEach(menu => this.scrollMenu(menu)));
|
|
|
+ },
|
|
|
+ getMenus() {
|
|
|
+ if (this.$refs.wrapper) {
|
|
|
+ return Array.prototype.slice.call(this.$refs.wrapper.getElementsByClassName('el-cascader-menu'));
|
|
|
+ } else {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
|
|
@@ -121,9 +135,19 @@
|
|
|
click: 'click',
|
|
|
hover: 'mouseenter'
|
|
|
}[expandTrigger];
|
|
|
- events.on[triggerEvent] = () => { this.activeItem(item, menuIndex); };
|
|
|
+ events.on[triggerEvent] = () => {
|
|
|
+ this.activeItem(item, menuIndex);
|
|
|
+ this.$nextTick(() => {
|
|
|
+ // adjust self and next level
|
|
|
+ this.scrollMenu(this.getMenus()[menuIndex]);
|
|
|
+ this.scrollMenu(this.getMenus()[menuIndex + 1]);
|
|
|
+ });
|
|
|
+ };
|
|
|
} else {
|
|
|
- events.on.click = () => { this.select(item, menuIndex); };
|
|
|
+ events.on.click = () => {
|
|
|
+ this.select(item, menuIndex);
|
|
|
+ this.$nextTick(() => this.scrollMenu(this.getMenus()[menuIndex]));
|
|
|
+ };
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -158,13 +182,14 @@
|
|
|
);
|
|
|
});
|
|
|
return (
|
|
|
- <transition name="el-zoom-in-top" on-after-leave={this.handleMenuLeave}>
|
|
|
+ <transition name="el-zoom-in-top" on-before-enter={this.handleMenuEnter} on-after-leave={this.handleMenuLeave}>
|
|
|
<div
|
|
|
v-show={visible}
|
|
|
class={[
|
|
|
'el-cascader-menus',
|
|
|
popperClass
|
|
|
]}
|
|
|
+ ref="wrapper"
|
|
|
>
|
|
|
{menus}
|
|
|
</div>
|