@appica/ui-react 1.2.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/CHANGELOG.md +61 -15
  2. package/agent-rules.md +2 -0
  3. package/appica.css +1 -1
  4. package/dist/components/alert-dialog/alert-dialog.js +1 -1
  5. package/dist/components/alert-dialog/alert-dialog.js.map +1 -1
  6. package/dist/components/autocomplete/autocomplete.d.ts.map +1 -1
  7. package/dist/components/autocomplete/autocomplete.js +3 -7
  8. package/dist/components/autocomplete/autocomplete.js.map +1 -1
  9. package/dist/components/badge/badge.js +1 -1
  10. package/dist/components/badge/badge.js.map +1 -1
  11. package/dist/components/breadcrumb/breadcrumb.js +2 -2
  12. package/dist/components/breadcrumb/breadcrumb.js.map +1 -1
  13. package/dist/components/button/button-variants.js +1 -1
  14. package/dist/components/button/button-variants.js.map +1 -1
  15. package/dist/components/calendar/calendar.js +1 -1
  16. package/dist/components/calendar/calendar.js.map +1 -1
  17. package/dist/components/carousel/carousel.d.ts +2 -10
  18. package/dist/components/carousel/carousel.d.ts.map +1 -1
  19. package/dist/components/carousel/carousel.js +153 -33
  20. package/dist/components/carousel/carousel.js.map +1 -1
  21. package/dist/components/color-area/color-area.d.ts.map +1 -1
  22. package/dist/components/color-area/color-area.js +1 -0
  23. package/dist/components/color-area/color-area.js.map +1 -1
  24. package/dist/components/color-slider/color-slider.d.ts.map +1 -1
  25. package/dist/components/color-slider/color-slider.js +1 -0
  26. package/dist/components/color-slider/color-slider.js.map +1 -1
  27. package/dist/components/color-swatch-picker/color-swatch-picker.js +1 -1
  28. package/dist/components/color-swatch-picker/color-swatch-picker.js.map +1 -1
  29. package/dist/components/combobox/combobox.d.ts +5 -4
  30. package/dist/components/combobox/combobox.d.ts.map +1 -1
  31. package/dist/components/combobox/combobox.js +5 -8
  32. package/dist/components/combobox/combobox.js.map +1 -1
  33. package/dist/components/compare-slider/compare-slider.d.ts +50 -0
  34. package/dist/components/compare-slider/compare-slider.d.ts.map +1 -0
  35. package/dist/components/compare-slider/compare-slider.js +321 -0
  36. package/dist/components/compare-slider/compare-slider.js.map +1 -0
  37. package/dist/components/context-menu/context-menu.js +1 -1
  38. package/dist/components/context-menu/context-menu.js.map +1 -1
  39. package/dist/components/copy-button/copy-button.d.ts +2 -2
  40. package/dist/components/copy-button/copy-button.d.ts.map +1 -1
  41. package/dist/components/copy-button/copy-button.js +49 -46
  42. package/dist/components/copy-button/copy-button.js.map +1 -1
  43. package/dist/components/date-field/date-field.d.ts.map +1 -1
  44. package/dist/components/date-field/date-field.js +7 -0
  45. package/dist/components/date-field/date-field.js.map +1 -1
  46. package/dist/components/date-picker/date-picker.d.ts +10 -0
  47. package/dist/components/date-picker/date-picker.d.ts.map +1 -1
  48. package/dist/components/date-picker/date-picker.js +14 -0
  49. package/dist/components/date-picker/date-picker.js.map +1 -1
  50. package/dist/components/dialog/dialog.js +1 -1
  51. package/dist/components/dialog/dialog.js.map +1 -1
  52. package/dist/components/dropdown-menu/dropdown-menu.d.ts +13 -2
  53. package/dist/components/dropdown-menu/dropdown-menu.d.ts.map +1 -1
  54. package/dist/components/dropdown-menu/dropdown-menu.js +109 -4
  55. package/dist/components/dropdown-menu/dropdown-menu.js.map +1 -1
  56. package/dist/components/field/field.d.ts.map +1 -1
  57. package/dist/components/field/field.js +1 -0
  58. package/dist/components/field/field.js.map +1 -1
  59. package/dist/components/loader/loader.d.ts +1 -1
  60. package/dist/components/loader/loader.d.ts.map +1 -1
  61. package/dist/components/loader/loader.js +7 -5
  62. package/dist/components/loader/loader.js.map +1 -1
  63. package/dist/components/navigation/navigation-link-variants.js +1 -1
  64. package/dist/components/navigation/navigation-link-variants.js.map +1 -1
  65. package/dist/components/navigation-menu/navigation-menu.js +1 -1
  66. package/dist/components/navigation-menu/navigation-menu.js.map +1 -1
  67. package/dist/components/number-field/number-field.d.ts +1 -1
  68. package/dist/components/number-field/number-field.d.ts.map +1 -1
  69. package/dist/components/number-field/number-field.js +7 -0
  70. package/dist/components/number-field/number-field.js.map +1 -1
  71. package/dist/components/pagination/pagination.d.ts.map +1 -1
  72. package/dist/components/pagination/pagination.js +1 -2
  73. package/dist/components/pagination/pagination.js.map +1 -1
  74. package/dist/components/popover/popover.js +1 -1
  75. package/dist/components/popover/popover.js.map +1 -1
  76. package/dist/components/preview-card/preview-card.js +1 -1
  77. package/dist/components/preview-card/preview-card.js.map +1 -1
  78. package/dist/components/select/select.js +2 -2
  79. package/dist/components/select/select.js.map +1 -1
  80. package/dist/components/slider/slider.d.ts.map +1 -1
  81. package/dist/components/slider/slider.js +2 -1
  82. package/dist/components/slider/slider.js.map +1 -1
  83. package/dist/components/sparkline/sparkline.d.ts.map +1 -1
  84. package/dist/components/sparkline/sparkline.js +1 -0
  85. package/dist/components/sparkline/sparkline.js.map +1 -1
  86. package/dist/components/spinner/spinner.d.ts +1 -1
  87. package/dist/components/spinner/spinner.d.ts.map +1 -1
  88. package/dist/components/spinner/spinner.js +7 -5
  89. package/dist/components/spinner/spinner.js.map +1 -1
  90. package/dist/components/tabs/tabs.js +1 -1
  91. package/dist/components/tabs/tabs.js.map +1 -1
  92. package/dist/components/thumbnail/thumbnail.d.ts +6 -1
  93. package/dist/components/thumbnail/thumbnail.d.ts.map +1 -1
  94. package/dist/components/thumbnail/thumbnail.js +2 -0
  95. package/dist/components/thumbnail/thumbnail.js.map +1 -1
  96. package/dist/components/time-field/time-field.d.ts.map +1 -1
  97. package/dist/components/time-field/time-field.js +7 -0
  98. package/dist/components/time-field/time-field.js.map +1 -1
  99. package/dist/components/tooltip/tooltip.js +1 -1
  100. package/dist/components/tooltip/tooltip.js.map +1 -1
  101. package/dist/hooks/use-media-query.d.ts +0 -4
  102. package/dist/hooks/use-media-query.d.ts.map +1 -1
  103. package/dist/hooks/use-media-query.js.map +1 -1
  104. package/dist/index.d.ts +1 -0
  105. package/dist/index.d.ts.map +1 -1
  106. package/dist/index.js +3 -2
  107. package/dist/index.js.map +1 -1
  108. package/dist/internal/utils.d.ts.map +1 -1
  109. package/dist/internal/utils.js +2 -1
  110. package/dist/internal/utils.js.map +1 -1
  111. package/package.json +28 -23
  112. package/src/components/alert-dialog/alert-dialog.tsx +1 -1
  113. package/src/components/autocomplete/autocomplete.test.tsx +33 -0
  114. package/src/components/autocomplete/autocomplete.tsx +3 -7
  115. package/src/components/badge/badge.tsx +1 -1
  116. package/src/components/breadcrumb/breadcrumb.test.tsx +57 -2
  117. package/src/components/breadcrumb/breadcrumb.tsx +2 -2
  118. package/src/components/button/button-variants.ts +1 -1
  119. package/src/components/calendar/calendar.tsx +1 -1
  120. package/src/components/carousel/carousel.test.tsx +526 -12
  121. package/src/components/carousel/carousel.tsx +173 -42
  122. package/src/components/chip/chip.test.tsx +4 -5
  123. package/src/components/color-area/color-area.test.tsx +5 -0
  124. package/src/components/color-area/color-area.tsx +1 -0
  125. package/src/components/color-slider/color-slider.test.tsx +5 -0
  126. package/src/components/color-slider/color-slider.tsx +1 -0
  127. package/src/components/color-swatch-picker/color-swatch-picker.tsx +1 -1
  128. package/src/components/combobox/combobox.test.tsx +66 -0
  129. package/src/components/combobox/combobox.tsx +14 -11
  130. package/src/components/compare-slider/compare-slider.test.tsx +261 -0
  131. package/src/components/compare-slider/compare-slider.tsx +397 -0
  132. package/src/components/context-menu/context-menu.test.tsx +2 -1
  133. package/src/components/context-menu/context-menu.tsx +1 -1
  134. package/src/components/copy-button/copy-button.test.tsx +68 -3
  135. package/src/components/copy-button/copy-button.tsx +49 -43
  136. package/src/components/date-field/date-field.test.tsx +82 -0
  137. package/src/components/date-field/date-field.tsx +7 -0
  138. package/src/components/date-picker/date-picker.test.tsx +70 -0
  139. package/src/components/date-picker/date-picker.tsx +26 -0
  140. package/src/components/dialog/dialog.tsx +1 -1
  141. package/src/components/dropdown-menu/dropdown-menu.test.tsx +190 -1
  142. package/src/components/dropdown-menu/dropdown-menu.tsx +129 -3
  143. package/src/components/field/field.test.tsx +34 -0
  144. package/src/components/field/field.tsx +1 -0
  145. package/src/components/loader/loader.test.tsx +17 -4
  146. package/src/components/loader/loader.tsx +2 -2
  147. package/src/components/navigation/navigation-link-variants.ts +1 -1
  148. package/src/components/navigation-menu/navigation-menu.tsx +2 -2
  149. package/src/components/number-field/number-field.test.tsx +59 -0
  150. package/src/components/number-field/number-field.tsx +8 -0
  151. package/src/components/pagination/pagination.test.tsx +83 -0
  152. package/src/components/pagination/pagination.tsx +1 -2
  153. package/src/components/popover/popover.tsx +1 -1
  154. package/src/components/preview-card/preview-card.tsx +1 -1
  155. package/src/components/select/select.tsx +2 -2
  156. package/src/components/slider/slider.test.tsx +5 -0
  157. package/src/components/slider/slider.tsx +2 -1
  158. package/src/components/sparkline/sparkline.test.tsx +16 -0
  159. package/src/components/sparkline/sparkline.tsx +1 -0
  160. package/src/components/spinner/spinner.test.tsx +17 -4
  161. package/src/components/spinner/spinner.tsx +2 -2
  162. package/src/components/tabs/tabs.tsx +1 -1
  163. package/src/components/thumbnail/thumbnail.test.tsx +8 -0
  164. package/src/components/thumbnail/thumbnail.tsx +7 -0
  165. package/src/components/time-field/time-field.test.tsx +64 -0
  166. package/src/components/time-field/time-field.tsx +7 -0
  167. package/src/components/tooltip/tooltip.tsx +1 -1
  168. package/src/hooks/use-media-query.ts +0 -4
  169. package/src/index.ts +1 -0
  170. package/src/internal/utils.test.tsx +8 -1
  171. package/src/internal/utils.ts +4 -1
  172. package/styles.css +4 -0
@@ -1,4 +1,5 @@
1
- import { render, screen } from '@testing-library/react'
1
+ import * as React from 'react'
2
+ import { act, fireEvent, render, screen } from '@testing-library/react'
2
3
  import userEvent from '@testing-library/user-event'
3
4
  import { describe, expect, it, vi, beforeEach } from 'vitest'
4
5
  import { axe } from 'vitest-axe'
@@ -65,7 +66,7 @@ vi.mock('embla-carousel-react', () => ({
65
66
  // Plugin factories: each mock factory inlines its stub so vitest hoisting
66
67
  // doesn't trip on a shared helper reference.
67
68
  vi.mock('embla-carousel-accessibility', () => ({
68
- default: () => ({ name: 'accessibility', options: {}, init: () => {} }),
69
+ default: (options?: object) => ({ name: 'accessibility', options: options ?? {}, init: () => {} }),
69
70
  }))
70
71
  vi.mock('embla-carousel-autoplay', () => ({
71
72
  default: () => ({ name: 'autoplay', options: {}, init: () => {} }),
@@ -100,6 +101,7 @@ import {
100
101
  useCarousel,
101
102
  useLinkedCarousels,
102
103
  type CarouselApi,
104
+ type CarouselOptions,
103
105
  type CarouselProps,
104
106
  type CarouselThumbsProps,
105
107
  } from './carousel'
@@ -110,6 +112,51 @@ import useEmblaCarousel from 'embla-carousel-react'
110
112
  // eslint-disable-next-line import/first
111
113
  import { renderHook } from '@testing-library/react'
112
114
 
115
+ // eslint-disable-next-line import/first
116
+ import { Button } from '../button/button'
117
+
118
+ // eslint-disable-next-line import/first
119
+ import { ReducedMotionProvider } from '../../providers/reduced-motion-provider'
120
+
121
+ /** Calls every handler still subscribed to an Embla event on the stub api. */
122
+ function dispatch(event: string, payload?: unknown) {
123
+ const removed = new Set(stubApi.off.mock.calls.filter((c: unknown[]) => c[0] === event).map((c: unknown[]) => c[1]))
124
+ stubApi.on.mock.calls
125
+ .filter((c: unknown[]) => c[0] === event && !removed.has(c[1]))
126
+ .forEach((c: unknown[]) => (c[1] as (api: StubApi, payload?: unknown) => void)(stubApi, payload))
127
+ }
128
+
129
+ function emit(event: string, payload?: unknown) {
130
+ act(() => dispatch(event, payload))
131
+ }
132
+
133
+ function mockDomSlides() {
134
+ stubApi.slideNodes.mockImplementation(() =>
135
+ Array.from(document.querySelectorAll<HTMLElement>('[data-slot="carousel-slide"]')),
136
+ )
137
+ }
138
+
139
+ /** A stand-in for the Autoplay plugin that reports play and stop through the stub's events. */
140
+ function mockAutoplay() {
141
+ let playing = false
142
+ const autoplay = {
143
+ options: { delay: 4000 },
144
+ isPlaying: vi.fn(() => playing),
145
+ play: vi.fn(() => {
146
+ playing = true
147
+ dispatch('autoplay:play')
148
+ }),
149
+ stop: vi.fn(() => {
150
+ if (!playing) return
151
+ playing = false
152
+ dispatch('autoplay:stop')
153
+ }),
154
+ reset: vi.fn(),
155
+ }
156
+ stubApi.plugins.mockReturnValue({ autoplay })
157
+ return autoplay
158
+ }
159
+
113
160
  function Basic(props?: Partial<CarouselProps>) {
114
161
  return (
115
162
  <Carousel {...props}>
@@ -136,22 +183,63 @@ beforeEach(() => {
136
183
  stubApi.plugins.mockReturnValue({})
137
184
  stubApi.slideNodes.mockReturnValue([])
138
185
  stubApi.containerNode.mockReturnValue(undefined)
186
+ stubApi.rootNode.mockReturnValue(undefined)
187
+ stubApi.internalEngine.mockReturnValue({
188
+ options: { active: true, axis: 'x' },
189
+ scrollSnapList: { slidesBySnap: [[0], [1], [2], [3]] },
190
+ })
191
+ stubApi.on.mockClear()
192
+ stubApi.off.mockClear()
139
193
  })
140
194
 
141
195
  describe('Carousel', () => {
142
- it('renders the root region with carousel data-slot and orientation', () => {
196
+ it('renders an unlabeled root as a carousel group with no default name', () => {
143
197
  const { container } = render(<Basic />)
144
198
  const root = container.querySelector('[data-slot="carousel"]') as HTMLElement
145
199
  expect(root).not.toBeNull()
146
200
  expect(root.getAttribute('data-orientation')).toBe('horizontal')
147
- expect(root.getAttribute('role')).toBe('region')
201
+ expect(root.getAttribute('role')).toBe('group')
148
202
  expect(root.getAttribute('aria-roledescription')).toBe('carousel')
149
- expect(root.getAttribute('aria-label')).toBe('Carousel')
203
+ expect(root.hasAttribute('aria-label')).toBe(false)
204
+ })
205
+
206
+ it('becomes a region when labeled with aria-label', () => {
207
+ render(<Basic aria-label="Gallery" />)
208
+ expect(screen.getByRole('region', { name: 'Gallery' })).toHaveAttribute('data-slot', 'carousel')
209
+ })
210
+
211
+ it('becomes a region when labeled with aria-labelledby', () => {
212
+ render(
213
+ <>
214
+ <h2 id="gallery-heading">New arrivals</h2>
215
+ <Basic aria-labelledby="gallery-heading" />
216
+ </>,
217
+ )
218
+ expect(screen.getByRole('region', { name: 'New arrivals' })).toHaveAttribute('data-slot', 'carousel')
219
+ })
220
+
221
+ it('lets a consumer role and roledescription win', () => {
222
+ const { container } = render(<Basic role="presentation" aria-roledescription="gallery" />)
223
+ const root = container.querySelector('[data-slot="carousel"]') as HTMLElement
224
+ expect(root.getAttribute('role')).toBe('presentation')
225
+ expect(root.getAttribute('aria-roledescription')).toBe('gallery')
226
+ })
227
+
228
+ it('merges a consumer ref with its own', () => {
229
+ const ref = React.createRef<HTMLDivElement>()
230
+ const { container } = render(<Basic {...({ ref } as Partial<CarouselProps>)} />)
231
+ expect(ref.current).toBe(container.querySelector('[data-slot="carousel"]'))
150
232
  })
151
233
 
152
- it('uses a custom aria-label when provided', () => {
234
+ it('leaves the viewport without a role or name, so each carousel is one landmark at most', () => {
153
235
  const { container } = render(<Basic aria-label="Gallery" />)
154
- expect(container.querySelector('[data-slot="carousel"]')?.getAttribute('aria-label')).toBe('Gallery')
236
+ const viewport = container.querySelector('[data-slot="carousel-viewport"]') as HTMLElement
237
+ expect(viewport.hasAttribute('role')).toBe(false)
238
+ expect(viewport.hasAttribute('aria-label')).toBe(false)
239
+ const plugins = (useEmblaCarousel as unknown as ReturnType<typeof vi.fn>).mock.calls.at(-1)?.[1] as {
240
+ name: string
241
+ }[]
242
+ expect(plugins.map((plugin) => plugin.name)).not.toContain('accessibility')
155
243
  })
156
244
 
157
245
  it('renders viewport + content + slides with the expected data-slots and roles', () => {
@@ -184,6 +272,13 @@ describe('Carousel', () => {
184
272
  expect(container.querySelector('[data-slot="carousel-content"]')?.getAttribute('data-orientation')).toBe('vertical')
185
273
  })
186
274
 
275
+ it('claims touch drags along its own axis from a surrounding Drawer', () => {
276
+ const { container: row } = render(<Basic />)
277
+ expect(row.querySelector('[data-slot="carousel-viewport"]')).toHaveAttribute('data-base-ui-swipe-ignore', 'x')
278
+ const { container: column } = render(<Basic orientation="vertical" />)
279
+ expect(column.querySelector('[data-slot="carousel-viewport"]')).toHaveAttribute('data-base-ui-swipe-ignore', 'y')
280
+ })
281
+
187
282
  it('forwards className on the root and other elements', () => {
188
283
  const { container } = render(
189
284
  <Carousel className="root-cls">
@@ -201,6 +296,169 @@ describe('Carousel', () => {
201
296
  })
202
297
  })
203
298
 
299
+ describe('Carousel slides', () => {
300
+ function slides(container: HTMLElement) {
301
+ return Array.from(container.querySelectorAll<HTMLElement>('[data-slot="carousel-slide"]'))
302
+ }
303
+
304
+ it('makes slides outside the viewport inert, and keeps the visible ones reachable', () => {
305
+ mockDomSlides()
306
+ stubApi.slidesInView.mockReturnValue([0, 1])
307
+ const { container } = render(<Basic />)
308
+ const [first, second, third, fourth] = slides(container)
309
+ expect(first).not.toHaveAttribute('inert')
310
+ expect(second).not.toHaveAttribute('inert')
311
+ expect(third).toHaveAttribute('inert')
312
+ expect(fourth).toHaveAttribute('inert')
313
+ slides(container).forEach((slide) => expect(slide).not.toHaveAttribute('aria-hidden'))
314
+ })
315
+
316
+ it('labels each slide with its position', () => {
317
+ mockDomSlides()
318
+ const { container } = render(<Basic />)
319
+ expect(slides(container).map((slide) => slide.getAttribute('aria-label'))).toEqual([
320
+ '1 of 4',
321
+ '2 of 4',
322
+ '3 of 4',
323
+ '4 of 4',
324
+ ])
325
+ })
326
+
327
+ it('keeps a slide label or labelledby of its own', () => {
328
+ mockDomSlides()
329
+ const { container } = render(
330
+ <Carousel>
331
+ <CarouselContent>
332
+ <CarouselSlide aria-label="Intro">A</CarouselSlide>
333
+ <CarouselSlide aria-labelledby="slide-2-title">
334
+ <h3 id="slide-2-title">Spring sale</h3>
335
+ </CarouselSlide>
336
+ <CarouselSlide>C</CarouselSlide>
337
+ </CarouselContent>
338
+ </Carousel>,
339
+ )
340
+ const [first, second, third] = slides(container)
341
+ expect(first).toHaveAttribute('aria-label', 'Intro')
342
+ expect(second).not.toHaveAttribute('aria-label')
343
+ expect(third).toHaveAttribute('aria-label', '3 of 3')
344
+ })
345
+
346
+ it('updates as slides scroll into view', () => {
347
+ mockDomSlides()
348
+ stubApi.slidesInView.mockReturnValue([0])
349
+ const { container } = render(<Basic />)
350
+ expect(slides(container)[1]).toHaveAttribute('inert')
351
+ stubApi.slidesInView.mockReturnValue([1, 2])
352
+ emit('slidesinview')
353
+ const [first, second, third] = slides(container)
354
+ expect(first).toHaveAttribute('inert')
355
+ expect(second).not.toHaveAttribute('inert')
356
+ expect(third).not.toHaveAttribute('inert')
357
+ })
358
+
359
+ it('falls back to the selected snap until the engine reports slides in view', () => {
360
+ mockDomSlides()
361
+ stubApi.slidesInView.mockReturnValue([])
362
+ stubApi.selectedSnap.mockReturnValue(2)
363
+ const { container } = render(<Basic />)
364
+ expect(slides(container).map((slide) => slide.hasAttribute('inert'))).toEqual([true, true, false, true])
365
+ })
366
+
367
+ it('follows the selected snap under fade, where every slide shares one place', () => {
368
+ mockDomSlides()
369
+ stubApi.plugins.mockReturnValue({ fade: {} })
370
+ stubApi.slidesInView.mockReturnValue([0, 1, 2, 3])
371
+ stubApi.selectedSnap.mockReturnValue(1)
372
+ const { container } = render(<Basic fade />)
373
+ expect(slides(container).map((slide) => slide.hasAttribute('inert'))).toEqual([true, false, true, true])
374
+ })
375
+
376
+ it('leaves every slide reachable while the engine is inactive', () => {
377
+ mockDomSlides()
378
+ stubApi.internalEngine.mockReturnValue({
379
+ options: { active: false },
380
+ scrollSnapList: { slidesBySnap: [[0], [1], [2], [3]] },
381
+ })
382
+ const { container } = render(<Basic active={false} />)
383
+ slides(container).forEach((slide) => expect(slide).not.toHaveAttribute('inert'))
384
+ })
385
+
386
+ it('never makes the slide holding focus inert, and re-checks once focus leaves', () => {
387
+ mockDomSlides()
388
+ stubApi.rootNode.mockImplementation(() => document.querySelector('[data-slot="carousel-viewport"]'))
389
+ stubApi.slidesInView.mockReturnValue([0, 1])
390
+ render(
391
+ <>
392
+ <Carousel>
393
+ <CarouselContent>
394
+ <CarouselSlide>A</CarouselSlide>
395
+ <CarouselSlide>
396
+ <button type="button">Shop now</button>
397
+ </CarouselSlide>
398
+ <CarouselSlide>C</CarouselSlide>
399
+ </CarouselContent>
400
+ </Carousel>
401
+ <button type="button">Outside</button>
402
+ </>,
403
+ )
404
+ const cta = screen.getByRole('button', { name: 'Shop now' })
405
+ const slide = cta.closest('[data-slot="carousel-slide"]') as HTMLElement
406
+ act(() => cta.focus())
407
+
408
+ stubApi.slidesInView.mockReturnValue([2])
409
+ emit('select')
410
+ expect(slide).not.toHaveAttribute('inert')
411
+ expect(document.activeElement).toBe(cta)
412
+
413
+ act(() => screen.getByRole('button', { name: 'Outside' }).focus())
414
+ expect(slide).toHaveAttribute('inert')
415
+ })
416
+
417
+ it('removes what it set on unmount', () => {
418
+ mockDomSlides()
419
+ stubApi.slidesInView.mockReturnValue([0])
420
+ const { container, unmount } = render(<Basic />)
421
+ const nodes = slides(container)
422
+ unmount()
423
+ nodes.forEach((slide) => {
424
+ expect(slide).not.toHaveAttribute('inert')
425
+ expect(slide).not.toHaveAttribute('aria-label')
426
+ })
427
+ })
428
+
429
+ it('leaves slides alone with accessibility={false}', () => {
430
+ mockDomSlides()
431
+ const { container } = render(<Basic accessibility={false} />)
432
+ slides(container).forEach((slide) => {
433
+ expect(slide).not.toHaveAttribute('inert')
434
+ expect(slide).not.toHaveAttribute('aria-label')
435
+ })
436
+ })
437
+
438
+ it('hands slides to the Embla plugin for an options object, still without naming the viewport', () => {
439
+ mockDomSlides()
440
+ const { container } = render(<Basic accessibility={{ slideRole: 'listitem', carouselAriaRoleDescription: 'x' }} />)
441
+ slides(container).forEach((slide) => expect(slide).not.toHaveAttribute('inert'))
442
+ const plugins = (useEmblaCarousel as unknown as ReturnType<typeof vi.fn>).mock.calls.at(-1)?.[1] as {
443
+ name: string
444
+ options: object
445
+ }[]
446
+ expect(plugins.find((plugin) => plugin.name === 'accessibility')?.options).toEqual({
447
+ carouselRole: '',
448
+ carouselAriaLabel: '',
449
+ carouselAriaRoleDescription: 'x',
450
+ slideRole: 'listitem',
451
+ })
452
+ })
453
+
454
+ it('has no accessibility violations with off-screen slides inert', async () => {
455
+ mockDomSlides()
456
+ stubApi.slidesInView.mockReturnValue([0])
457
+ const { container } = render(<Basic aria-label="Featured" />)
458
+ expect(await axe(container)).toHaveNoViolations()
459
+ })
460
+ })
461
+
204
462
  describe('CarouselPrev / CarouselNext', () => {
205
463
  it('renders as buttons with the right data-slot and aria-label', () => {
206
464
  render(<Basic />)
@@ -264,14 +522,17 @@ describe('CarouselPrev / CarouselNext', () => {
264
522
  expect(link.getAttribute('href')).toBe('#prev')
265
523
  })
266
524
 
267
- it('disables prev when canGoToPrev() reports false', () => {
525
+ it('marks prev aria-disabled, not natively disabled, when canGoToPrev() reports false', () => {
268
526
  render(<Basic />)
269
527
  const prev = screen.getByRole('button', { name: 'Previous slide' })
270
- expect(prev).toBeDisabled()
528
+ expect(prev).toHaveAttribute('aria-disabled', 'true')
529
+ expect(prev).not.toHaveAttribute('disabled')
271
530
  expect(prev.getAttribute('data-disabled')).not.toBeNull()
272
531
  })
273
532
 
274
- it('honors a consumer-supplied disabled prop on next', () => {
533
+ it('honors a consumer-supplied disabled prop on next', async () => {
534
+ const user = userEvent.setup()
535
+ stubApi.goToNext.mockClear()
275
536
  render(
276
537
  <Carousel>
277
538
  <CarouselContent>
@@ -281,7 +542,34 @@ describe('CarouselPrev / CarouselNext', () => {
281
542
  </Carousel>,
282
543
  )
283
544
  const next = screen.getByRole('button', { name: 'Next slide' })
284
- expect(next).toBeDisabled()
545
+ expect(next).toHaveAttribute('aria-disabled', 'true')
546
+ await user.click(next)
547
+ expect(stubApi.goToNext).not.toHaveBeenCalled()
548
+ })
549
+
550
+ it('keeps focus on an arrow once it reaches the end', () => {
551
+ render(<Basic />)
552
+ const next = screen.getByRole('button', { name: 'Next slide' })
553
+ act(() => next.focus())
554
+ stubApi.canGoToNext.mockReturnValue(false)
555
+ emit('select')
556
+ expect(next).toHaveAttribute('aria-disabled', 'true')
557
+ expect(document.activeElement).toBe(next)
558
+ })
559
+
560
+ it('passes aria-disabled through a rendered Button without disabling it natively', () => {
561
+ render(
562
+ <Carousel>
563
+ <CarouselContent>
564
+ <CarouselSlide>1</CarouselSlide>
565
+ </CarouselContent>
566
+ <CarouselPrev render={<Button variant="outline" size="icon-md" />} />
567
+ </Carousel>,
568
+ )
569
+ const prev = screen.getByRole('button', { name: 'Previous slide' })
570
+ expect(prev).toHaveAttribute('aria-disabled', 'true')
571
+ expect(prev).toHaveAttribute('data-disabled')
572
+ expect(prev).not.toHaveAttribute('disabled')
285
573
  })
286
574
 
287
575
  it('calls api.goToNext when next is clicked', async () => {
@@ -343,6 +631,39 @@ describe('CarouselPagination', () => {
343
631
  expect(stubApi.goTo).toHaveBeenCalledWith(2)
344
632
  })
345
633
 
634
+ it('slides the autoplay indicator in rather than resizing it', () => {
635
+ mockAutoplay()
636
+ const { container } = render(<Basic autoplay />)
637
+ const indicator = container.querySelector('[data-slot="carousel-pagination-indicator"]') as HTMLElement
638
+ expect(indicator).not.toBeNull()
639
+ expect(indicator.style.width).toBe('')
640
+ expect(indicator.style.height).toBe('')
641
+ expect(indicator.style.transitionDuration).toBe('4000ms')
642
+ })
643
+
644
+ it('slides the vertical autoplay indicator in rather than resizing it', () => {
645
+ mockAutoplay()
646
+ const { container } = render(
647
+ <Carousel autoplay>
648
+ <CarouselContent>
649
+ <CarouselSlide>1</CarouselSlide>
650
+ <CarouselSlide>2</CarouselSlide>
651
+ <CarouselSlide>3</CarouselSlide>
652
+ </CarouselContent>
653
+ <CarouselPagination orientation="vertical" />
654
+ <CarouselProgress source="autoplay" orientation="vertical" />
655
+ </Carousel>,
656
+ )
657
+ const indicators = container.querySelectorAll<HTMLElement>(
658
+ '[data-slot="carousel-pagination-indicator"][data-orientation="vertical"]',
659
+ )
660
+ expect(indicators).toHaveLength(2)
661
+ indicators.forEach((indicator) => {
662
+ expect(indicator.style.width).toBe('')
663
+ expect(indicator.style.height).toBe('')
664
+ })
665
+ })
666
+
346
667
  it('renders nothing when there is only one snap', () => {
347
668
  stubApi.snapList.mockReturnValue([0])
348
669
  render(
@@ -449,6 +770,13 @@ describe('CarouselThumbs / CarouselThumb', () => {
449
770
  expect(track.getAttribute('data-orientation')).toBe('vertical')
450
771
  })
451
772
 
773
+ it('claims drags along the rail axis, independent of the carousel axis', () => {
774
+ const { container } = render(<WithThumbs orientation="vertical" />)
775
+ const [main, rail] = container.querySelectorAll('[data-slot="carousel-viewport"]')
776
+ expect(main).toHaveAttribute('data-base-ui-swipe-ignore', 'x')
777
+ expect(rail).toHaveAttribute('data-base-ui-swipe-ignore', 'y')
778
+ })
779
+
452
780
  it('applies the light variant to the thumbnails and the indicator', () => {
453
781
  const { container } = render(<WithThumbs light />)
454
782
  const thumb = container.querySelector('[data-slot="carousel-thumb"]') as HTMLElement
@@ -477,6 +805,34 @@ describe('CarouselThumbs / CarouselThumb', () => {
477
805
  expect(options.containScroll).toBe('keepSnaps')
478
806
  })
479
807
 
808
+ it('keeps thumbnails as plain buttons, outside any slide management', () => {
809
+ const mocked = vi.mocked(useEmblaCarousel)
810
+ const thumbsApi = {
811
+ ...stubApi,
812
+ slideNodes: vi.fn(() => Array.from(document.querySelectorAll<HTMLElement>('[data-slot="carousel-thumb"]'))),
813
+ }
814
+ mockDomSlides()
815
+ mocked.mockImplementation(((options?: CarouselOptions) => {
816
+ const api = options?.slides ? thumbsApi : stubApi
817
+ return [vi.fn(), api, api]
818
+ }) as unknown as typeof useEmblaCarousel)
819
+ try {
820
+ const { container } = render(<WithThumbs />)
821
+ const thumbs = Array.from(container.querySelectorAll<HTMLElement>('[data-slot="carousel-thumb"]'))
822
+ expect(thumbs).toHaveLength(3)
823
+ thumbs.forEach((thumb, index) => {
824
+ expect(screen.getByRole('button', { name: `Go to slide ${index + 1}` })).toBe(thumb)
825
+ expect(thumb).not.toHaveAttribute('aria-hidden')
826
+ expect(thumb).not.toHaveAttribute('aria-roledescription')
827
+ expect(thumb).not.toHaveAttribute('inert')
828
+ })
829
+ const railPlugins = mocked.mock.calls.findLast(([options]) => options?.slides)?.[1] ?? []
830
+ expect(railPlugins.map((plugin) => plugin.name)).not.toContain('accessibility')
831
+ } finally {
832
+ mocked.mockImplementation((() => [vi.fn(), stubApi, stubApi]) as unknown as typeof useEmblaCarousel)
833
+ }
834
+ })
835
+
480
836
  it('throws when a thumbnail is used outside CarouselThumbs', () => {
481
837
  const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
482
838
  expect(() => render(<CarouselThumb>Orphan</CarouselThumb>)).toThrow(/CarouselThumb/)
@@ -558,7 +914,10 @@ describe('useCarousel + lifecycle', () => {
558
914
  }
559
915
  stubApi.plugins.mockReturnValue({ wheelGestures: {}, autoplay })
560
916
  stubApi.rootNode.mockReturnValue(viewport)
561
- stubApi.internalEngine.mockReturnValue({ options: { axis: 'x' } })
917
+ stubApi.internalEngine.mockReturnValue({
918
+ options: { active: true, axis: 'x' },
919
+ scrollSnapList: { slidesBySnap: [] },
920
+ })
562
921
  try {
563
922
  render(<Basic autoplay wheelGestures />)
564
923
  viewport.dispatchEvent(new WheelEvent('wheel', { deltaX: 2, deltaY: 40 }))
@@ -581,6 +940,146 @@ describe('useCarousel + lifecycle', () => {
581
940
  })
582
941
  })
583
942
 
943
+ describe('Carousel autoplay', () => {
944
+ function root(container: HTMLElement) {
945
+ return container.querySelector('[data-slot="carousel"]') as HTMLElement
946
+ }
947
+
948
+ it('starts rotation on mount', () => {
949
+ const autoplay = mockAutoplay()
950
+ render(<Basic autoplay />)
951
+ expect(autoplay.play).toHaveBeenCalledTimes(1)
952
+ })
953
+
954
+ it('stays off under reduced motion', () => {
955
+ const autoplay = mockAutoplay()
956
+ render(
957
+ <ReducedMotionProvider disableAnimations>
958
+ <Basic autoplay />
959
+ </ReducedMotionProvider>,
960
+ )
961
+ expect(autoplay.play).not.toHaveBeenCalled()
962
+ })
963
+
964
+ it('stops when reduced motion turns on, and starts again when it turns off', () => {
965
+ const autoplay = mockAutoplay()
966
+ const { rerender } = render(
967
+ <ReducedMotionProvider>
968
+ <Basic autoplay />
969
+ </ReducedMotionProvider>,
970
+ )
971
+ expect(autoplay.isPlaying()).toBe(true)
972
+ rerender(
973
+ <ReducedMotionProvider disableAnimations>
974
+ <Basic autoplay />
975
+ </ReducedMotionProvider>,
976
+ )
977
+ expect(autoplay.isPlaying()).toBe(false)
978
+ rerender(
979
+ <ReducedMotionProvider>
980
+ <Basic autoplay />
981
+ </ReducedMotionProvider>,
982
+ )
983
+ expect(autoplay.isPlaying()).toBe(true)
984
+ })
985
+
986
+ it('pauses while hovered and resumes when the pointer leaves', () => {
987
+ const autoplay = mockAutoplay()
988
+ const { container } = render(<Basic autoplay />)
989
+ fireEvent.pointerEnter(root(container))
990
+ expect(autoplay.isPlaying()).toBe(false)
991
+ expect(container.querySelector('[data-slot="carousel-pagination-indicator"]')).toBeNull()
992
+ fireEvent.pointerLeave(root(container))
993
+ expect(autoplay.isPlaying()).toBe(true)
994
+ expect(autoplay.play).toHaveBeenCalledTimes(2)
995
+ })
996
+
997
+ it('pauses while focus is inside and resumes once it leaves the carousel', () => {
998
+ const autoplay = mockAutoplay()
999
+ render(
1000
+ <>
1001
+ <Basic autoplay />
1002
+ <button type="button">Outside</button>
1003
+ </>,
1004
+ )
1005
+ act(() => screen.getByRole('button', { name: 'Next slide' }).focus())
1006
+ expect(autoplay.isPlaying()).toBe(false)
1007
+ act(() => screen.getByRole('button', { name: 'Previous slide' }).focus())
1008
+ expect(autoplay.isPlaying()).toBe(false)
1009
+ act(() => screen.getByRole('button', { name: 'Outside' }).focus())
1010
+ expect(autoplay.isPlaying()).toBe(true)
1011
+ })
1012
+
1013
+ it('waits for both the pointer and focus to leave', () => {
1014
+ const autoplay = mockAutoplay()
1015
+ const { container } = render(
1016
+ <>
1017
+ <Basic autoplay />
1018
+ <button type="button">Outside</button>
1019
+ </>,
1020
+ )
1021
+ fireEvent.pointerEnter(root(container))
1022
+ act(() => screen.getByRole('button', { name: 'Next slide' }).focus())
1023
+ fireEvent.pointerLeave(root(container))
1024
+ expect(autoplay.isPlaying()).toBe(false)
1025
+ act(() => screen.getByRole('button', { name: 'Outside' }).focus())
1026
+ expect(autoplay.isPlaying()).toBe(true)
1027
+ })
1028
+
1029
+ it('keeps a pointerdown stop after the pointer leaves, without resumeAfter', () => {
1030
+ const autoplay = mockAutoplay()
1031
+ const { container } = render(<Basic autoplay />)
1032
+ fireEvent.pointerEnter(root(container))
1033
+ emit('pointerdown')
1034
+ fireEvent.pointerLeave(root(container))
1035
+ expect(autoplay.isPlaying()).toBe(false)
1036
+ expect(autoplay.play).toHaveBeenCalledTimes(1)
1037
+ })
1038
+
1039
+ it('holds the resumeAfter restart while hovered or focused', () => {
1040
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
1041
+ try {
1042
+ const autoplay = mockAutoplay()
1043
+ const { container } = render(
1044
+ <>
1045
+ <Basic autoplay={{ resumeAfter: 1000 }} />
1046
+ <button type="button">Outside</button>
1047
+ </>,
1048
+ )
1049
+ fireEvent.pointerEnter(root(container))
1050
+ emit('pointerdown')
1051
+ emit('autoplay:interaction', { detail: { interaction: 'pointerdown' } })
1052
+ act(() => vi.advanceTimersByTime(1000))
1053
+ expect(autoplay.isPlaying()).toBe(false)
1054
+
1055
+ act(() => screen.getByRole('button', { name: 'Next slide' }).focus())
1056
+ fireEvent.pointerLeave(root(container))
1057
+ expect(autoplay.isPlaying()).toBe(false)
1058
+
1059
+ act(() => screen.getByRole('button', { name: 'Outside' }).focus())
1060
+ expect(autoplay.isPlaying()).toBe(true)
1061
+ } finally {
1062
+ vi.useRealTimers()
1063
+ }
1064
+ })
1065
+
1066
+ it('restarts after resumeAfter once nothing is inside', () => {
1067
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
1068
+ try {
1069
+ const autoplay = mockAutoplay()
1070
+ render(<Basic autoplay={{ resumeAfter: 1000 }} />)
1071
+ emit('autoplay:interaction', { detail: { interaction: 'pointerdown' } })
1072
+ expect(autoplay.isPlaying()).toBe(false)
1073
+ act(() => vi.advanceTimersByTime(999))
1074
+ expect(autoplay.isPlaying()).toBe(false)
1075
+ act(() => vi.advanceTimersByTime(1))
1076
+ expect(autoplay.isPlaying()).toBe(true)
1077
+ } finally {
1078
+ vi.useRealTimers()
1079
+ }
1080
+ })
1081
+ })
1082
+
584
1083
  describe('useLinkedCarousels', () => {
585
1084
  function makeApi() {
586
1085
  const stub = {
@@ -650,6 +1149,21 @@ describe('a11y', () => {
650
1149
  expect(await axe(container)).toHaveNoViolations()
651
1150
  })
652
1151
 
1152
+ it('reports no landmark violations with several carousels on one page', async () => {
1153
+ const { container } = render(
1154
+ <main>
1155
+ <Basic />
1156
+ <Basic />
1157
+ <Basic aria-label="New arrivals" />
1158
+ <Basic aria-label="Best sellers" />
1159
+ </main>,
1160
+ )
1161
+ const results = await axe(container, {
1162
+ runOnly: ['landmark-unique', 'aria-allowed-role', 'aria-hidden-focus'],
1163
+ })
1164
+ expect(results).toHaveNoViolations()
1165
+ })
1166
+
653
1167
  it('has no accessibility violations with a thumbnail rail', async () => {
654
1168
  const { container } = render(
655
1169
  <Carousel>