fix: Fix thumbnail carousel scroll position (#1606)

* fix: Fix thumbnail carousel scroll position

* Small formatting fix
This commit is contained in:
Dermot Duffy
2024-10-02 20:28:13 -07:00
committed by GitHub
parent 1f5d4bd8b0
commit 21b468734c
7 changed files with 26 additions and 20 deletions
+1 -4
View File
@@ -128,10 +128,7 @@ export class CarouselController {
// This controller manages slide changes (including shadow DOM
// assignments, which the stock watcher does not handle).
watchSlides: false,
// We use the auto-size plugin to manage resizes without carousel resets
// mid-scroll.
watchResize: false,
watchResize: true,
watchDrag: this._draggable,
},
[
+11 -6
View File
@@ -38,9 +38,13 @@ function AutoSize(): AutoSizeType {
intersectionHandler,
);
const debouncedSetContainerHeight = debounce(() => setContainerHeight(), 200, {
trailing: true,
});
const debouncedSetContainerHeight = debounce(
() => setContainerHeightAndReInit(),
200,
{
trailing: true,
},
);
function init(emblaApiInstance: EmblaCarouselType): void {
emblaApi = emblaApiInstance;
@@ -87,8 +91,9 @@ function AutoSize(): AutoSizeType {
if (isContainerIntersectingNow !== previousContainerIntersecting) {
// Don't reinitialize on first call (intersectionHandler is always called
// on initial observation).
const callReInit = previousContainerIntersecting !== null;
// on initial observation), nor when the viewport is not intersecting.
const callReInit =
isContainerIntersectingNow && previousContainerIntersecting !== null;
previousContainerIntersecting = isContainerIntersectingNow;
if (callReInit) {
reInitController?.reinit();
@@ -122,7 +127,7 @@ function AutoSize(): AutoSizeType {
}
}
function setContainerHeight(): void {
function setContainerHeightAndReInit(): void {
const {
slideRegistry,
options: { axis },