Skip to content

Commit

Permalink
fix(esl-carousel): fix incorrect alignment of the grid carousel rende…
Browse files Browse the repository at this point in the history
…rer if there are no enough slides
  • Loading branch information
abarmina committed Jun 26, 2024
1 parent 41cd0b8 commit 6956729
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
transition: transform 0.25s linear;
}

&.esl-carousel-horizontal [esl-carousel-slide] {
&.esl-carousel-horizontal :is([esl-carousel-slide], [esl-carousel-fake-slide]) {
width: var(--esl-slide-size);
}
&.esl-carousel-vertical [esl-carousel-slide] {
&.esl-carousel-vertical :is([esl-carousel-slide], [esl-carousel-fake-slide]) {
height: var(--esl-slide-size);
}
}
19 changes: 15 additions & 4 deletions src/modules/esl-carousel/renderers/esl-carousel.grid.renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,23 @@ export class ESLGridCarouselRenderer extends ESLDefaultCarouselRenderer {
@prop(2, {readonly: true})
public readonly ROWS: number;

/** @returns fake slides collection to fill the last "row" in grid mode */
/** @returns count of fake slides to fill the last "row" or incomplete carousel state */
public get fakeSlidesCount(): number {
if (this.$carousel.$slides.length < this.count) {
return this.count - this.$carousel.$slides.length;
}
return this.$carousel.$slides.length % this.ROWS;
}

/**
* @returns fake slides collection
* @see ESLGridCarouselRenderer.fakeSlidesCount
*/
@memoize()
public get $fakeSlides(): HTMLElement[] {
const count = this.$carousel.$slides.length % this.ROWS;
if (count === 0) return [];
return Array.from({length: this.ROWS - count}, this.buildFakeSlide.bind(this));
const length = this.fakeSlidesCount;
if (length === 0) return [];
return Array.from({length}, this.buildFakeSlide.bind(this));
}

/** @returns all slides including {@link ESLGridCarouselRenderer.$fakeSlides} slides created in grid mode */
Expand Down

0 comments on commit 6956729

Please sign in to comment.