feat(carousel): enhance item retrieval logic for improved circular navigation

This commit is contained in:
2026-07-23 12:15:44 -03:00
parent 8963bd5460
commit ea0bd4a956
2 changed files with 4 additions and 2 deletions

View File

@@ -143,7 +143,9 @@ describe('CarouselComponent', () => {
const pages = fixture.nativeElement.querySelectorAll('.carousel__page');
expect(pages).toHaveLength(3);
expect(pages[0].querySelectorAll('.carousel__item')).toHaveLength(2);
expect(pages[0].textContent).toContain('Tercero');
expect(pages[0].textContent).toContain('Primero');
expect(pages[1].textContent).toContain('Primero');
expect(pages[2].textContent).toContain('Tercero');

View File

@@ -260,10 +260,10 @@ export class CarouselComponent<T> implements AfterViewInit {
const pageCount = this.pageCount();
const normalizedPage = this.normalizePage(page, pageCount);
const start = normalizedPage * this.itemsPerPage();
const end = Math.min(start + this.itemsPerPage(), this.items().length);
const items: CarouselPageItem<T>[] = [];
for (let index = start; index < end; index += 1) {
for (let offset = 0; offset < this.itemsPerPage(); offset += 1) {
const index = (start + offset) % this.items().length;
items.push({ item: this.items()[index], index });
}