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
|
@ -1,14 +1,6 @@
|
|||
<script setup lang="ts">
|
||||
import type { SearchResult } from './types'
|
||||
const props = defineProps<{ result: SearchResult; active: boolean }>()
|
||||
|
||||
const el = ref<HTMLElement>()
|
||||
watch(() => props.active, (active) => {
|
||||
const _el = unrefElement(el)
|
||||
|
||||
if (active && _el)
|
||||
_el.scrollIntoView({ block: 'nearest', inline: 'start' })
|
||||
})
|
||||
defineProps<{ result: SearchResult; active: boolean }>()
|
||||
|
||||
const onActivate = () => {
|
||||
(document.activeElement as HTMLElement).blur()
|
||||
|
@ -16,11 +8,11 @@ const onActivate = () => {
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<RouterLink ref="el" :to="result.to" py2 block px2 :aria-selected="active" :class="{ 'bg-active': active }" hover:bg-active @click="() => onActivate()">
|
||||
<CommonScrollIntoView as="RouterLink" :active="active" :to="result.to" py2 block px2 :aria-selected="active" :class="{ 'bg-active': active }" hover:bg-active @click="() => onActivate()">
|
||||
<SearchHashtagInfo v-if="result.type === 'hashtag'" :hashtag="result.hashtag" />
|
||||
<AccountInfo v-else-if="result.type === 'account'" :account="result.account" />
|
||||
<div v-else-if="result.type === 'action'" text-center>
|
||||
{{ result.action!.label }}
|
||||
</div>
|
||||
</RouterLink>
|
||||
</CommonScrollIntoView>
|
||||
</template>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue