Skip to content

Commit

Permalink
feat(components): scroll to bottom on activate, fix #63
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Nov 23, 2023
1 parent 242c122 commit 2887039
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/components/client/virtual/list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<script lang="ts" setup>
import { ref, computed, watch, nextTick, onActivated, onMounted } from 'vue'
import { ref, computed, watch, nextTick, onActivated, onMounted, PropType } from 'vue'
import type { ElScrollbar } from 'element-plus'
import Virtual from './virtual'
import VirtualItem from './item'
Expand All @@ -35,6 +35,10 @@ const props = defineProps({
activeKey: { default: '' },
threshold: { default: 0 },
maxHeight: String,
activate: {
type: String as PropType<'top' | 'bottom' | 'current'>,
default: 'bottom',
},
})
const dataShown = computed<any[]>(() => props.data.slice(range.start, range.end))
Expand Down Expand Up @@ -124,7 +128,11 @@ function scrollToBottom() {
let scrollTop = 0
onActivated(() => {
root.value.setScrollTop(scrollTop)
if (props.activate === 'bottom') {
scrollToBottom()
} else if (props.activate === 'current') {
root.value.setScrollTop(scrollTop)
}
})
function onScroll(ev: MouseEvent) {
Expand Down

0 comments on commit 2887039

Please sign in to comment.