Skip to content

Commit

Permalink
Merge pull request #2538 from exadel-inc/fix/count-reserve-slides
Browse files Browse the repository at this point in the history
fix(esl-carousel): fix count of slides to be rendered before the first slide
  • Loading branch information
ala-n committed Jul 25, 2024
2 parents 4bc8b55 + cd68ea3 commit daea2a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ export class ESLDefaultCarouselRenderer extends ESLCarouselRenderer {
/**
* @returns count of slides to be rendered (reserved) before the first slide
*/
protected calcReserveCount(back?: boolean): number {
protected getReserveCount(back?: boolean): number {
const {size, count, loop, currentIndex} = this;
const freeSlides = size - count;
// no need to reorder if there are no free slides or loop is disabled
if (!loop || !freeSlides) return 0;
// if back option is not set, prefer to reserve slides with respect to semantic order
if (typeof back !== 'boolean') back = !!currentIndex;
// otherwise, ensure that there are at least half of free slides reserved (if the back option is set - round up, otherwise - round down)
return Math.min(count, back ? Math.ceil(freeSlides / 2) : Math.floor(freeSlides / 2));
return back ? Math.ceil(freeSlides / 2) : Math.floor(freeSlides / 2);
}

/**
Expand All @@ -192,7 +192,7 @@ export class ESLDefaultCarouselRenderer extends ESLCarouselRenderer {
*/
protected reorder(back?: boolean): void {
const {size, loop, currentIndex, $slides} = this;
const reserve = this.calcReserveCount(back);
const reserve = this.getReserveCount(back);

const index = loop ? currentIndex : 0;
for (let i = 0; i < size; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ export class ESLGridCarouselRenderer extends ESLDefaultCarouselRenderer {
/**
* @returns count of slides to be rendered (reserved) before the first slide does not include fake slides
*/
protected override calcReserveCount(back?: boolean): number {
const reserve = super.calcReserveCount(back);
protected override getReserveCount(back?: boolean): number {
const reserve = super.getReserveCount(back);
return reserve - (reserve % this.ROWS);
}

Expand Down

0 comments on commit daea2a9

Please sign in to comment.