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

TimeSelect: auto scroll to selected option

parent e1cda09c
<template> <template>
<transition name="el-zoom-in-top" @after-leave="$emit('dodestroy')"> <transition name="el-zoom-in-top" @before-enter="handleMenuEnter" @after-leave="$emit('dodestroy')">
<div <div
ref="popper"
v-show="visible" v-show="visible"
:style="{ width: width + 'px' }" :style="{ width: width + 'px' }"
:class="popperClass" :class="popperClass"
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
<script type="text/babel"> <script type="text/babel">
import ElScrollbar from 'element-ui/packages/scrollbar'; import ElScrollbar from 'element-ui/packages/scrollbar';
import scrollIntoView from 'element-ui/src/utils/scroll-into-view';
const parseTime = function(time) { const parseTime = function(time) {
const values = ('' || time).split(':'); const values = ('' || time).split(':');
...@@ -81,6 +83,7 @@ ...@@ -81,6 +83,7 @@
} else if (this.maxTime && compareTime(val, this.maxTime) > 0) { } else if (this.maxTime && compareTime(val, this.maxTime) > 0) {
this.$emit('pick'); this.$emit('pick');
} }
this.$nextTick(() => this.scrollToOption());
} }
}, },
...@@ -93,6 +96,15 @@ ...@@ -93,6 +96,15 @@
handleClear() { handleClear() {
this.$emit('pick'); this.$emit('pick');
},
scrollToOption(className = 'selected') {
const menu = this.$refs.popper.querySelector('.el-picker-panel__content');
scrollIntoView(menu, menu.getElementsByClassName(className)[0]);
},
handleMenuEnter() {
this.$nextTick(() => this.scrollToOption());
} }
}, },
......
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