Skip to content

Commit e05ae82

Browse files
committed
FaScrollArea 组件新增 onScroll 事件
1 parent a2fc0d3 commit e05ae82

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/ui/components/FaScrollArea/index.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ const props = withDefaults(
2525
},
2626
)
2727
28+
const emits = defineEmits<{
29+
onScroll: [Event]
30+
}>()
31+
2832
const scrollAreaRef = useTemplateRef('scrollAreaRef')
2933
3034
const arrivedState = ref<{
@@ -46,6 +50,10 @@ const showMaskEnd = computed(() => {
4650
return !arrivedState.value?.bottom
4751
})
4852
53+
function onScroll(event: Event) {
54+
emits('onScroll', event)
55+
}
56+
4957
function onWheel(event: WheelEvent) {
5058
if (props.horizontal) {
5159
scrollAreaRef.value?.el?.viewportElement?.scrollBy({
@@ -108,7 +116,7 @@ defineExpose({
108116
'--mask-scroll-container-gradient-color': props.gradientColor,
109117
} : {}"
110118
>
111-
<ScrollArea ref="scrollAreaRef" :class="cn('relative z-0 flex-1', props.contentClass)" :scrollbar="props.scrollbar" :on-wheel="onWheel">
119+
<ScrollArea ref="scrollAreaRef" :class="cn('relative z-0 flex-1', props.contentClass)" :scrollbar="props.scrollbar" :on-scroll="onScroll" :on-wheel="onWheel">
112120
<slot />
113121
<ScrollBar v-if="props.horizontal" orientation="horizontal" :class="{ 'opacity-0 pointer-events-none': !props.scrollbar }" />
114122
</ScrollArea>

src/ui/components/FaScrollArea/scroll-area/ScrollArea.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import ScrollBar from './ScrollBar.vue'
1313
const props = defineProps<ScrollAreaRootProps & {
1414
class?: HTMLAttributes['class']
1515
scrollbar?: boolean
16+
onScroll?: (event: Event) => void
1617
onWheel?: (event: WheelEvent) => void
1718
}>()
1819
@@ -31,7 +32,7 @@ defineExpose({
3132

3233
<template>
3334
<ScrollAreaRoot v-bind="delegatedProps" :class="cn('relative overflow-hidden', props.class)">
34-
<ScrollAreaViewport ref="viewportRef" class="scroll-area-viewport h-full w-full rounded-[inherit]" @wheel.prevent="onWheel">
35+
<ScrollAreaViewport ref="viewportRef" class="scroll-area-viewport h-full w-full rounded-[inherit]" @scroll="onScroll" @wheel="onWheel">
3536
<slot />
3637
</ScrollAreaViewport>
3738
<ScrollBar :class="{ 'opacity-0 pointer-events-none': !props.scrollbar }" />

0 commit comments

Comments
 (0)