@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
@@ -12,7 +12,7 @@ import ClassNames, { type ClassNamesOptionsType } from 'embla-carousel-class-nam
12
12
  import Fade, { type FadeOptionsType } from 'embla-carousel-fade'
13
13
  import { WheelGesturesPlugin, type WheelGesturesPluginOptions } from 'embla-carousel-wheel-gestures'
14
14
  import type { EmblaCarouselType, EmblaOptionsType, EmblaPluginType } from 'embla-carousel'
15
- import { cn } from '../../internal/utils'
15
+ import { cn, useComposedRefs } from '../../internal/utils'
16
16
  import { useDirection } from '../../hooks/use-direction'
17
17
  import { useReducedMotion } from '../../hooks/use-reduced-motion'
18
18
 
@@ -67,6 +67,80 @@ function useCarousel(): CarouselContextValue {
67
67
  return ctx
68
68
  }
69
69
 
70
+ // The root already names the carousel, so the plugin's empty values keep the
71
+ // viewport from becoming a second landmark (its setter skips empty strings).
72
+ const CAROUSEL_ACCESSIBILITY_VIEWPORT: CarouselAccessibilityOptions = {
73
+ carouselRole: '',
74
+ carouselAriaLabel: '',
75
+ carouselAriaRoleDescription: '',
76
+ }
77
+
78
+ function getShownSlides(api: CarouselApi): Set<number> {
79
+ const { options, scrollSnapList } = api.internalEngine()
80
+ if (!options.active) return new Set(api.slideNodes().keys())
81
+ // Fade stacks every slide in one place, and the in-view list stays empty
82
+ // until the engine's IntersectionObserver first reports.
83
+ const inView = api.plugins().fade ? [] : api.slidesInView()
84
+ return new Set(inView.length ? inView : (scrollSnapList.slidesBySnap[api.selectedSnap()] ?? []))
85
+ }
86
+
87
+ function useSlideVisibility(api: CarouselApi | undefined, enabled: boolean) {
88
+ React.useEffect(() => {
89
+ if (!api || !enabled) return
90
+ const inert = new Set<HTMLElement>()
91
+ const labels = new Map<HTMLElement, string>()
92
+
93
+ const release = (node: HTMLElement) => {
94
+ if (inert.delete(node)) node.removeAttribute('inert')
95
+ if (labels.has(node) && node.getAttribute('aria-label') === labels.get(node)) node.removeAttribute('aria-label')
96
+ labels.delete(node)
97
+ }
98
+
99
+ const sync = (focused: EventTarget | null) => {
100
+ const slides = api.slideNodes()
101
+ const shown = getShownSlides(api)
102
+ new Set([...inert, ...labels.keys()]).forEach((node) => {
103
+ if (!slides.includes(node)) release(node)
104
+ })
105
+ slides.forEach((node, index) => {
106
+ const hidden = !shown.has(index) && !(focused instanceof Node && node.contains(focused))
107
+ if (hidden && !inert.has(node)) {
108
+ node.setAttribute('inert', '')
109
+ inert.add(node)
110
+ } else if (!hidden && inert.delete(node)) {
111
+ node.removeAttribute('inert')
112
+ }
113
+
114
+ const ownLabel = node.getAttribute('aria-label')
115
+ if (node.hasAttribute('aria-labelledby') || (ownLabel !== null && ownLabel !== labels.get(node))) {
116
+ labels.delete(node)
117
+ return
118
+ }
119
+ const label = `${index + 1} of ${slides.length}`
120
+ if (ownLabel !== label) node.setAttribute('aria-label', label)
121
+ labels.set(node, label)
122
+ })
123
+ }
124
+
125
+ const onChange = () => sync(document.activeElement)
126
+ const onFocusOut = (event: FocusEvent) => sync(event.relatedTarget)
127
+ const viewport = api.rootNode()
128
+
129
+ onChange()
130
+ api.on('select', onChange)
131
+ api.on('reinit', onChange)
132
+ api.on('slidesinview', onChange)
133
+ viewport?.addEventListener('focusout', onFocusOut)
134
+ return () => {
135
+ api.off('select', onChange)
136
+ api.off('reinit', onChange)
137
+ api.off('slidesinview', onChange)
138
+ viewport?.removeEventListener('focusout', onFocusOut)
139
+ new Set([...inert, ...labels.keys()]).forEach(release)
140
+ }
141
+ }, [api, enabled])
142
+ }
143
+
70
144
  interface CarouselProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'onSelect' | 'onScroll' | 'children'> {
71
145
  /**
72
146
  * Scroll axis. Maps to Embla's `axis`; exposed as `data-orientation`.
@@ -111,7 +185,7 @@ interface CarouselProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'onS
111
185
  duration?: number
112
186
  /** Escape hatch: a raw Embla options object, merged last so it wins over the flat props. */
113
187
  options?: CarouselOptions
114
- /** Enable the Autoplay plugin. `resumeAfter` (ms) restarts the timer after user interaction. */
188
+ /** Enable the Autoplay plugin. It pauses while hovered or focused and stays off under reduced motion. `resumeAfter` (ms) restarts the timer after user interaction. */
115
189
  autoplay?: boolean | CarouselAutoplayOptions
116
190
  /** Enable continuous Auto Scroll. Mutually exclusive with `autoplay`; paused under reduced motion. */
117
191
  autoScroll?: boolean | CarouselAutoScrollOptions
@@ -122,7 +196,7 @@ interface CarouselProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'onS
122
196
  /** Enable the Class Names plugin, which toggles `snapped` / `inView` classes on slides. */
123
197
  classNames?: boolean | CarouselClassNamesOptions
124
198
  /**
125
- * Keyboard/ARIA plugin for the viewport. Set `false` to opt out.
199
+ * Slide semantics. `true` makes slides outside the viewport `inert` and labels each slide "n of m". An options object hands slides to Embla's Accessibility plugin instead, and `false` leaves them alone.
126
200
  * @default true
127
201
  */
128
202
  accessibility?: boolean | CarouselAccessibilityOptions
@@ -207,8 +281,8 @@ function Carousel({
207
281
 
208
282
  const plugins = React.useMemo<CarouselPlugin[]>(() => {
209
283
  const list: CarouselPlugin[] = []
210
- if (accessibility !== false) {
211
- list.push(Accessibility(typeof accessibility === 'object' ? accessibility : undefined))
284
+ if (typeof accessibility === 'object') {
285
+ list.push(Accessibility({ ...CAROUSEL_ACCESSIBILITY_VIEWPORT, ...accessibility }))
212
286
  }
213
287
  if (wheelGestures !== false) {
214
288
  list.push(WheelGesturesPlugin(typeof wheelGestures === 'object' ? wheelGestures : undefined))
@@ -270,6 +344,11 @@ function Carousel({
270
344
  ])
271
345
 
272
346
  const [viewportRef, emblaApi] = useEmblaCarousel(emblaOptions, plugins)
347
+ useSlideVisibility(emblaApi, accessibility === true)
348
+
349
+ const { ref: forwardedRef, ...rootProps } = rest as typeof rest & { ref?: React.Ref<HTMLDivElement> }
350
+ const rootRef = React.useRef<HTMLDivElement>(null)
351
+ const composedRootRef = useComposedRefs(rootRef, forwardedRef)
273
352
 
274
353
  const setApiRef = React.useRef(setApi)
275
354
  const onReInitRef = React.useRef(onReInit)
@@ -346,7 +425,6 @@ function Carousel({
346
425
  const syncScroll = () => {
347
426
  notifyScroll()
348
427
  }
349
- const syncInView = () => {}
350
428
 
351
429
  syncFull()
352
430
  setApiRef.current?.(emblaApi)
@@ -372,7 +450,6 @@ function Carousel({
372
450
  emblaApi.on('reinit', handleReInit)
373
451
  emblaApi.on('select', handleSelect)
374
452
  emblaApi.on('scroll', handleScroll)
375
- emblaApi.on('slidesinview', syncInView)
376
453
  emblaApi.on('slideschanged', syncFull)
377
454
 
378
455
  const autoplayPlugin = emblaApi.plugins().autoplay
@@ -396,6 +473,21 @@ function Carousel({
396
473
  }, resumeAfter)
397
474
  }
398
475
 
476
+ const root = rootRef.current
477
+ let hovered = false
478
+ let focused = false
479
+ // Rotation that hover or focus stopped, owed a restart once both have left.
480
+ let held = false
481
+ const playAutoplay = () => {
482
+ if (hovered || focused) held = true
483
+ else emblaApi.plugins().autoplay?.play()
484
+ }
485
+ const interruptAutoplay = () => {
486
+ held = false
487
+ emblaApi.plugins().autoplay?.stop()
488
+ scheduleResume(playAutoplay)
489
+ }
490
+
399
491
  let cleanupAutoplay: (() => void) | undefined
400
492
  if (autoplayPlugin) {
401
493
  const rawDelay = autoplayPlugin.options.delay
@@ -406,6 +498,7 @@ function Carousel({
406
498
  isPlaying: autoplayPlugin.isPlaying(),
407
499
  })
408
500
  const onPlay = () => {
501
+ held = false
409
502
  clearResumeTimer()
410
503
  setAutoplayState((s) => (s ? { ...s, isPlaying: true } : s))
411
504
  }
@@ -413,26 +506,71 @@ function Carousel({
413
506
  const onTimerSet = () => setAutoplayState((s) => (s ? { ...s, cycleId: s.cycleId + 1, isPlaying: true } : s))
414
507
  const onTimerStopped = () => setAutoplayState((s) => (s ? { ...s, isPlaying: false } : s))
415
508
  const resetOnSelect = () => autoplayPlugin.reset()
509
+ const onUserStop = () => {
510
+ held = false
511
+ }
416
512
  const onInteraction = (_api: CarouselApi, event: { detail: { interaction: string } }) => {
417
513
  if (event.detail.interaction === 'pointerdown' || event.detail.interaction === 'slidefocus') {
418
- autoplayPlugin.stop()
419
- scheduleResume(() => emblaApi.plugins().autoplay?.play())
514
+ interruptAutoplay()
420
515
  }
421
516
  }
517
+ const hold = () => {
518
+ if (!emblaApi.plugins().autoplay?.isPlaying()) return
519
+ held = true
520
+ emblaApi.plugins().autoplay?.stop()
521
+ }
522
+ const release = () => {
523
+ if (held) playAutoplay()
524
+ }
525
+ const onPointerEnter = () => {
526
+ hovered = true
527
+ hold()
528
+ }
529
+ const onPointerLeave = () => {
530
+ hovered = false
531
+ release()
532
+ }
533
+ const onFocusIn = () => {
534
+ focused = true
535
+ hold()
536
+ }
537
+ const onFocusOut = (event: FocusEvent) => {
538
+ if (event.relatedTarget instanceof Node && root?.contains(event.relatedTarget)) return
539
+ focused = false
540
+ release()
541
+ }
422
542
  emblaApi.on('autoplay:play', onPlay)
423
543
  emblaApi.on('autoplay:stop', onStop)
424
544
  emblaApi.on('autoplay:timerset', onTimerSet)
425
545
  emblaApi.on('autoplay:timerstopped', onTimerStopped)
426
546
  emblaApi.on('select', resetOnSelect)
547
+ emblaApi.on('pointerdown', onUserStop)
548
+ emblaApi.on('slidefocus', onUserStop)
427
549
  if (resumeAfter > 0) emblaApi.on('autoplay:interaction', onInteraction)
428
- if (autoplayEnabled) autoplayPlugin.play()
550
+ root?.addEventListener('pointerenter', onPointerEnter)
551
+ root?.addEventListener('pointerleave', onPointerLeave)
552
+ root?.addEventListener('focusin', onFocusIn)
553
+ root?.addEventListener('focusout', onFocusOut)
554
+ if (autoplayEnabled && !reducedMotion) {
555
+ hovered = !!root?.matches(':hover')
556
+ focused = !!root?.contains(document.activeElement)
557
+ playAutoplay()
558
+ } else {
559
+ autoplayPlugin.stop()
560
+ }
429
561
  cleanupAutoplay = () => {
430
562
  emblaApi.off('autoplay:play', onPlay)
431
563
  emblaApi.off('autoplay:stop', onStop)
432
564
  emblaApi.off('autoplay:timerset', onTimerSet)
433
565
  emblaApi.off('autoplay:timerstopped', onTimerStopped)
434
566
  emblaApi.off('select', resetOnSelect)
567
+ emblaApi.off('pointerdown', onUserStop)
568
+ emblaApi.off('slidefocus', onUserStop)
435
569
  if (resumeAfter > 0) emblaApi.off('autoplay:interaction', onInteraction)
570
+ root?.removeEventListener('pointerenter', onPointerEnter)
571
+ root?.removeEventListener('pointerleave', onPointerLeave)
572
+ root?.removeEventListener('focusin', onFocusIn)
573
+ root?.removeEventListener('focusout', onFocusOut)
436
574
  }
437
575
  } else {
438
576
  setAutoplayState(null)
@@ -461,9 +599,8 @@ function Carousel({
461
599
  const along = Math.abs(vertical ? event.deltaY : event.deltaX)
462
600
  const across = Math.abs(vertical ? event.deltaX : event.deltaY)
463
601
  if (along <= across) return
464
- if (autoplayPlugin?.isPlaying()) {
465
- autoplayPlugin.stop()
466
- scheduleResume(() => emblaApi.plugins().autoplay?.play())
602
+ if (autoplayPlugin?.isPlaying() || held) {
603
+ interruptAutoplay()
467
604
  } else if (autoScrollPlugin?.isPlaying()) {
468
605
  autoScrollPlugin.stop()
469
606
  scheduleResume(() => emblaApi.plugins().autoScroll?.play())
@@ -477,14 +614,13 @@ function Carousel({
477
614
  emblaApi.off('reinit', handleReInit)
478
615
  emblaApi.off('select', handleSelect)
479
616
  emblaApi.off('scroll', handleScroll)
480
- emblaApi.off('slidesinview', syncInView)
481
617
  emblaApi.off('slideschanged', syncFull)
482
618
  cleanupAutoplay?.()
483
619
  cleanupAutoScroll?.()
484
620
  cleanupWheel?.()
485
621
  clearResumeTimer()
486
622
  }
487
- }, [emblaApi, autoplayEnabled, autoScrollEnabled, resumeAfterMs])
623
+ }, [emblaApi, autoplayEnabled, autoScrollEnabled, resumeAfterMs, reducedMotion])
488
624
 
489
625
  const scrollPrev = React.useCallback(() => emblaApi?.goToPrev(), [emblaApi])
490
626
  const scrollNext = React.useCallback(() => emblaApi?.goToNext(), [emblaApi])
@@ -536,11 +672,11 @@ function Carousel({
536
672
  <div
537
673
  data-slot="carousel"
538
674
  data-orientation={orientation}
539
- role="region"
675
+ role={rootProps['aria-label'] || rootProps['aria-labelledby'] ? 'region' : 'group'}
540
676
  aria-roledescription="carousel"
541
- aria-label="Carousel"
542
677
  className={cn('relative', className)}
543
- {...rest}
678
+ {...rootProps}
679
+ ref={composedRootRef}
544
680
  >
545
681
  {children}
546
682
  </div>
@@ -557,6 +693,7 @@ function CarouselContent({ className, children, viewportProps, ...rest }: Carous
557
693
  const { viewportRef, orientation, autoHeight } = useCarousel()
558
694
  return (
559
695
  <div
696
+ data-base-ui-swipe-ignore={orientation === 'vertical' ? 'y' : 'x'}
560
697
  {...viewportProps}
561
698
  ref={viewportRef}
562
699
  data-slot="carousel-viewport"
@@ -641,7 +778,7 @@ const CAROUSEL_THUMB_OPTIONS: CarouselOptions = { slides: ':scope > [data-slot=c
641
778
  const CAROUSEL_THUMB_TRANSITION = cn(
642
779
  'transition-[opacity,translate,scale] motion-reduce:transition-none',
643
780
  'duration-[300ms,250ms,250ms]',
644
- 'ease-[ease-out,cubic-bezier(0.175,0.885,0.32,1.5),cubic-bezier(0.175,0.885,0.32,1.5)]',
781
+ 'ease-[ease-out,var(--ease-spring),var(--ease-spring)]',
645
782
  'active:duration-[300ms,100ms,100ms] active:ease-[ease-out,ease-in-out,ease-in-out]',
646
783
  )
647
784
 
@@ -731,6 +868,7 @@ function CarouselThumbs({
731
868
  // means the same thing on both carousels.
732
869
  containScroll="keepSnaps"
733
870
  options={CAROUSEL_THUMB_OPTIONS}
871
+ accessibility={false}
734
872
  setApi={setApi}
735
873
  light={light}
736
874
  role="group"
@@ -881,9 +1019,9 @@ function CarouselPrev({ className, position = 'inside', disabled: disabledProp,
881
1019
  type: 'button',
882
1020
  'data-slot': 'carousel-prev',
883
1021
  'data-disabled': disabled || undefined,
1022
+ 'aria-disabled': disabled || undefined,
884
1023
  'aria-label': 'Previous slide',
885
- disabled,
886
- onClick: scrollPrev,
1024
+ onClick: disabled ? undefined : scrollPrev,
887
1025
  suppressHydrationWarning: true,
888
1026
  } as unknown as React.ButtonHTMLAttributes<HTMLButtonElement>,
889
1027
  props,
@@ -921,9 +1059,9 @@ function CarouselNext({ className, position = 'inside', disabled: disabledProp,
921
1059
  type: 'button',
922
1060
  'data-slot': 'carousel-next',
923
1061
  'data-disabled': disabled || undefined,
1062
+ 'aria-disabled': disabled || undefined,
924
1063
  'aria-label': 'Next slide',
925
- disabled,
926
- onClick: scrollNext,
1064
+ onClick: disabled ? undefined : scrollNext,
927
1065
  suppressHydrationWarning: true,
928
1066
  } as unknown as React.ButtonHTMLAttributes<HTMLButtonElement>,
929
1067
  props,
@@ -1020,6 +1158,13 @@ function CarouselPagination({
1020
1158
  )
1021
1159
  }
1022
1160
 
1161
+ // The bar slides in under its parent's `overflow-hidden` instead of growing, so
1162
+ // the countdown never triggers layout.
1163
+ const AUTOPLAY_INDICATOR_TRAVEL: Record<CarouselOrientation, { start: string; end: string }> = {
1164
+ horizontal: { start: '-translate-x-full rtl:translate-x-full', end: 'translate-x-0' },
1165
+ vertical: { start: '-translate-y-full', end: 'translate-y-0' },
1166
+ }
1167
+
1023
1168
  interface CarouselAutoplayIndicatorProps {
1024
1169
  delay: number
1025
1170
  isPlaying: boolean
@@ -1041,8 +1186,7 @@ function CarouselAutoplayIndicator({ delay, isPlaying, light, orientation }: Car
1041
1186
  }
1042
1187
  }, [])
1043
1188
 
1044
- const isHorizontal = orientation === 'horizontal'
1045
- const fillValue = armed && isPlaying ? '100%' : '0%'
1189
+ const travel = AUTOPLAY_INDICATOR_TRAVEL[orientation]
1046
1190
 
1047
1191
  return (
1048
1192
  <span
@@ -1051,17 +1195,12 @@ function CarouselAutoplayIndicator({ delay, isPlaying, light, orientation }: Car
1051
1195
  data-orientation={orientation}
1052
1196
  data-playing={isPlaying || undefined}
1053
1197
  className={cn(
1054
- 'absolute rounded-full',
1055
- isHorizontal ? 'inset-y-0 inset-s-0' : 'inset-x-0 top-0',
1056
- isHorizontal ? 'motion-safe:transition-[width]' : 'motion-safe:transition-[height]',
1057
- 'motion-safe:ease-linear',
1198
+ 'absolute inset-0 rounded-full',
1199
+ 'motion-safe:transition-[translate] motion-safe:ease-linear',
1200
+ armed && isPlaying ? travel.end : travel.start,
1058
1201
  light ? 'bg-white' : 'bg-primary',
1059
1202
  )}
1060
- style={{
1061
- transitionDuration: `${delay}ms`,
1062
- width: isHorizontal ? fillValue : undefined,
1063
- height: isHorizontal ? undefined : fillValue,
1064
- }}
1203
+ style={{ transitionDuration: `${delay}ms` }}
1065
1204
  />
1066
1205
  )
1067
1206
  }
@@ -1262,14 +1401,6 @@ function CarouselAutoplayCircularIndicator({
1262
1401
  * "main + thumbnails" pattern. Wires `select` on each so navigating either
1263
1402
  * one drives the other. Both apis can be undefined initially (e.g. waiting on
1264
1403
  * `setApi`); the effect re-runs once both resolve.
1265
- *
1266
- * @example
1267
- * const [mainApi, setMainApi] = useState<CarouselApi>()
1268
- * const [thumbsApi, setThumbsApi] = useState<CarouselApi>()
1269
- * useLinkedCarousels(mainApi, thumbsApi)
1270
- *
1271
- * <Carousel setApi={setMainApi}>…</Carousel>
1272
- * <Carousel setApi={setThumbsApi} align="start" containScroll="keepSnaps">…</Carousel>
1273
1404
  */
1274
1405
  function useLinkedCarousels(mainApi: CarouselApi | undefined, thumbsApi: CarouselApi | undefined): void {
1275
1406
  React.useEffect(() => {
@@ -86,8 +86,8 @@ describe('Chip', () => {
86
86
 
87
87
  await waitFor(() => {
88
88
  expect(screen.queryByRole('button', { name: /Red/ })).toBeNull()
89
+ expect(onDismiss).toHaveBeenCalledTimes(1)
89
90
  })
90
- expect(onDismiss).toHaveBeenCalledTimes(1)
91
91
  })
92
92
 
93
93
  it('calls user onClick before dismissing and respects preventDefault', async () => {
@@ -215,11 +215,10 @@ describe('ChipGroup', () => {
215
215
  expect(screen.queryByRole('button', { name: /A/ })).toBeNull()
216
216
  expect(screen.queryByRole('button', { name: /B/ })).toBeNull()
217
217
  expect(screen.queryByRole('button', { name: /C/ })).toBeNull()
218
+ expect(onDismissA).toHaveBeenCalledTimes(1)
219
+ expect(onDismissB).toHaveBeenCalledTimes(1)
220
+ expect(onDismissC).toHaveBeenCalledTimes(1)
218
221
  })
219
-
220
- expect(onDismissA).toHaveBeenCalledTimes(1)
221
- expect(onDismissB).toHaveBeenCalledTimes(1)
222
- expect(onDismissC).toHaveBeenCalledTimes(1)
223
222
  })
224
223
 
225
224
  it('clearAll() ignores non-dismissible chips', async () => {
@@ -20,6 +20,11 @@ function inputs() {
20
20
  }
21
21
 
22
22
  describe('ColorArea', () => {
23
+ it('keeps a surrounding Drawer from swiping on any drag that starts on the area', () => {
24
+ const { container } = render(<ColorArea defaultValue="#3b82f6" />)
25
+ expect(container.querySelector('[data-slot="color-area"]')).toHaveAttribute('data-base-ui-swipe-ignore', '')
26
+ })
27
+
23
28
  it('exposes one range input per axis, labeled by channel', () => {
24
29
  render(<ColorArea defaultValue="hsb(0, 100%, 100%)" xChannel="saturation" yChannel="brightness" />)
25
30
  const [x, y] = inputs()
@@ -318,6 +318,7 @@ function ColorArea({
318
318
  ref={containerRef}
319
319
  role="group"
320
320
  aria-label={ariaLabel}
321
+ data-base-ui-swipe-ignore=""
321
322
  {...props}
322
323
  data-slot="color-area"
323
324
  data-space={space}
@@ -36,6 +36,11 @@ const thumb = () => document.querySelector('[data-slot="color-slider-thumb"]') a
36
36
  const stopCount = () => (track().style.backgroundImage.match(/rgba?\(/g) ?? []).length
37
37
 
38
38
  describe('ColorSlider', () => {
39
+ it('keeps a surrounding Drawer from swiping on any drag that starts on the slider', () => {
40
+ const { container } = renderSlider({ channel: 'hue', defaultValue: '#3b82f6' })
41
+ expect(container.querySelector('[data-slot="color-slider"]')).toHaveAttribute('data-base-ui-swipe-ignore', '')
42
+ })
43
+
39
44
  it('exposes the channel as a labeled range input', () => {
40
45
  renderSlider({ channel: 'hue', defaultValue: 'hsb(120, 50%, 50%)' })
41
46
  expect(slider()).toHaveAttribute('aria-label', 'Hue')
@@ -271,6 +271,7 @@ function ColorSlider({
271
271
  return (
272
272
  <div
273
273
  ref={containerRef}
274
+ data-base-ui-swipe-ignore=""
274
275
  {...props}
275
276
  data-slot="color-slider"
276
277
  data-orientation={orientation}
@@ -26,7 +26,7 @@ const pickerVariants = cva('relative isolate flex gap-1', {
26
26
  // The button is the outer ring's box, so the swatch has to sit inside it. At 0.8em
27
27
  // the gap either side is 0.1em, which holds at every size because both are ems.
28
28
  const itemVariants = cva(
29
- 'outline-ring relative flex size-[1em] shrink-0 transform-gpu cursor-pointer items-center justify-center focus-visible:outline-3 motion-safe:transition motion-safe:duration-250 motion-safe:ease-[cubic-bezier(0.175,0.885,0.32,1.5)] motion-safe:active:translate-y-px motion-safe:active:scale-90 motion-safe:active:duration-100 motion-safe:active:ease-in-out data-disabled:pointer-events-none data-disabled:cursor-default',
29
+ 'outline-ring relative flex size-[1em] shrink-0 transform-gpu cursor-pointer items-center justify-center focus-visible:outline-3 motion-safe:transition motion-safe:duration-250 motion-safe:ease-spring motion-safe:active:translate-y-px motion-safe:active:scale-90 motion-safe:active:duration-100 motion-safe:active:ease-in-out data-disabled:pointer-events-none data-disabled:cursor-default',
30
30
  { variants: { shape: COLOR_SWATCH_SHAPES } },
31
31
  )
32
32
 
@@ -13,6 +13,7 @@ import {
13
13
  ComboboxItem,
14
14
  ComboboxList,
15
15
  ComboboxValue,
16
+ createComboboxItems,
16
17
  } from './combobox'
17
18
 
18
19
  const FRAMEWORKS = ['Next.js', 'SvelteKit', 'Nuxt.js', 'Remix', 'Astro']
@@ -161,6 +162,38 @@ describe('Combobox', () => {
161
162
  expect(onValueChange).toHaveBeenCalledWith('Remix', expect.anything())
162
163
  })
163
164
 
165
+ it('selects by ID from a createComboboxItems collection and shows the label', async () => {
166
+ const user = setupUser()
167
+ const onValueChange = vi.fn()
168
+ const people = [
169
+ { id: 'liam', name: 'Liam Hudson' },
170
+ { id: 'sarah', name: 'Sarah Jenkins' },
171
+ ]
172
+ const items = createComboboxItems(people, { getValue: (person) => person.id, getLabel: (person) => person.name })
173
+ render(
174
+ <Combobox items={items} onValueChange={onValueChange}>
175
+ <ComboboxInput aria-label="Assign to" />
176
+ <ComboboxContent>
177
+ <ComboboxList>
178
+ {(person: (typeof people)[number]) => (
179
+ <ComboboxItem key={person.id} value={person.id}>
180
+ {person.name}
181
+ </ComboboxItem>
182
+ )}
183
+ </ComboboxList>
184
+ </ComboboxContent>
185
+ </Combobox>,
186
+ )
187
+
188
+ const input = screen.getByRole('combobox', { name: 'Assign to' })
189
+ await user.type(input, 'sar')
190
+ expect(screen.queryByRole('option', { name: 'Liam Hudson' })).toBeNull()
191
+ await user.click(await screen.findByRole('option', { name: 'Sarah Jenkins' }))
192
+
193
+ expect(onValueChange).toHaveBeenCalledWith('sarah', expect.anything())
194
+ await waitFor(() => expect(input).toHaveValue('Sarah Jenkins'))
195
+ })
196
+
164
197
  it('renders the check indicator on the selected item', async () => {
165
198
  const user = setupUser()
166
199
  renderSingle({ defaultValue: 'Astro' })
@@ -219,6 +252,39 @@ describe('Combobox', () => {
219
252
  expect(screen.queryByRole('button', { name: 'Toggle popup' })).toBeNull()
220
253
  })
221
254
 
255
+ it('keeps ComboboxEmpty in the accessibility tree as a status region while results show', async () => {
256
+ const user = setupUser()
257
+ renderSingle()
258
+ await user.click(screen.getByRole('combobox'))
259
+ await screen.findByRole('option', { name: 'Next.js' })
260
+
261
+ const empty = document.querySelector('[data-slot="combobox-empty"]')
262
+ expect(empty).toBeEmptyDOMElement()
263
+ expect(empty).not.toHaveClass('hidden')
264
+ expect(screen.getByRole('status')).toBe(empty)
265
+ })
266
+
267
+ it('renders the no-results text inside the status region', async () => {
268
+ const user = setupUser()
269
+ renderSingle()
270
+ const input = screen.getByRole('combobox')
271
+ await user.click(input)
272
+ await user.type(input, 'zzzzzz')
273
+ const status = await screen.findByRole('status')
274
+ expect(status).toHaveTextContent('No items found.')
275
+ expect(status).toHaveAttribute('data-slot', 'combobox-empty')
276
+ })
277
+
278
+ it('has no accessibility violations with the popup open and no matches', async () => {
279
+ const user = setupUser()
280
+ renderSingle()
281
+ const input = screen.getByRole('combobox')
282
+ await user.click(input)
283
+ await user.type(input, 'zzzzzz')
284
+ await screen.findByText('No items found.')
285
+ expect(await axe(document.body, { rules: { region: { enabled: false } } })).toHaveNoViolations()
286
+ })
287
+
222
288
  it('shows ComboboxEmpty when the filter has no matches', async () => {
223
289
  const user = setupUser()
224
290
  renderSingle()
@@ -30,9 +30,13 @@ function useComboboxContext() {
30
30
  return ctx
31
31
  }
32
32
 
33
- type BaseComboboxRootProps = React.ComponentProps<typeof BaseCombobox.Root>
33
+ type ComboboxProps<
34
+ Value = unknown,
35
+ Multiple extends boolean | undefined = false,
36
+ Item = Value,
37
+ > = BaseCombobox.Root.Props<Value, Multiple, Item> & ComboboxOwnProps
34
38
 
35
- interface ComboboxProps extends BaseComboboxRootProps {
39
+ interface ComboboxOwnProps {
36
40
  /**
37
41
  * Input height, popup radius, and item sizing.
38
42
  * @default 'md'
@@ -55,7 +59,7 @@ interface ComboboxProps extends BaseComboboxRootProps {
55
59
  icon?: boolean
56
60
  }
57
61
 
58
- function Combobox({
62
+ function Combobox<Value, Multiple extends boolean | undefined = false, Item = Value>({
59
63
  size = 'md',
60
64
  variant = 'outline',
61
65
  clearable = false,
@@ -63,7 +67,7 @@ function Combobox({
63
67
  grid = false,
64
68
  children,
65
69
  ...rest
66
- }: ComboboxProps) {
70
+ }: ComboboxProps<Value, Multiple, Item>) {
67
71
  const reducedMotion = useReducedMotion()
68
72
  const ctx = React.useMemo<ComboboxContextValue>(
69
73
  () => ({ size, variant, clearable, icon, grid, reducedMotion }),
@@ -346,7 +350,7 @@ function ComboboxContent({ className, children, ...props }: ComboboxContentProps
346
350
  'w-(--anchor-width) min-w-36',
347
351
  'max-h-(--available-height) overflow-hidden',
348
352
  'origin-(--transform-origin)',
349
- 'motion-safe:transition-[opacity,scale] motion-safe:duration-200 motion-safe:ease-[cubic-bezier(0.175,0.885,0.32,1.5)]',
353
+ 'motion-safe:ease-spring motion-safe:transition-[opacity,scale] motion-safe:duration-200',
350
354
  'data-starting-style:motion-safe:scale-90 data-starting-style:motion-safe:opacity-0',
351
355
  'data-ending-style:motion-safe:scale-95 data-ending-style:motion-safe:opacity-0 data-ending-style:motion-safe:duration-100 data-ending-style:motion-safe:ease-out',
352
356
  className,
@@ -454,7 +458,7 @@ function ComboboxItem({ className, children, ...props }: ComboboxItemProps) {
454
458
  'before:bg-background-muted before:absolute before:inset-0 before:-z-10 before:rounded-[inherit] before:opacity-0',
455
459
  'active:translate-y-px active:scale-[0.98]',
456
460
  'data-highlighted:not-data-disabled:text-foreground-intense data-highlighted:not-data-disabled:before:opacity-100',
457
- 'motion-safe:transition motion-safe:duration-250 motion-safe:ease-[cubic-bezier(0.175,0.885,0.32,1.5)]',
461
+ 'motion-safe:ease-spring motion-safe:transition motion-safe:duration-250',
458
462
  'motion-safe:active:duration-100 motion-safe:active:ease-in-out',
459
463
  'motion-safe:before:transition-opacity motion-safe:before:duration-200 motion-safe:before:ease-out',
460
464
  'data-disabled:opacity-disabled data-disabled:pointer-events-none',
@@ -488,11 +492,7 @@ function ComboboxEmpty({ className, ...props }: ComboboxEmptyProps) {
488
492
  return (
489
493
  <BaseCombobox.Empty
490
494
  data-slot="combobox-empty"
491
- className={cn(
492
- 'text-foreground-muted hidden text-center group-data-empty/combobox-content:block',
493
- EMPTY_SIZE[size],
494
- className,
495
- )}
495
+ className={cn('text-foreground-muted text-center empty:p-0', EMPTY_SIZE[size], className)}
496
496
  {...props}
497
497
  />
498
498
  )
@@ -588,6 +588,8 @@ function ClearIcon(props: IconProps) {
588
588
  )
589
589
  }
590
590
 
591
+ const createComboboxItems = BaseCombobox.createItems
592
+
591
593
  export {
592
594
  Combobox,
593
595
  ComboboxInput,
@@ -603,6 +605,7 @@ export {
603
605
  ComboboxLabel,
604
606
  ComboboxCollection,
605
607
  ComboboxSeparator,
608
+ createComboboxItems,
606
609
  }
607
610
  export type {
608
611
  ComboboxProps,