@appica/ui-react 1.1.0 → 1.3.0
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.
- package/CHANGELOG.md +62 -14
- package/README.md +1 -1
- package/agent-rules.md +2 -2
- package/appica.css +1 -1
- package/dist/components/accordion/accordion.js +1 -0
- package/dist/components/accordion/accordion.js.map +1 -1
- package/dist/components/alert/alert.d.ts +1 -1
- package/dist/components/alert/alert.js +1 -0
- package/dist/components/alert/alert.js.map +1 -1
- package/dist/components/alert-dialog/alert-dialog.js +2 -1
- package/dist/components/alert-dialog/alert-dialog.js.map +1 -1
- package/dist/components/autocomplete/autocomplete.js +3 -2
- package/dist/components/autocomplete/autocomplete.js.map +1 -1
- package/dist/components/avatar/avatar.d.ts +1 -1
- package/dist/components/avatar/avatar.js +1 -0
- package/dist/components/avatar/avatar.js.map +1 -1
- package/dist/components/background-pattern/background-pattern-interactive.d.ts +2 -1
- package/dist/components/background-pattern/background-pattern-interactive.d.ts.map +1 -1
- package/dist/components/background-pattern/background-pattern-interactive.js +3 -1
- package/dist/components/background-pattern/background-pattern-interactive.js.map +1 -1
- package/dist/components/background-pattern/background-pattern-shared.d.ts +3 -2
- package/dist/components/background-pattern/background-pattern-shared.d.ts.map +1 -1
- package/dist/components/background-pattern/background-pattern-shared.js +47 -15
- package/dist/components/background-pattern/background-pattern-shared.js.map +1 -1
- package/dist/components/background-pattern/background-pattern.d.ts +1 -1
- package/dist/components/background-pattern/background-pattern.d.ts.map +1 -1
- package/dist/components/background-pattern/background-pattern.js +12 -3
- package/dist/components/background-pattern/background-pattern.js.map +1 -1
- package/dist/components/background-pattern/index.js +1 -0
- package/dist/components/background-pattern/index.js.map +1 -1
- package/dist/components/badge/badge.d.ts +2 -2
- package/dist/components/badge/badge.js +2 -1
- package/dist/components/badge/badge.js.map +1 -1
- package/dist/components/border-beam/border-beam.js +1 -0
- package/dist/components/border-beam/border-beam.js.map +1 -1
- package/dist/components/breadcrumb/breadcrumb.js +2 -1
- package/dist/components/breadcrumb/breadcrumb.js.map +1 -1
- package/dist/components/button/button-variants.d.ts +2 -2
- package/dist/components/button/button-variants.js +2 -1
- package/dist/components/button/button-variants.js.map +1 -1
- package/dist/components/button/button.js +1 -0
- package/dist/components/button/button.js.map +1 -1
- package/dist/components/button/index.js +1 -0
- package/dist/components/button/index.js.map +1 -1
- package/dist/components/button-group/button-group-context.js +1 -0
- package/dist/components/button-group/button-group-context.js.map +1 -1
- package/dist/components/button-group/button-group.js +1 -0
- package/dist/components/button-group/button-group.js.map +1 -1
- package/dist/components/calendar/calendar.js +2 -1
- package/dist/components/calendar/calendar.js.map +1 -1
- package/dist/components/card/card.js +2 -1
- package/dist/components/card/card.js.map +1 -1
- package/dist/components/carousel/carousel.d.ts +3 -11
- package/dist/components/carousel/carousel.d.ts.map +1 -1
- package/dist/components/carousel/carousel.js +25 -1
- package/dist/components/carousel/carousel.js.map +1 -1
- package/dist/components/checkbox/checkbox.js +1 -0
- package/dist/components/checkbox/checkbox.js.map +1 -1
- package/dist/components/checkbox-group/checkbox-group.js +1 -0
- package/dist/components/checkbox-group/checkbox-group.js.map +1 -1
- package/dist/components/chip/chip.d.ts +1 -1
- package/dist/components/chip/chip.js +1 -0
- package/dist/components/chip/chip.js.map +1 -1
- package/dist/components/collapsible/collapsible.js +1 -0
- package/dist/components/collapsible/collapsible.js.map +1 -1
- package/dist/components/color-area/color-area.d.ts.map +1 -1
- package/dist/components/color-area/color-area.js +2 -0
- package/dist/components/color-area/color-area.js.map +1 -1
- package/dist/components/color-picker/color-picker.js +1 -0
- package/dist/components/color-picker/color-picker.js.map +1 -1
- package/dist/components/color-slider/color-slider.d.ts.map +1 -1
- package/dist/components/color-slider/color-slider.js +2 -0
- package/dist/components/color-slider/color-slider.js.map +1 -1
- package/dist/components/color-swatch/color-swatch.d.ts +1 -1
- package/dist/components/color-swatch/color-swatch.js +1 -0
- package/dist/components/color-swatch/color-swatch.js.map +1 -1
- package/dist/components/color-swatch-picker/color-swatch-picker.d.ts +1 -1
- package/dist/components/color-swatch-picker/color-swatch-picker.js +2 -1
- package/dist/components/color-swatch-picker/color-swatch-picker.js.map +1 -1
- package/dist/components/combobox/combobox.d.ts +5 -4
- package/dist/components/combobox/combobox.d.ts.map +1 -1
- package/dist/components/combobox/combobox.js +5 -3
- package/dist/components/combobox/combobox.js.map +1 -1
- package/dist/components/compare-slider/compare-slider.d.ts +50 -0
- package/dist/components/compare-slider/compare-slider.d.ts.map +1 -0
- package/dist/components/compare-slider/compare-slider.js +321 -0
- package/dist/components/compare-slider/compare-slider.js.map +1 -0
- package/dist/components/context-menu/context-menu.d.ts.map +1 -1
- package/dist/components/context-menu/context-menu.js +7 -1
- package/dist/components/context-menu/context-menu.js.map +1 -1
- package/dist/components/copy-button/copy-button.d.ts +3 -1
- package/dist/components/copy-button/copy-button.d.ts.map +1 -1
- package/dist/components/copy-button/copy-button.js +5 -4
- package/dist/components/copy-button/copy-button.js.map +1 -1
- package/dist/components/countdown/countdown.js +1 -0
- package/dist/components/countdown/countdown.js.map +1 -1
- package/dist/components/date-field/date-field.js +1 -0
- package/dist/components/date-field/date-field.js.map +1 -1
- package/dist/components/date-picker/date-picker.js +1 -0
- package/dist/components/date-picker/date-picker.js.map +1 -1
- package/dist/components/dialog/dialog.js +2 -1
- package/dist/components/dialog/dialog.js.map +1 -1
- package/dist/components/drawer/drawer.js +1 -0
- package/dist/components/drawer/drawer.js.map +1 -1
- package/dist/components/dropdown-menu/dropdown-menu.d.ts +13 -2
- package/dist/components/dropdown-menu/dropdown-menu.d.ts.map +1 -1
- package/dist/components/dropdown-menu/dropdown-menu.js +115 -4
- package/dist/components/dropdown-menu/dropdown-menu.js.map +1 -1
- package/dist/components/field/field.js +1 -0
- package/dist/components/field/field.js.map +1 -1
- package/dist/components/fieldset/fieldset.js +1 -0
- package/dist/components/fieldset/fieldset.js.map +1 -1
- package/dist/components/form/form.js +1 -0
- package/dist/components/form/form.js.map +1 -1
- package/dist/components/gradient-glow/gradient-glow.d.ts +6 -1
- package/dist/components/gradient-glow/gradient-glow.d.ts.map +1 -1
- package/dist/components/gradient-glow/gradient-glow.js +4 -2
- package/dist/components/gradient-glow/gradient-glow.js.map +1 -1
- package/dist/components/input/index.js +1 -0
- package/dist/components/input/index.js.map +1 -1
- package/dist/components/input/input-variants.d.ts +1 -1
- package/dist/components/input/input-variants.js +1 -0
- package/dist/components/input/input-variants.js.map +1 -1
- package/dist/components/input/input.js +1 -0
- package/dist/components/input/input.js.map +1 -1
- package/dist/components/kbd/kbd.js +1 -0
- package/dist/components/kbd/kbd.js.map +1 -1
- package/dist/components/loader/loader.js +1 -0
- package/dist/components/loader/loader.js.map +1 -1
- package/dist/components/menubar/menubar.js +1 -0
- package/dist/components/menubar/menubar.js.map +1 -1
- package/dist/components/meter/meter.js +1 -0
- package/dist/components/meter/meter.js.map +1 -1
- package/dist/components/navigation/index.js +1 -0
- package/dist/components/navigation/index.js.map +1 -1
- package/dist/components/navigation/navigation-context.js +1 -0
- package/dist/components/navigation/navigation-context.js.map +1 -1
- package/dist/components/navigation/navigation-link-variants.d.ts +2 -2
- package/dist/components/navigation/navigation-link-variants.js +2 -1
- package/dist/components/navigation/navigation-link-variants.js.map +1 -1
- package/dist/components/navigation/navigation-link.js +1 -0
- package/dist/components/navigation/navigation-link.js.map +1 -1
- package/dist/components/navigation/navigation.js +1 -0
- package/dist/components/navigation/navigation.js.map +1 -1
- package/dist/components/navigation-menu/navigation-menu.js +2 -1
- package/dist/components/navigation-menu/navigation-menu.js.map +1 -1
- package/dist/components/number-field/number-field.js +1 -0
- package/dist/components/number-field/number-field.js.map +1 -1
- package/dist/components/otp-field/otp-field.js +1 -0
- package/dist/components/otp-field/otp-field.js.map +1 -1
- package/dist/components/pagination/pagination.js +1 -0
- package/dist/components/pagination/pagination.js.map +1 -1
- package/dist/components/popover/popover.js +2 -1
- package/dist/components/popover/popover.js.map +1 -1
- package/dist/components/preview-card/preview-card.js +2 -1
- package/dist/components/preview-card/preview-card.js.map +1 -1
- package/dist/components/progress/progress.js +1 -0
- package/dist/components/progress/progress.js.map +1 -1
- package/dist/components/radio/radio.js +1 -0
- package/dist/components/radio/radio.js.map +1 -1
- package/dist/components/radio-group/radio-group.js +1 -0
- package/dist/components/radio-group/radio-group.js.map +1 -1
- package/dist/components/rating/rating.js +1 -0
- package/dist/components/rating/rating.js.map +1 -1
- package/dist/components/scroll-area/scroll-area.js +1 -0
- package/dist/components/scroll-area/scroll-area.js.map +1 -1
- package/dist/components/select/select.js +3 -2
- package/dist/components/select/select.js.map +1 -1
- package/dist/components/separator/separator.js +1 -0
- package/dist/components/separator/separator.js.map +1 -1
- package/dist/components/skeleton/skeleton.js +1 -0
- package/dist/components/skeleton/skeleton.js.map +1 -1
- package/dist/components/slider/slider.d.ts.map +1 -1
- package/dist/components/slider/slider.js +3 -1
- package/dist/components/slider/slider.js.map +1 -1
- package/dist/components/sparkline/sparkline.d.ts.map +1 -1
- package/dist/components/sparkline/sparkline.js +2 -0
- package/dist/components/sparkline/sparkline.js.map +1 -1
- package/dist/components/spinner/spinner.js +1 -0
- package/dist/components/spinner/spinner.js.map +1 -1
- package/dist/components/switch/switch.d.ts +15 -15
- package/dist/components/switch/switch.d.ts.map +1 -1
- package/dist/components/switch/switch.js +1 -0
- package/dist/components/switch/switch.js.map +1 -1
- package/dist/components/table/table.js +1 -0
- package/dist/components/table/table.js.map +1 -1
- package/dist/components/tabs/tabs.d.ts +1 -1
- package/dist/components/tabs/tabs.js +2 -1
- package/dist/components/tabs/tabs.js.map +1 -1
- package/dist/components/text-animate/text-animate.js +1 -0
- package/dist/components/text-animate/text-animate.js.map +1 -1
- package/dist/components/textarea/textarea.js +1 -0
- package/dist/components/textarea/textarea.js.map +1 -1
- package/dist/components/thumbnail/thumbnail.d.ts +8 -3
- package/dist/components/thumbnail/thumbnail.d.ts.map +1 -1
- package/dist/components/thumbnail/thumbnail.js +3 -0
- package/dist/components/thumbnail/thumbnail.js.map +1 -1
- package/dist/components/time-field/time-field.js +1 -0
- package/dist/components/time-field/time-field.js.map +1 -1
- package/dist/components/toast/toast.js +1 -0
- package/dist/components/toast/toast.js.map +1 -1
- package/dist/components/toc/toc.js +1 -0
- package/dist/components/toc/toc.js.map +1 -1
- package/dist/components/toggle/toggle.js +1 -0
- package/dist/components/toggle/toggle.js.map +1 -1
- package/dist/components/toggle-group/toggle-group.js +1 -0
- package/dist/components/toggle-group/toggle-group.js.map +1 -1
- package/dist/components/toolbar/toolbar.js +1 -0
- package/dist/components/toolbar/toolbar.js.map +1 -1
- package/dist/components/tooltip/tooltip.js +2 -1
- package/dist/components/tooltip/tooltip.js.map +1 -1
- package/dist/hooks/use-direction.js +1 -0
- package/dist/hooks/use-direction.js.map +1 -1
- package/dist/hooks/use-dismissible.js +1 -0
- package/dist/hooks/use-dismissible.js.map +1 -1
- package/dist/hooks/use-local-storage.js +1 -0
- package/dist/hooks/use-local-storage.js.map +1 -1
- package/dist/hooks/use-media-query.d.ts +0 -4
- package/dist/hooks/use-media-query.d.ts.map +1 -1
- package/dist/hooks/use-media-query.js +1 -0
- package/dist/hooks/use-media-query.js.map +1 -1
- package/dist/hooks/use-reduced-motion.js +1 -0
- package/dist/hooks/use-reduced-motion.js.map +1 -1
- package/dist/hooks/use-theme.js +1 -0
- package/dist/hooks/use-theme.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/internal/color-control.d.ts +9 -9
- package/dist/internal/color-control.d.ts.map +1 -1
- package/dist/internal/color-control.js +1 -0
- package/dist/internal/color-control.js.map +1 -1
- package/dist/internal/color-math.js +1 -0
- package/dist/internal/color-math.js.map +1 -1
- package/dist/internal/color-picker-context.js +1 -0
- package/dist/internal/color-picker-context.js.map +1 -1
- package/dist/internal/floating.d.ts +2 -2
- package/dist/internal/floating.d.ts.map +1 -1
- package/dist/internal/floating.js +1 -0
- package/dist/internal/floating.js.map +1 -1
- package/dist/internal/modal.d.ts +1 -1
- package/dist/internal/modal.d.ts.map +1 -1
- package/dist/internal/modal.js +1 -0
- package/dist/internal/modal.js.map +1 -1
- package/dist/internal/utils.d.ts +2 -2
- package/dist/internal/utils.d.ts.map +1 -1
- package/dist/internal/utils.js +3 -1
- package/dist/internal/utils.js.map +1 -1
- package/dist/lib/color.js +1 -0
- package/dist/lib/color.js.map +1 -1
- package/dist/providers/direction-provider.js +1 -0
- package/dist/providers/direction-provider.js.map +1 -1
- package/dist/providers/reduced-motion-provider.js +1 -0
- package/dist/providers/reduced-motion-provider.js.map +1 -1
- package/dist/providers/theme-provider/index.js +1 -0
- package/dist/providers/theme-provider/index.js.map +1 -1
- package/dist/providers/theme-provider/theme-provider.js +1 -0
- package/dist/providers/theme-provider/theme-provider.js.map +1 -1
- package/dist/providers/theme-provider/theme-script.js +1 -0
- package/dist/providers/theme-provider/theme-script.js.map +1 -1
- package/package.json +36 -29
- package/src/components/alert-dialog/alert-dialog.tsx +1 -1
- package/src/components/autocomplete/autocomplete.tsx +2 -2
- package/src/components/background-pattern/background-pattern-interactive.tsx +3 -1
- package/src/components/background-pattern/background-pattern-shared.tsx +55 -18
- package/src/components/background-pattern/background-pattern.test.tsx +35 -0
- package/src/components/background-pattern/background-pattern.tsx +11 -4
- package/src/components/badge/badge.tsx +1 -1
- package/src/components/breadcrumb/breadcrumb.tsx +1 -1
- package/src/components/button/button-variants.ts +1 -1
- package/src/components/calendar/calendar.tsx +1 -1
- package/src/components/card/card.tsx +1 -1
- package/src/components/carousel/carousel.test.tsx +38 -0
- package/src/components/carousel/carousel.tsx +28 -12
- package/src/components/color-area/color-area.test.tsx +5 -0
- package/src/components/color-area/color-area.tsx +1 -0
- package/src/components/color-slider/color-slider.test.tsx +5 -0
- package/src/components/color-slider/color-slider.tsx +1 -0
- package/src/components/color-swatch-picker/color-swatch-picker.tsx +1 -1
- package/src/components/combobox/combobox.test.tsx +33 -0
- package/src/components/combobox/combobox.tsx +13 -6
- package/src/components/compare-slider/compare-slider.test.tsx +261 -0
- package/src/components/compare-slider/compare-slider.tsx +397 -0
- package/src/components/context-menu/context-menu.test.tsx +28 -0
- package/src/components/context-menu/context-menu.tsx +6 -1
- package/src/components/copy-button/copy-button.test.tsx +13 -0
- package/src/components/copy-button/copy-button.tsx +11 -5
- package/src/components/dialog/dialog.tsx +1 -1
- package/src/components/dropdown-menu/dropdown-menu.test.tsx +216 -0
- package/src/components/dropdown-menu/dropdown-menu.tsx +134 -3
- package/src/components/gradient-glow/gradient-glow.test.tsx +6 -0
- package/src/components/gradient-glow/gradient-glow.tsx +18 -10
- package/src/components/navigation/navigation-link-variants.ts +1 -1
- package/src/components/navigation-menu/navigation-menu.tsx +2 -2
- package/src/components/popover/popover.tsx +1 -1
- package/src/components/preview-card/preview-card.tsx +1 -1
- package/src/components/select/select.tsx +2 -2
- package/src/components/slider/slider.test.tsx +5 -0
- package/src/components/slider/slider.tsx +2 -1
- package/src/components/sparkline/sparkline.test.tsx +16 -0
- package/src/components/sparkline/sparkline.tsx +1 -0
- package/src/components/tabs/tabs.tsx +1 -1
- package/src/components/thumbnail/thumbnail.test.tsx +8 -0
- package/src/components/thumbnail/thumbnail.tsx +7 -0
- package/src/components/tooltip/tooltip.tsx +1 -1
- package/src/hooks/use-media-query.ts +0 -4
- package/src/index.ts +1 -0
- package/src/internal/utils.test.tsx +8 -1
- package/src/internal/utils.ts +4 -1
- package/styles.css +4 -0
|
@@ -93,8 +93,8 @@ interface CarouselProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'onS
|
|
|
93
93
|
* @default 'trimSnaps'
|
|
94
94
|
*/
|
|
95
95
|
containScroll?: false | 'trimSnaps' | 'keepSnaps'
|
|
96
|
-
/** Release snap points
|
|
97
|
-
dragFree?: boolean
|
|
96
|
+
/** Release snap points and glide to a momentum stop. `'snap'` glides, then settles on the nearest snap point. */
|
|
97
|
+
dragFree?: boolean | 'snap'
|
|
98
98
|
/** Index of the slide to start on. */
|
|
99
99
|
startSnap?: number
|
|
100
100
|
/**
|
|
@@ -103,7 +103,7 @@ interface CarouselProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'onS
|
|
|
103
103
|
*/
|
|
104
104
|
active?: boolean
|
|
105
105
|
/**
|
|
106
|
-
* Whether pointer dragging is enabled
|
|
106
|
+
* Whether pointer dragging is enabled.
|
|
107
107
|
* @default true
|
|
108
108
|
*/
|
|
109
109
|
draggable?: boolean
|
|
@@ -294,8 +294,10 @@ function Carousel({
|
|
|
294
294
|
emblaApi.internalEngine().scrollBody.useDuration(0)
|
|
295
295
|
}
|
|
296
296
|
emblaApi.on('pointerup', snapToTargetInstantly)
|
|
297
|
+
emblaApi.on('scroll', snapToTargetInstantly)
|
|
297
298
|
return () => {
|
|
298
299
|
emblaApi.off('pointerup', snapToTargetInstantly)
|
|
300
|
+
emblaApi.off('scroll', snapToTargetInstantly)
|
|
299
301
|
}
|
|
300
302
|
}, [emblaApi, reducedMotion])
|
|
301
303
|
|
|
@@ -451,6 +453,26 @@ function Carousel({
|
|
|
451
453
|
}
|
|
452
454
|
}
|
|
453
455
|
|
|
456
|
+
let cleanupWheel: (() => void) | undefined
|
|
457
|
+
if (emblaApi.plugins().wheelGestures && (autoplayPlugin || autoScrollPlugin)) {
|
|
458
|
+
const viewport = emblaApi.rootNode()
|
|
459
|
+
const vertical = emblaApi.internalEngine().options.axis === 'y'
|
|
460
|
+
const onWheel = (event: WheelEvent) => {
|
|
461
|
+
const along = Math.abs(vertical ? event.deltaY : event.deltaX)
|
|
462
|
+
const across = Math.abs(vertical ? event.deltaX : event.deltaY)
|
|
463
|
+
if (along <= across) return
|
|
464
|
+
if (autoplayPlugin?.isPlaying()) {
|
|
465
|
+
autoplayPlugin.stop()
|
|
466
|
+
scheduleResume(() => emblaApi.plugins().autoplay?.play())
|
|
467
|
+
} else if (autoScrollPlugin?.isPlaying()) {
|
|
468
|
+
autoScrollPlugin.stop()
|
|
469
|
+
scheduleResume(() => emblaApi.plugins().autoScroll?.play())
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
viewport.addEventListener('wheel', onWheel, { passive: true })
|
|
473
|
+
cleanupWheel = () => viewport.removeEventListener('wheel', onWheel)
|
|
474
|
+
}
|
|
475
|
+
|
|
454
476
|
return () => {
|
|
455
477
|
emblaApi.off('reinit', handleReInit)
|
|
456
478
|
emblaApi.off('select', handleSelect)
|
|
@@ -459,6 +481,7 @@ function Carousel({
|
|
|
459
481
|
emblaApi.off('slideschanged', syncFull)
|
|
460
482
|
cleanupAutoplay?.()
|
|
461
483
|
cleanupAutoScroll?.()
|
|
484
|
+
cleanupWheel?.()
|
|
462
485
|
clearResumeTimer()
|
|
463
486
|
}
|
|
464
487
|
}, [emblaApi, autoplayEnabled, autoScrollEnabled, resumeAfterMs])
|
|
@@ -534,6 +557,7 @@ function CarouselContent({ className, children, viewportProps, ...rest }: Carous
|
|
|
534
557
|
const { viewportRef, orientation, autoHeight } = useCarousel()
|
|
535
558
|
return (
|
|
536
559
|
<div
|
|
560
|
+
data-base-ui-swipe-ignore={orientation === 'vertical' ? 'y' : 'x'}
|
|
537
561
|
{...viewportProps}
|
|
538
562
|
ref={viewportRef}
|
|
539
563
|
data-slot="carousel-viewport"
|
|
@@ -618,7 +642,7 @@ const CAROUSEL_THUMB_OPTIONS: CarouselOptions = { slides: ':scope > [data-slot=c
|
|
|
618
642
|
const CAROUSEL_THUMB_TRANSITION = cn(
|
|
619
643
|
'transition-[opacity,translate,scale] motion-reduce:transition-none',
|
|
620
644
|
'duration-[300ms,250ms,250ms]',
|
|
621
|
-
'ease-[ease-out,
|
|
645
|
+
'ease-[ease-out,var(--ease-spring),var(--ease-spring)]',
|
|
622
646
|
'active:duration-[300ms,100ms,100ms] active:ease-[ease-out,ease-in-out,ease-in-out]',
|
|
623
647
|
)
|
|
624
648
|
|
|
@@ -1239,14 +1263,6 @@ function CarouselAutoplayCircularIndicator({
|
|
|
1239
1263
|
* "main + thumbnails" pattern. Wires `select` on each so navigating either
|
|
1240
1264
|
* one drives the other. Both apis can be undefined initially (e.g. waiting on
|
|
1241
1265
|
* `setApi`); the effect re-runs once both resolve.
|
|
1242
|
-
*
|
|
1243
|
-
* @example
|
|
1244
|
-
* const [mainApi, setMainApi] = useState<CarouselApi>()
|
|
1245
|
-
* const [thumbsApi, setThumbsApi] = useState<CarouselApi>()
|
|
1246
|
-
* useLinkedCarousels(mainApi, thumbsApi)
|
|
1247
|
-
*
|
|
1248
|
-
* <Carousel setApi={setMainApi}>…</Carousel>
|
|
1249
|
-
* <Carousel setApi={setThumbsApi} align="start" containScroll="keepSnaps">…</Carousel>
|
|
1250
1266
|
*/
|
|
1251
1267
|
function useLinkedCarousels(mainApi: CarouselApi | undefined, thumbsApi: CarouselApi | undefined): void {
|
|
1252
1268
|
React.useEffect(() => {
|
|
@@ -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()
|
|
@@ -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')
|
|
@@ -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-
|
|
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' })
|
|
@@ -30,9 +30,13 @@ function useComboboxContext() {
|
|
|
30
30
|
return ctx
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
type
|
|
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
|
|
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
|
|
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:
|
|
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',
|
|
@@ -588,6 +592,8 @@ function ClearIcon(props: IconProps) {
|
|
|
588
592
|
)
|
|
589
593
|
}
|
|
590
594
|
|
|
595
|
+
const createComboboxItems = BaseCombobox.createItems
|
|
596
|
+
|
|
591
597
|
export {
|
|
592
598
|
Combobox,
|
|
593
599
|
ComboboxInput,
|
|
@@ -603,6 +609,7 @@ export {
|
|
|
603
609
|
ComboboxLabel,
|
|
604
610
|
ComboboxCollection,
|
|
605
611
|
ComboboxSeparator,
|
|
612
|
+
createComboboxItems,
|
|
606
613
|
}
|
|
607
614
|
export type {
|
|
608
615
|
ComboboxProps,
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { act, fireEvent, render, screen, within } from '@testing-library/react'
|
|
3
|
+
import userEvent from '@testing-library/user-event'
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
import { axe } from 'vitest-axe'
|
|
6
|
+
import { CompareSlider, type CompareSliderProps } from './compare-slider'
|
|
7
|
+
import { DirectionProvider } from '../../providers/direction-provider'
|
|
8
|
+
|
|
9
|
+
const RECT = { x: 0, y: 0, top: 0, left: 0, right: 200, bottom: 100, width: 200, height: 100 }
|
|
10
|
+
|
|
11
|
+
function stubSize() {
|
|
12
|
+
vi.spyOn(HTMLDivElement.prototype, 'getBoundingClientRect').mockImplementation(
|
|
13
|
+
() => ({ ...RECT, toJSON: () => RECT }) as DOMRect,
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class MockIntersectionObserver {
|
|
18
|
+
static instances: MockIntersectionObserver[] = []
|
|
19
|
+
callback: IntersectionObserverCallback
|
|
20
|
+
constructor(callback: IntersectionObserverCallback) {
|
|
21
|
+
this.callback = callback
|
|
22
|
+
MockIntersectionObserver.instances.push(this)
|
|
23
|
+
}
|
|
24
|
+
observe = () => {}
|
|
25
|
+
unobserve = () => {}
|
|
26
|
+
disconnect = () => {}
|
|
27
|
+
takeRecords = () => []
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function renderSlider(props: Partial<CompareSliderProps> = {}) {
|
|
31
|
+
return render(
|
|
32
|
+
<CompareSlider
|
|
33
|
+
data-testid="root"
|
|
34
|
+
aria-label="Compare the sketch with the room"
|
|
35
|
+
before={<img alt="Sketch" src="/sketch.png" />}
|
|
36
|
+
after={<img alt="Room" src="/room.jpg" />}
|
|
37
|
+
{...props}
|
|
38
|
+
/>,
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const slider = () => screen.getByRole('slider') as HTMLInputElement
|
|
43
|
+
const root = () => screen.getByTestId('root')
|
|
44
|
+
const layer = (side: 'before' | 'after') => root().querySelector(`[data-slot="compare-slider-${side}"]`) as HTMLElement
|
|
45
|
+
|
|
46
|
+
afterEach(() => {
|
|
47
|
+
vi.restoreAllMocks()
|
|
48
|
+
vi.unstubAllGlobals()
|
|
49
|
+
MockIntersectionObserver.instances = []
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
describe('CompareSlider', () => {
|
|
53
|
+
it('renders both layers around a labeled slider set to 50', () => {
|
|
54
|
+
renderSlider()
|
|
55
|
+
expect(screen.getByRole('img', { name: 'Sketch' })).toBeInTheDocument()
|
|
56
|
+
expect(screen.getByRole('img', { name: 'Room' })).toBeInTheDocument()
|
|
57
|
+
expect(slider()).toHaveAccessibleName('Compare the sketch with the room')
|
|
58
|
+
expect(slider()).toHaveValue('50')
|
|
59
|
+
expect(root()).toHaveAttribute('data-orientation', 'horizontal')
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('clips each layer to its side of the divider, starting at defaultValue', () => {
|
|
63
|
+
renderSlider({ defaultValue: 30 })
|
|
64
|
+
expect(slider()).toHaveValue('30')
|
|
65
|
+
expect(layer('before').style.clipPath).toBe('inset(0 70% 0 0)')
|
|
66
|
+
expect(layer('after').style.clipPath).toBe('inset(0 0 0 30%)')
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('puts before on the right in a right-to-left layout', () => {
|
|
70
|
+
render(
|
|
71
|
+
<DirectionProvider dir="rtl">
|
|
72
|
+
<CompareSlider data-testid="root" aria-label="Compare" defaultValue={30} before="Before" after="After" />
|
|
73
|
+
</DirectionProvider>,
|
|
74
|
+
)
|
|
75
|
+
expect(layer('before').style.clipPath).toBe('inset(0 0 0 70%)')
|
|
76
|
+
expect(layer('after').style.clipPath).toBe('inset(0 30% 0 0)')
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('stacks before above after when vertical', () => {
|
|
80
|
+
renderSlider({ orientation: 'vertical', defaultValue: 30 })
|
|
81
|
+
expect(root()).toHaveAttribute('data-orientation', 'vertical')
|
|
82
|
+
expect(slider()).toHaveAttribute('aria-orientation', 'vertical')
|
|
83
|
+
expect(layer('before').style.clipPath).toBe('inset(0 0 70% 0)')
|
|
84
|
+
expect(layer('after').style.clipPath).toBe('inset(30% 0 0 0)')
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('moves the divider to a mouse press, follows the drag and commits on release', async () => {
|
|
88
|
+
stubSize()
|
|
89
|
+
const onValueChange = vi.fn()
|
|
90
|
+
const onValueCommitted = vi.fn()
|
|
91
|
+
const user = userEvent.setup()
|
|
92
|
+
renderSlider({ onValueChange, onValueCommitted })
|
|
93
|
+
|
|
94
|
+
await user.pointer([
|
|
95
|
+
{ keys: '[MouseLeft>]', target: root(), coords: { clientX: 50, clientY: 50 } },
|
|
96
|
+
{ target: root(), coords: { clientX: 150, clientY: 50 } },
|
|
97
|
+
])
|
|
98
|
+
expect(onValueChange).toHaveBeenNthCalledWith(1, 25)
|
|
99
|
+
expect(slider()).toHaveValue('75')
|
|
100
|
+
expect(root()).toHaveAttribute('data-dragging')
|
|
101
|
+
expect(onValueCommitted).not.toHaveBeenCalled()
|
|
102
|
+
|
|
103
|
+
await user.pointer({ keys: '[/MouseLeft]', target: root() })
|
|
104
|
+
expect(onValueCommitted).toHaveBeenCalledExactlyOnceWith(75)
|
|
105
|
+
expect(root()).not.toHaveAttribute('data-dragging')
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('leaves a touch swipe across the axis to the page, and follows one along it', async () => {
|
|
109
|
+
stubSize()
|
|
110
|
+
const user = userEvent.setup()
|
|
111
|
+
renderSlider()
|
|
112
|
+
|
|
113
|
+
await user.pointer([
|
|
114
|
+
{ keys: '[TouchA>]', target: root(), coords: { clientX: 100, clientY: 10 } },
|
|
115
|
+
{ pointerName: 'TouchA', target: root(), coords: { clientX: 104, clientY: 60 } },
|
|
116
|
+
{ keys: '[/TouchA]', target: root() },
|
|
117
|
+
])
|
|
118
|
+
expect(slider()).toHaveValue('50')
|
|
119
|
+
|
|
120
|
+
await user.pointer([
|
|
121
|
+
{ keys: '[TouchA>]', target: root(), coords: { clientX: 100, clientY: 50 } },
|
|
122
|
+
{ pointerName: 'TouchA', target: root(), coords: { clientX: 60, clientY: 52 } },
|
|
123
|
+
{ pointerName: 'TouchA', target: root(), coords: { clientX: 40, clientY: 52 } },
|
|
124
|
+
{ keys: '[/TouchA]', target: root() },
|
|
125
|
+
])
|
|
126
|
+
expect(slider()).toHaveValue('20')
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('moves the divider to a tap, but not to a touch the page takes over for scrolling', async () => {
|
|
130
|
+
stubSize()
|
|
131
|
+
const onValueCommitted = vi.fn()
|
|
132
|
+
const user = userEvent.setup()
|
|
133
|
+
renderSlider({ onValueCommitted })
|
|
134
|
+
|
|
135
|
+
await user.pointer({ keys: '[TouchA]', target: root(), coords: { clientX: 40, clientY: 50 } })
|
|
136
|
+
expect(slider()).toHaveValue('20')
|
|
137
|
+
expect(onValueCommitted).toHaveBeenCalledExactlyOnceWith(20)
|
|
138
|
+
|
|
139
|
+
fireEvent.pointerDown(root(), { pointerType: 'touch', pointerId: 2, clientX: 150, clientY: 50 })
|
|
140
|
+
expect(root()).toHaveAttribute('data-dragging')
|
|
141
|
+
fireEvent.pointerCancel(root(), { pointerType: 'touch', pointerId: 2, clientX: 150, clientY: 50 })
|
|
142
|
+
expect(root()).not.toHaveAttribute('data-dragging')
|
|
143
|
+
expect(slider()).toHaveValue('20')
|
|
144
|
+
expect(onValueCommitted).toHaveBeenCalledTimes(1)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('steps with the arrow keys, by 10 with Shift, and jumps to the ends with Home and End', async () => {
|
|
148
|
+
const onValueCommitted = vi.fn()
|
|
149
|
+
const user = userEvent.setup()
|
|
150
|
+
renderSlider({ onValueCommitted })
|
|
151
|
+
|
|
152
|
+
slider().focus()
|
|
153
|
+
await user.keyboard('{ArrowRight}')
|
|
154
|
+
expect(slider()).toHaveValue('51')
|
|
155
|
+
expect(onValueCommitted).toHaveBeenLastCalledWith(51)
|
|
156
|
+
await user.keyboard('{Shift>}{ArrowLeft}{/Shift}')
|
|
157
|
+
expect(slider()).toHaveValue('41')
|
|
158
|
+
await user.keyboard('{Home}')
|
|
159
|
+
expect(slider()).toHaveValue('0')
|
|
160
|
+
await user.keyboard('{End}')
|
|
161
|
+
expect(slider()).toHaveValue('100')
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
it('moves the divider the way the arrow points, in RTL and when vertical', async () => {
|
|
165
|
+
const user = userEvent.setup()
|
|
166
|
+
const { unmount } = render(
|
|
167
|
+
<DirectionProvider dir="rtl">
|
|
168
|
+
<CompareSlider aria-label="Compare" before="Before" after="After" />
|
|
169
|
+
</DirectionProvider>,
|
|
170
|
+
)
|
|
171
|
+
slider().focus()
|
|
172
|
+
await user.keyboard('{ArrowLeft}')
|
|
173
|
+
expect(slider()).toHaveValue('51')
|
|
174
|
+
unmount()
|
|
175
|
+
|
|
176
|
+
renderSlider({ orientation: 'vertical' })
|
|
177
|
+
slider().focus()
|
|
178
|
+
await user.keyboard('{ArrowDown}')
|
|
179
|
+
expect(slider()).toHaveValue('51')
|
|
180
|
+
await user.keyboard('{ArrowUp}{ArrowUp}')
|
|
181
|
+
expect(slider()).toHaveValue('49')
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
it('reports changes but holds its position while controlled', async () => {
|
|
185
|
+
const onValueChange = vi.fn()
|
|
186
|
+
const user = userEvent.setup()
|
|
187
|
+
const { rerender } = renderSlider({ value: 20, onValueChange })
|
|
188
|
+
|
|
189
|
+
slider().focus()
|
|
190
|
+
await user.keyboard('{ArrowRight}')
|
|
191
|
+
expect(onValueChange).toHaveBeenCalledWith(21)
|
|
192
|
+
expect(slider()).toHaveValue('20')
|
|
193
|
+
|
|
194
|
+
rerender(<CompareSlider aria-label="Compare" value={60} before="Before" after="After" />)
|
|
195
|
+
expect(slider()).toHaveValue('60')
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
it('draws a double arrow that follows orientation, and takes a replacement icon', () => {
|
|
199
|
+
const handlePath = () => root().querySelector('[data-slot="compare-slider-handle"] path')?.getAttribute('d')
|
|
200
|
+
const { rerender } = renderSlider()
|
|
201
|
+
const horizontal = handlePath()
|
|
202
|
+
rerender(<CompareSlider data-testid="root" orientation="vertical" before="Before" after="After" />)
|
|
203
|
+
expect(handlePath()).not.toBe(horizontal)
|
|
204
|
+
|
|
205
|
+
rerender(
|
|
206
|
+
<CompareSlider data-testid="root" icon={<svg data-testid="custom-icon" />} before="Before" after="After" />,
|
|
207
|
+
)
|
|
208
|
+
expect(screen.getByTestId('custom-icon')).toBeInTheDocument()
|
|
209
|
+
expect(root().querySelectorAll('[data-slot="compare-slider-handle"] svg')).toHaveLength(1)
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
it('pins each label inside its own layer, so it clips with that side', () => {
|
|
213
|
+
const { rerender } = renderSlider({ beforeLabel: 'Drawing', afterLabel: 'Photo' })
|
|
214
|
+
expect(within(layer('before')).getByText('Drawing')).toHaveAttribute('data-slot', 'compare-slider-label')
|
|
215
|
+
expect(within(layer('after')).getByText('Photo')).toHaveAttribute('data-slot', 'compare-slider-label')
|
|
216
|
+
|
|
217
|
+
rerender(<CompareSlider data-testid="root" before="Before" after="After" />)
|
|
218
|
+
expect(root().querySelector('[data-slot="compare-slider-label"]')).toBeNull()
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
it('opens on before alone with reveal, then moves to defaultValue once in view', () => {
|
|
222
|
+
vi.stubGlobal('IntersectionObserver', MockIntersectionObserver)
|
|
223
|
+
renderSlider({ reveal: true, defaultValue: 40 })
|
|
224
|
+
expect(slider()).toHaveValue('100')
|
|
225
|
+
expect(layer('after').style.clipPath).toBe('inset(0 0 0 100%)')
|
|
226
|
+
|
|
227
|
+
act(() => {
|
|
228
|
+
MockIntersectionObserver.instances[0]!.callback(
|
|
229
|
+
[{ isIntersecting: true } as IntersectionObserverEntry],
|
|
230
|
+
MockIntersectionObserver.instances[0] as unknown as IntersectionObserver,
|
|
231
|
+
)
|
|
232
|
+
})
|
|
233
|
+
expect(slider()).toHaveValue('40')
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it('ignores presses and keys while disabled', async () => {
|
|
237
|
+
stubSize()
|
|
238
|
+
const onValueChange = vi.fn()
|
|
239
|
+
const user = userEvent.setup()
|
|
240
|
+
renderSlider({ disabled: true, onValueChange })
|
|
241
|
+
|
|
242
|
+
expect(slider()).toBeDisabled()
|
|
243
|
+
expect(root()).toHaveAttribute('data-disabled')
|
|
244
|
+
await user.pointer({ keys: '[MouseLeft]', target: root(), coords: { clientX: 20, clientY: 50 } })
|
|
245
|
+
expect(onValueChange).not.toHaveBeenCalled()
|
|
246
|
+
expect(slider()).toHaveValue('50')
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
it('claims drags along its own axis from a surrounding Drawer', () => {
|
|
250
|
+
const { unmount } = renderSlider()
|
|
251
|
+
expect(root()).toHaveAttribute('data-base-ui-swipe-ignore', 'x')
|
|
252
|
+
unmount()
|
|
253
|
+
renderSlider({ orientation: 'vertical' })
|
|
254
|
+
expect(root()).toHaveAttribute('data-base-ui-swipe-ignore', 'y')
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
it('has no accessibility violations', async () => {
|
|
258
|
+
const { container } = renderSlider({ beforeLabel: 'Drawing', afterLabel: 'Photo' })
|
|
259
|
+
expect(await axe(container)).toHaveNoViolations()
|
|
260
|
+
})
|
|
261
|
+
})
|