Skip to content

Commit

Permalink
fix(carousel): enable previus click to back to index 0 (#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus-rosa-jsm authored Feb 11, 2025
1 parent f6e9d98 commit 7ce50cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/core/src/components/carousel/carousel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,17 @@ describe('AtomCarousel', () => {
'.navigation--next'
) as HTMLElement

nextButton?.click()
const prevButton = page.root?.shadowRoot?.querySelector(
'.navigation--prev'
) as HTMLElement

nextButton?.click()
await page.waitForChanges()

expect(page?.rootInstance.currentIdx).toBe(1)

prevButton?.click()
await page.waitForChanges()
expect(page?.rootInstance.currentIdx).toBe(0)
})

it('should working with loop', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/carousel/carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class AtomCarousel {
}

set currentIndex(value: number) {
if (!this.carouselWrapper || !value) return
if (!this.carouselWrapper) return

this.currentIdx = value
this.carouselWrapper.style.transform = `translateX(-${this.currentIndex * 100}%)`
Expand Down

0 comments on commit 7ce50cd

Please sign in to comment.