From 79bf66d961184ca247a52f7c8f1b8884c87cfddd Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Sat, 9 Apr 2022 07:57:30 -0700 Subject: [PATCH] Always rescroll after the carousel is re-initalized. --- package.json | 2 +- src/components/thumbnail-carousel.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 7079863d..91ddb3fd 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "crypto": "^1.0.1", "custom-card-helpers": "^1.9.0", "date-fns": "^2.28.0", - "embla-carousel": "^6.1.1", + "embla-carousel": "^6.2.0", "embla-carousel-wheel-gestures": "^2.1.1", "home-assistant-js-websocket": "^6.1.1", "keycharm": "^0.4.0", diff --git a/src/components/thumbnail-carousel.ts b/src/components/thumbnail-carousel.ts index 28fedd9f..a0b0b449 100644 --- a/src/components/thumbnail-carousel.ts +++ b/src/components/thumbnail-carousel.ts @@ -75,6 +75,11 @@ export class FrigateCardThumbnailCarousel extends FrigateCardCarousel { protected _resizeHandler(): void { if (this._carousel) { this._carousel.reInit(); + // Reinit will cause the scroll position to reset, so re-scroll to the + // correct location. + if (this._selected !== undefined && this._selected !== null) { + this.carouselScrollTo(this._selected); + } } } @@ -102,7 +107,7 @@ export class FrigateCardThumbnailCarousel extends FrigateCardCarousel { return { containScroll: 'keepSnaps', dragFree: true, - startIndex: this._selected ?? 0, + startIndex: this._selected ?? undefined, }; } @@ -139,7 +144,6 @@ export class FrigateCardThumbnailCarousel extends FrigateCardCarousel { this.updateComplete.then(() => { if (this._carousel) { if (this._selected !== undefined && this._selected !== null) { - console.info('thumbnail carousel scroll to') this.carouselScrollTo(this._selected); } }