Browse Source

feat(api): scroll to list item when necessary

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4222/head
Pranav C 2 years ago
parent
commit
c610caa667
  1. 2
      packages/nc-gui/components/smartsheet/expanded-form/Comments.vue
  2. 18
      packages/nc-gui/components/virtual-cell/components/ListItems.vue

2
packages/nc-gui/components/smartsheet/expanded-form/Comments.vue

@ -16,7 +16,7 @@ watch(
// todo: replace setTimeout // todo: replace setTimeout
setTimeout(() => { setTimeout(() => {
if (commentsWrapperEl.value) commentsWrapperEl.value.scrollTop = commentsWrapperEl.value?.scrollHeight if (commentsWrapperEl.value) commentsWrapperEl.value.scrollTop = commentsWrapperEl.value?.scrollHeight
}, 200) }, 200
}, },
{ immediate: true }, { immediate: true },
) )

18
packages/nc-gui/components/virtual-cell/components/ListItems.vue

@ -1,5 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onUnmounted } from '@vue/runtime-core' import { onUnmounted } from '@vue/runtime-core'
import { Card } from 'ant-design-vue'
import { RelationTypes, UITypes } from 'nocodb-sdk' import { RelationTypes, UITypes } from 'nocodb-sdk'
import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk' import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk'
import { import {
@ -104,7 +105,9 @@ watch(expandedFormDlg, (nexVal) => {
if (!nexVal && !isNew.value) vModel.value = false if (!nexVal && !isNew.value) vModel.value = false
}) })
const removeListeners = useSelectedCellKeyupListener(vModel, (e: KeyboardEvent) => { const { cleanup } = useSelectedCellKeyupListener(
vModel,
(e: KeyboardEvent) => {
switch (e.key) { switch (e.key) {
case 'ArrowUp': case 'ArrowUp':
selectedRowIndex.value = Math.max(0, selectedRowIndex.value - 1) selectedRowIndex.value = Math.max(0, selectedRowIndex.value - 1)
@ -122,11 +125,17 @@ const removeListeners = useSelectedCellKeyupListener(vModel, (e: KeyboardEvent)
} }
break break
} }
}, true) },
true,
)
onUnmounted(() => { onUnmounted(() => {
removeListeners() cleanup.value?.()
}) })
const activeRow = (el: InstanceType<typeof Card>) => {
el?.$el?.scrollIntoView({ block: 'nearest', inline: 'nearest' })
}
</script> </script>
<template> <template>
@ -162,9 +171,10 @@ onUnmounted(() => {
<a-card <a-card
v-for="(refRow, i) in childrenExcludedList?.list ?? []" v-for="(refRow, i) in childrenExcludedList?.list ?? []"
:key="i" :key="i"
:ref="selectedRowIndex === i ? activeRow : null"
class="!my-4 cursor-pointer hover:(!bg-gray-200/50 shadow-md) group" class="!my-4 cursor-pointer hover:(!bg-gray-200/50 shadow-md) group"
:class="{ 'nc-selected-row': selectedRowIndex === i }"
@click="linkRow(refRow)" @click="linkRow(refRow)"
:class="{'nc-selected-row':selectedRowIndex === i}"
> >
{{ refRow[relatedTablePrimaryValueProp] }} {{ refRow[relatedTablePrimaryValueProp] }}
<span class="hidden group-hover:(inline) text-gray-400 text-[11px] ml-1"> <span class="hidden group-hover:(inline) text-gray-400 text-[11px] ml-1">

Loading…
Cancel
Save