Skip to content

Commit

Permalink
fix(carousel): update index when items are removed
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRichel committed Jul 21, 2022
1 parent b6a616a commit 21c2f62
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/BIMDataComponents/BIMDataCarousel/BIMDataCarousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ export default {
},
mounted() {
this.distributeItems();
// Redistribute items on slider resize
this.resizeObserver = new ResizeObserver(() => this.distributeItems());
this.resizeObserver.observe(this.$refs.slider);
// Redistribute items when items are added/removed
this.mutationObserver = new MutationObserver(() => this.distributeItems());
this.mutationObserver.observe(this.$refs.slider, { childList: true });
},
Expand Down Expand Up @@ -129,7 +131,9 @@ export default {
});
}
this.maxIndex = children.length - nbDisplayed;
this.maxIndex =
children.length > nbDisplayed ? children.length - nbDisplayed : 0;
this.index = Math.min(this.index, this.maxIndex);
this.translations = offsets;
}
},
Expand Down

0 comments on commit 21c2f62

Please sign in to comment.