From 30234a2bdbdeb98711efb9bebf8fa66d1631e9cc Mon Sep 17 00:00:00 2001 From: Laura Martinez Garcia Date: Wed, 15 May 2024 15:36:49 +0200 Subject: [PATCH] fix: refactor reset method --- .../src/composables/use-scroll.ts | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/x-components/src/composables/use-scroll.ts b/packages/x-components/src/composables/use-scroll.ts index f191cfacdc..59ff1031ba 100644 --- a/packages/x-components/src/composables/use-scroll.ts +++ b/packages/x-components/src/composables/use-scroll.ts @@ -1,4 +1,5 @@ import { computed, nextTick, onMounted, Ref, ref, watch } from 'vue'; +import { isArray } from '@empathyco/x-utils'; import { XEvent } from '../wiring/events.types'; import { ScrollDirection } from '../components/scroll/scroll.types'; import { throttle } from '../utils/throttle'; @@ -294,13 +295,25 @@ export function useScroll( * @internal */ const $x = use$x(); - $x.on(props.resetOn as XEvent, true).subscribe(() => { - nextTick().then(() => { - if (props.resetOnChange) { - scrollEl.value?.scrollTo({ top: 0 }); - } + if (isArray(props.resetOn)) { + props.resetOn.forEach(event => + $x.on(event, true).subscribe(() => { + nextTick().then(() => { + if (props.resetOnChange) { + scrollEl.value?.scrollTo({ top: 0 }); + } + }); + }) + ); + } else { + $x.on(props.resetOn, true).subscribe(() => { + nextTick().then(() => { + if (props.resetOnChange) { + scrollEl.value?.scrollTo({ top: 0 }); + } + }); }); - }); + } return { throttledStoreScrollData }; }