Skip to content

Commit

Permalink
chore: minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
alenaksu authored Oct 24, 2024
1 parent cd8495d commit 555a5d3
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/components/carousel/carousel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class SlCarousel extends ShoelaceElement {
private autoplayController = new AutoplayController(this, () => this.next());
private readonly localize = new LocalizeController(this);
private mutationObserver: MutationObserver;
private pendingInteractionScroll = false;
private pendingSlideChange = false;

connectedCallback(): void {
super.connectedCallback();
Expand Down Expand Up @@ -262,7 +262,7 @@ export default class SlCarousel extends ShoelaceElement {
@eventOptions({ passive: true })
private handleScroll() {
this.scrolling = true;
if (!this.pendingInteractionScroll) {
if (!this.pendingSlideChange) {
this.synchronizeSlides();
}
}
Expand Down Expand Up @@ -320,7 +320,7 @@ export default class SlCarousel extends ShoelaceElement {
private handleScrollEnd() {
if (!this.scrolling || this.dragging) return;
this.scrolling = false;
this.pendingInteractionScroll = false;
this.pendingSlideChange = false;
this.synchronizeSlides();
}

Expand Down Expand Up @@ -496,12 +496,14 @@ export default class SlCarousel extends ShoelaceElement {
const nextLeft = nextSlideRect.left - scrollContainerRect.left;
const nextTop = nextSlideRect.top - scrollContainerRect.top;

this.pendingInteractionScroll = true;
scrollContainer.scrollTo({
left: nextLeft + scrollContainer.scrollLeft,
top: nextTop + scrollContainer.scrollTop,
behavior
});
if (nextLeft || nextTop) {
this.pendingSlideChange = true;
scrollContainer.scrollTo({
left: nextLeft + scrollContainer.scrollLeft,
top: nextTop + scrollContainer.scrollTop,
behavior
});
}
}

render() {
Expand Down

0 comments on commit 555a5d3

Please sign in to comment.