feat: add component to enable scroll-into view (#451)
This commit is contained in:
parent
c1d1138742
commit
a18e5e2332
3 changed files with 26 additions and 15 deletions
17
components/common/CommonScrollIntoView.vue
Normal file
17
components/common/CommonScrollIntoView.vue
Normal file
|
@ -0,0 +1,17 @@
|
|||
<script setup lang="ts">
|
||||
const { as = 'div', active } = defineProps<{ as: any; active: boolean }>()
|
||||
const el = ref()
|
||||
|
||||
watch(() => active, (active) => {
|
||||
const _el = unrefElement(el)
|
||||
|
||||
if (active && _el)
|
||||
_el.scrollIntoView({ block: 'nearest', inline: 'start' })
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<component :is="as" ref="el">
|
||||
<slot />
|
||||
</component>
|
||||
</template>
|
Loading…
Add table
Add a link
Reference in a new issue