Skip to content

Commit

Permalink
fix: refactor reset method
Browse files Browse the repository at this point in the history
  • Loading branch information
lauramargar committed May 15, 2024
1 parent 5ccab1c commit 30234a2
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions packages/x-components/src/composables/use-scroll.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 };
}

0 comments on commit 30234a2

Please sign in to comment.