Commit e1cda09c authored by wacky6.AriesMBP's avatar wacky6.AriesMBP Committed by 杨奕

Cascader: auto scroll to selected option

parent 8b5d2086
<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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment