@appica/ui-react 1.2.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.
Files changed (116) hide show
  1. package/CHANGELOG.md +37 -15
  2. package/appica.css +1 -1
  3. package/dist/components/alert-dialog/alert-dialog.js +1 -1
  4. package/dist/components/alert-dialog/alert-dialog.js.map +1 -1
  5. package/dist/components/autocomplete/autocomplete.js +2 -2
  6. package/dist/components/autocomplete/autocomplete.js.map +1 -1
  7. package/dist/components/badge/badge.js +1 -1
  8. package/dist/components/badge/badge.js.map +1 -1
  9. package/dist/components/breadcrumb/breadcrumb.js +1 -1
  10. package/dist/components/breadcrumb/breadcrumb.js.map +1 -1
  11. package/dist/components/button/button-variants.js +1 -1
  12. package/dist/components/button/button-variants.js.map +1 -1
  13. package/dist/components/calendar/calendar.js +1 -1
  14. package/dist/components/calendar/calendar.js.map +1 -1
  15. package/dist/components/carousel/carousel.d.ts +0 -8
  16. package/dist/components/carousel/carousel.d.ts.map +1 -1
  17. package/dist/components/carousel/carousel.js +2 -1
  18. package/dist/components/carousel/carousel.js.map +1 -1
  19. package/dist/components/color-area/color-area.d.ts.map +1 -1
  20. package/dist/components/color-area/color-area.js +1 -0
  21. package/dist/components/color-area/color-area.js.map +1 -1
  22. package/dist/components/color-slider/color-slider.d.ts.map +1 -1
  23. package/dist/components/color-slider/color-slider.js +1 -0
  24. package/dist/components/color-slider/color-slider.js.map +1 -1
  25. package/dist/components/color-swatch-picker/color-swatch-picker.js +1 -1
  26. package/dist/components/color-swatch-picker/color-swatch-picker.js.map +1 -1
  27. package/dist/components/combobox/combobox.d.ts +5 -4
  28. package/dist/components/combobox/combobox.d.ts.map +1 -1
  29. package/dist/components/combobox/combobox.js +4 -3
  30. package/dist/components/combobox/combobox.js.map +1 -1
  31. package/dist/components/compare-slider/compare-slider.d.ts +50 -0
  32. package/dist/components/compare-slider/compare-slider.d.ts.map +1 -0
  33. package/dist/components/compare-slider/compare-slider.js +321 -0
  34. package/dist/components/compare-slider/compare-slider.js.map +1 -0
  35. package/dist/components/context-menu/context-menu.js +1 -1
  36. package/dist/components/context-menu/context-menu.js.map +1 -1
  37. package/dist/components/dialog/dialog.js +1 -1
  38. package/dist/components/dialog/dialog.js.map +1 -1
  39. package/dist/components/dropdown-menu/dropdown-menu.d.ts +13 -2
  40. package/dist/components/dropdown-menu/dropdown-menu.d.ts.map +1 -1
  41. package/dist/components/dropdown-menu/dropdown-menu.js +109 -4
  42. package/dist/components/dropdown-menu/dropdown-menu.js.map +1 -1
  43. package/dist/components/navigation/navigation-link-variants.js +1 -1
  44. package/dist/components/navigation/navigation-link-variants.js.map +1 -1
  45. package/dist/components/navigation-menu/navigation-menu.js +1 -1
  46. package/dist/components/navigation-menu/navigation-menu.js.map +1 -1
  47. package/dist/components/popover/popover.js +1 -1
  48. package/dist/components/popover/popover.js.map +1 -1
  49. package/dist/components/preview-card/preview-card.js +1 -1
  50. package/dist/components/preview-card/preview-card.js.map +1 -1
  51. package/dist/components/select/select.js +2 -2
  52. package/dist/components/select/select.js.map +1 -1
  53. package/dist/components/slider/slider.d.ts.map +1 -1
  54. package/dist/components/slider/slider.js +2 -1
  55. package/dist/components/slider/slider.js.map +1 -1
  56. package/dist/components/sparkline/sparkline.d.ts.map +1 -1
  57. package/dist/components/sparkline/sparkline.js +1 -0
  58. package/dist/components/sparkline/sparkline.js.map +1 -1
  59. package/dist/components/tabs/tabs.js +1 -1
  60. package/dist/components/tabs/tabs.js.map +1 -1
  61. package/dist/components/thumbnail/thumbnail.d.ts +6 -1
  62. package/dist/components/thumbnail/thumbnail.d.ts.map +1 -1
  63. package/dist/components/thumbnail/thumbnail.js +2 -0
  64. package/dist/components/thumbnail/thumbnail.js.map +1 -1
  65. package/dist/components/tooltip/tooltip.js +1 -1
  66. package/dist/components/tooltip/tooltip.js.map +1 -1
  67. package/dist/hooks/use-media-query.d.ts +0 -4
  68. package/dist/hooks/use-media-query.d.ts.map +1 -1
  69. package/dist/hooks/use-media-query.js.map +1 -1
  70. package/dist/index.d.ts +1 -0
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +3 -2
  73. package/dist/index.js.map +1 -1
  74. package/dist/internal/utils.d.ts.map +1 -1
  75. package/dist/internal/utils.js +2 -1
  76. package/dist/internal/utils.js.map +1 -1
  77. package/package.json +25 -20
  78. package/src/components/alert-dialog/alert-dialog.tsx +1 -1
  79. package/src/components/autocomplete/autocomplete.tsx +2 -2
  80. package/src/components/badge/badge.tsx +1 -1
  81. package/src/components/breadcrumb/breadcrumb.tsx +1 -1
  82. package/src/components/button/button-variants.ts +1 -1
  83. package/src/components/calendar/calendar.tsx +1 -1
  84. package/src/components/carousel/carousel.test.tsx +14 -0
  85. package/src/components/carousel/carousel.tsx +2 -9
  86. package/src/components/color-area/color-area.test.tsx +5 -0
  87. package/src/components/color-area/color-area.tsx +1 -0
  88. package/src/components/color-slider/color-slider.test.tsx +5 -0
  89. package/src/components/color-slider/color-slider.tsx +1 -0
  90. package/src/components/color-swatch-picker/color-swatch-picker.tsx +1 -1
  91. package/src/components/combobox/combobox.test.tsx +33 -0
  92. package/src/components/combobox/combobox.tsx +13 -6
  93. package/src/components/compare-slider/compare-slider.test.tsx +261 -0
  94. package/src/components/compare-slider/compare-slider.tsx +397 -0
  95. package/src/components/context-menu/context-menu.tsx +1 -1
  96. package/src/components/dialog/dialog.tsx +1 -1
  97. package/src/components/dropdown-menu/dropdown-menu.test.tsx +188 -0
  98. package/src/components/dropdown-menu/dropdown-menu.tsx +129 -3
  99. package/src/components/navigation/navigation-link-variants.ts +1 -1
  100. package/src/components/navigation-menu/navigation-menu.tsx +2 -2
  101. package/src/components/popover/popover.tsx +1 -1
  102. package/src/components/preview-card/preview-card.tsx +1 -1
  103. package/src/components/select/select.tsx +2 -2
  104. package/src/components/slider/slider.test.tsx +5 -0
  105. package/src/components/slider/slider.tsx +2 -1
  106. package/src/components/sparkline/sparkline.test.tsx +16 -0
  107. package/src/components/sparkline/sparkline.tsx +1 -0
  108. package/src/components/tabs/tabs.tsx +1 -1
  109. package/src/components/thumbnail/thumbnail.test.tsx +8 -0
  110. package/src/components/thumbnail/thumbnail.tsx +7 -0
  111. package/src/components/tooltip/tooltip.tsx +1 -1
  112. package/src/hooks/use-media-query.ts +0 -4
  113. package/src/index.ts +1 -0
  114. package/src/internal/utils.test.tsx +8 -1
  115. package/src/internal/utils.ts +4 -1
  116. package/styles.css +4 -0
@@ -7,10 +7,14 @@ import {
7
7
  DropdownMenu,
8
8
  DropdownMenuCheckboxItem,
9
9
  DropdownMenuContent,
10
+ DropdownMenuEmpty,
11
+ DropdownMenuFilterProvider,
10
12
  DropdownMenuGroup,
11
13
  DropdownMenuGroupLabel,
14
+ DropdownMenuInput,
12
15
  DropdownMenuItem,
13
16
  DropdownMenuLinkItem,
17
+ DropdownMenuList,
14
18
  DropdownMenuRadioGroup,
15
19
  DropdownMenuRadioItem,
16
20
  DropdownMenuSeparator,
@@ -252,4 +256,188 @@ describe('DropdownMenu', () => {
252
256
  const { container } = render(<BasicMenu />)
253
257
  expect(await axe(container)).toHaveNoViolations()
254
258
  })
259
+
260
+ it('reports highlight changes through onItemHighlighted', async () => {
261
+ const user = setupUser()
262
+ const onItemHighlighted = vi.fn()
263
+ render(
264
+ <DropdownMenu onItemHighlighted={onItemHighlighted}>
265
+ <DropdownMenuTrigger>Open</DropdownMenuTrigger>
266
+ <DropdownMenuContent>
267
+ <DropdownMenuItem>Profile</DropdownMenuItem>
268
+ <DropdownMenuItem>Settings</DropdownMenuItem>
269
+ </DropdownMenuContent>
270
+ </DropdownMenu>,
271
+ )
272
+ await user.click(screen.getByRole('button', { name: 'Open' }))
273
+ await screen.findByRole('menuitem', { name: 'Profile' })
274
+ await user.keyboard('{ArrowDown}')
275
+ await waitFor(() => {
276
+ expect(onItemHighlighted).toHaveBeenCalledWith(
277
+ screen.getByRole('menuitem', { name: 'Profile' }),
278
+ expect.objectContaining({ reason: 'keyboard', event: expect.any(KeyboardEvent) }),
279
+ )
280
+ })
281
+ })
282
+
283
+ it('List: keeps content beside the list out of the menu role', async () => {
284
+ const user = setupUser()
285
+ render(
286
+ <DropdownMenu>
287
+ <DropdownMenuTrigger>Open</DropdownMenuTrigger>
288
+ <DropdownMenuContent>
289
+ <p>Signed in as Sarah</p>
290
+ <DropdownMenuList>
291
+ <DropdownMenuItem>Profile</DropdownMenuItem>
292
+ </DropdownMenuList>
293
+ </DropdownMenuContent>
294
+ </DropdownMenu>,
295
+ )
296
+ await user.click(screen.getByRole('button', { name: 'Open' }))
297
+ const menu = await screen.findByRole('menu')
298
+ expect(menu).toContainElement(screen.getByRole('menuitem', { name: 'Profile' }))
299
+ expect(menu).not.toContainElement(screen.getByText('Signed in as Sarah'))
300
+ })
301
+ })
302
+
303
+ function FilterMenu({ onDuplicate, autoHighlight }: { onDuplicate?: () => void; autoHighlight?: boolean } = {}) {
304
+ return (
305
+ <DropdownMenuFilterProvider {...(autoHighlight && { autoHighlight })}>
306
+ <DropdownMenu>
307
+ <DropdownMenuTrigger>Actions</DropdownMenuTrigger>
308
+ <DropdownMenuContent>
309
+ <DropdownMenuInput aria-label="Filter actions" placeholder="Filter actions" />
310
+ <DropdownMenuEmpty>No actions found.</DropdownMenuEmpty>
311
+ <DropdownMenuList>
312
+ <DropdownMenuGroup>
313
+ <DropdownMenuGroupLabel>File</DropdownMenuGroupLabel>
314
+ <DropdownMenuItem>Rename</DropdownMenuItem>
315
+ <DropdownMenuItem onClick={onDuplicate}>Duplicate</DropdownMenuItem>
316
+ </DropdownMenuGroup>
317
+ <DropdownMenuSeparator />
318
+ <DropdownMenuGroup data-testid="share-group">
319
+ <DropdownMenuGroupLabel>Share</DropdownMenuGroupLabel>
320
+ <DropdownMenuItem>Copy link</DropdownMenuItem>
321
+ </DropdownMenuGroup>
322
+ </DropdownMenuList>
323
+ </DropdownMenuContent>
324
+ </DropdownMenu>
325
+ </DropdownMenuFilterProvider>
326
+ )
327
+ }
328
+
329
+ describe('DropdownMenu filtering', () => {
330
+ it('focuses the search field when opened with a click', async () => {
331
+ const user = setupUser()
332
+ render(<FilterMenu />)
333
+ await user.click(screen.getByRole('button', { name: 'Actions' }))
334
+ const input = await screen.findByRole('searchbox', { name: 'Filter actions' })
335
+ await waitFor(() => expect(input).toHaveFocus())
336
+ })
337
+
338
+ it('narrows the items to the matches and hides groups left empty', async () => {
339
+ const user = setupUser()
340
+ render(<FilterMenu />)
341
+ await user.click(screen.getByRole('button', { name: 'Actions' }))
342
+ await user.type(await screen.findByRole('searchbox', { name: 'Filter actions' }), 'ren')
343
+ await waitFor(() => {
344
+ expect(screen.getAllByRole('menuitem').map((item) => item.textContent)).toEqual(['Rename'])
345
+ })
346
+ expect(screen.getByTestId('share-group')).not.toBeVisible()
347
+ })
348
+
349
+ it('announces the empty message once nothing matches', async () => {
350
+ const user = setupUser()
351
+ render(<FilterMenu />)
352
+ await user.click(screen.getByRole('button', { name: 'Actions' }))
353
+ expect(screen.queryByText('No actions found.')).toBeNull()
354
+ await user.type(await screen.findByRole('searchbox', { name: 'Filter actions' }), 'zzz')
355
+ expect(await screen.findByRole('status')).toHaveTextContent('No actions found.')
356
+ expect(screen.queryAllByRole('menuitem')).toHaveLength(0)
357
+ })
358
+
359
+ it('selects a match with the keyboard while focus stays in the field', async () => {
360
+ const user = setupUser()
361
+ const onDuplicate = vi.fn()
362
+ render(<FilterMenu onDuplicate={onDuplicate} />)
363
+ await user.click(screen.getByRole('button', { name: 'Actions' }))
364
+ const input = await screen.findByRole('searchbox', { name: 'Filter actions' })
365
+ await user.type(input, 'dup')
366
+ await user.keyboard('{ArrowDown}')
367
+ await waitFor(() => {
368
+ expect(screen.getByRole('menuitem', { name: 'Duplicate' })).toHaveAttribute('data-highlighted')
369
+ })
370
+ expect(input).toHaveFocus()
371
+ await user.keyboard('{Enter}')
372
+ expect(onDuplicate).toHaveBeenCalledTimes(1)
373
+ })
374
+
375
+ it('highlights the first match as you type with autoHighlight', async () => {
376
+ const user = setupUser()
377
+ render(<FilterMenu autoHighlight />)
378
+ await user.click(screen.getByRole('button', { name: 'Actions' }))
379
+ await user.type(await screen.findByRole('searchbox', { name: 'Filter actions' }), 'link')
380
+ await waitFor(() => {
381
+ expect(screen.getByRole('menuitem', { name: 'Copy link' })).toHaveAttribute('data-highlighted')
382
+ })
383
+ })
384
+
385
+ it('clears the query from the clear button', async () => {
386
+ const user = setupUser()
387
+ render(<FilterMenu />)
388
+ await user.click(screen.getByRole('button', { name: 'Actions' }))
389
+ const input = await screen.findByRole('searchbox', { name: 'Filter actions' })
390
+ expect(document.querySelector('[data-slot="dropdown-menu-clear"]')).toBeNull()
391
+ await user.type(input, 'ren')
392
+ const clear = document.querySelector<HTMLButtonElement>('[data-slot="dropdown-menu-clear"]')
393
+ expect(clear).not.toBeNull()
394
+ await user.click(clear!)
395
+ expect(input).toHaveValue('')
396
+ await waitFor(() => expect(screen.getAllByRole('menuitem')).toHaveLength(3))
397
+ })
398
+
399
+ it('filters a submenu wrapped in its own provider', async () => {
400
+ const user = setupUser()
401
+ render(
402
+ <DropdownMenu>
403
+ <DropdownMenuTrigger>Open</DropdownMenuTrigger>
404
+ <DropdownMenuContent>
405
+ <DropdownMenuItem>Rename</DropdownMenuItem>
406
+ <DropdownMenuFilterProvider>
407
+ <DropdownMenuSub>
408
+ <DropdownMenuSubTrigger>Move to</DropdownMenuSubTrigger>
409
+ <DropdownMenuSubContent>
410
+ <DropdownMenuInput aria-label="Filter folders" />
411
+ <DropdownMenuList>
412
+ <DropdownMenuItem>Documents</DropdownMenuItem>
413
+ <DropdownMenuItem>Downloads</DropdownMenuItem>
414
+ <DropdownMenuItem>Projects</DropdownMenuItem>
415
+ </DropdownMenuList>
416
+ </DropdownMenuSubContent>
417
+ </DropdownMenuSub>
418
+ </DropdownMenuFilterProvider>
419
+ </DropdownMenuContent>
420
+ </DropdownMenu>,
421
+ )
422
+ await user.click(screen.getByRole('button', { name: 'Open' }))
423
+ expect(screen.queryByRole('searchbox')).toBeNull()
424
+ await screen.findByRole('menuitem', { name: /Move to/ })
425
+ await user.keyboard('{ArrowDown}{ArrowDown}{ArrowRight}')
426
+ const input = await screen.findByRole('searchbox', { name: 'Filter folders' })
427
+ await waitFor(() => expect(input).toHaveFocus())
428
+ await user.keyboard('do')
429
+ await waitFor(() => {
430
+ expect(screen.queryByRole('menuitem', { name: 'Projects' })).toBeNull()
431
+ })
432
+ expect(screen.getByRole('menuitem', { name: 'Documents' })).toBeInTheDocument()
433
+ expect(screen.getByRole('menuitem', { name: 'Downloads' })).toBeInTheDocument()
434
+ })
435
+
436
+ it('has no a11y violations while open', async () => {
437
+ const user = setupUser()
438
+ render(<FilterMenu />)
439
+ await user.click(screen.getByRole('button', { name: 'Actions' }))
440
+ await user.type(await screen.findByRole('searchbox', { name: 'Filter actions' }), 're')
441
+ expect(await axe(document.body)).toHaveNoViolations()
442
+ })
255
443
  })
@@ -5,6 +5,7 @@ import { Menu as BaseMenu } from '@base-ui/react/menu'
5
5
  import { useReducedMotion } from '../../hooks/use-reduced-motion'
6
6
  import { cn } from '../../internal/utils'
7
7
  import { type FloatingContentProps, splitFloatingProps } from '../../internal/floating'
8
+ import { inputVariants } from '../input/input-variants'
8
9
  import { navigationLinkVariants } from '../navigation/navigation-link-variants'
9
10
 
10
11
  type DropdownMenuSize = 'sm' | 'md' | 'lg'
@@ -44,6 +45,12 @@ function DropdownMenu({ size = 'md', children, ...rest }: DropdownMenuProps) {
44
45
  )
45
46
  }
46
47
 
48
+ type DropdownMenuFilterProviderProps = React.ComponentProps<typeof BaseMenu.FilterProvider>
49
+
50
+ function DropdownMenuFilterProvider(props: DropdownMenuFilterProviderProps) {
51
+ return <BaseMenu.FilterProvider {...props} />
52
+ }
53
+
47
54
  type DropdownMenuTriggerProps = React.ComponentProps<typeof BaseMenu.Trigger>
48
55
 
49
56
  function DropdownMenuTrigger({ className, ...props }: DropdownMenuTriggerProps) {
@@ -67,13 +74,20 @@ function popupClassName(size: DropdownMenuSize, className?: string) {
67
74
  'max-h-(--available-height) w-(--anchor-width) bg-background border-border-overlay flex flex-col border shadow-2xl outline-none',
68
75
  POPUP_SIZE[size],
69
76
  'origin-(--transform-origin)',
70
- 'motion-safe:transition-[opacity,scale] motion-safe:duration-200 motion-safe:ease-[cubic-bezier(0.175,0.885,0.32,1.5)]',
77
+ 'motion-safe:transition-[opacity,scale] motion-safe:duration-200 motion-safe:ease-spring',
71
78
  'data-starting-style:motion-safe:scale-90 data-starting-style:motion-safe:opacity-0',
72
79
  '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',
73
80
  className,
74
81
  )
75
82
  }
76
83
 
84
+ const POPUP_BODY = cn(
85
+ 'flex flex-col gap-0.5 overflow-x-hidden overflow-y-auto p-2',
86
+ 'has-data-[slot=dropdown-menu-list]:p-0',
87
+ 'has-data-[slot=dropdown-menu-input]:gap-2 has-data-[slot=dropdown-menu-input]:*:data-[slot=dropdown-menu-list]:pt-0',
88
+ 'has-data-[slot=dropdown-menu-empty]:*:data-[slot=dropdown-menu-list]:p-0',
89
+ )
90
+
77
91
  type DropdownMenuFloatingProps = FloatingContentProps<
78
92
  React.ComponentProps<typeof BaseMenu.Positioner>,
79
93
  React.ComponentProps<typeof BaseMenu.Portal>
@@ -97,13 +111,91 @@ function DropdownMenuContent({ className, children, ...props }: DropdownMenuCont
97
111
  className={cn('isolate z-50', positioner.className as string | undefined)}
98
112
  >
99
113
  <BaseMenu.Popup data-slot="dropdown-menu-content" className={popupClassName(size, className)} {...popup}>
100
- <div className="flex flex-col gap-0.5 overflow-x-hidden overflow-y-auto p-2">{children}</div>
114
+ <div className={POPUP_BODY}>{children}</div>
101
115
  </BaseMenu.Popup>
102
116
  </BaseMenu.Positioner>
103
117
  </BaseMenu.Portal>
104
118
  )
105
119
  }
106
120
 
121
+ const INPUT_RADIUS: Record<DropdownMenuSize, string> = {
122
+ sm: 'rounded-xs',
123
+ md: 'rounded-sm',
124
+ lg: 'rounded-md',
125
+ }
126
+
127
+ interface DropdownMenuInputProps extends Omit<React.ComponentProps<typeof BaseMenu.Input>, 'className'> {
128
+ /** Extra classes on the frame that holds the field, its search icon and its clear button. */
129
+ className?: string
130
+ }
131
+
132
+ function DropdownMenuInput({ className, ...props }: DropdownMenuInputProps) {
133
+ const { size } = useDropdownMenuContext()
134
+ return (
135
+ <div
136
+ data-slot="dropdown-menu-input"
137
+ className={cn(
138
+ inputVariants({ size }),
139
+ 'm-2 mb-0 flex w-auto shrink-0 items-center',
140
+ INPUT_RADIUS[size],
141
+ 'has-data-highlighted:ring-ring-input has-data-highlighted:border-transparent has-data-highlighted:ring-3',
142
+ className,
143
+ )}
144
+ >
145
+ <SearchIcon className="text-foreground-subtle -ms-0.5" />
146
+ <BaseMenu.Input
147
+ data-slot="dropdown-menu-input-field"
148
+ className="placeholder:text-foreground-subtle h-full min-w-0 flex-1 bg-transparent outline-none"
149
+ {...props}
150
+ />
151
+ <BaseMenu.Clear
152
+ data-slot="dropdown-menu-clear"
153
+ className="text-foreground-subtle hover:text-foreground shrink-0 cursor-pointer transition-colors duration-200 outline-none motion-reduce:transition-none"
154
+ >
155
+ <ClearIcon className="size-[1em]" />
156
+ </BaseMenu.Clear>
157
+ </div>
158
+ )
159
+ }
160
+
161
+ const EMPTY_SIZE: Record<DropdownMenuSize, string> = {
162
+ sm: 'px-2.5 py-2 text-xs',
163
+ md: 'px-3 py-2.5 text-sm',
164
+ lg: 'px-3.5 py-3 text-base',
165
+ }
166
+
167
+ type DropdownMenuEmptyProps = React.ComponentProps<typeof BaseMenu.Empty>
168
+
169
+ function DropdownMenuEmpty({ className, ...props }: DropdownMenuEmptyProps) {
170
+ const { size } = useDropdownMenuContext()
171
+ return (
172
+ <BaseMenu.Empty
173
+ data-slot="dropdown-menu-empty"
174
+ className={cn('text-foreground-muted text-center', EMPTY_SIZE[size], className)}
175
+ {...props}
176
+ />
177
+ )
178
+ }
179
+
180
+ type DropdownMenuListProps = React.ComponentProps<typeof BaseMenu.List>
181
+
182
+ function DropdownMenuList({ className, ...props }: DropdownMenuListProps) {
183
+ return (
184
+ <BaseMenu.List
185
+ data-slot="dropdown-menu-list"
186
+ className={cn(
187
+ 'flex min-h-0 flex-1 flex-col gap-0.5 overflow-x-hidden overflow-y-auto p-2 outline-none',
188
+ '*:data-[slot=dropdown-menu-separator]:first:hidden *:data-[slot=dropdown-menu-separator]:last:hidden',
189
+ '*:data-[slot=dropdown-menu-separator]:has-[+[hidden]]:hidden',
190
+ '[&>[hidden]+[data-slot=dropdown-menu-separator]]:hidden',
191
+ '[&>[data-slot=dropdown-menu-separator]+[data-slot=dropdown-menu-separator]]:hidden',
192
+ className,
193
+ )}
194
+ {...props}
195
+ />
196
+ )
197
+ }
198
+
107
199
  const ITEM_BASE = 'w-full outline-hidden'
108
200
 
109
201
  const ITEM_TEXT: Record<DropdownMenuSize, string> = {
@@ -272,7 +364,7 @@ function DropdownMenuSubContent({ className, children, ...props }: DropdownMenuS
272
364
  className={cn('isolate z-50', positioner.className as string | undefined)}
273
365
  >
274
366
  <BaseMenu.Popup data-slot="dropdown-menu-sub-content" className={popupClassName(size, className)} {...popup}>
275
- <div className="flex flex-col gap-0.5 overflow-x-hidden overflow-y-auto p-2">{children}</div>
367
+ <div className={POPUP_BODY}>{children}</div>
276
368
  </BaseMenu.Popup>
277
369
  </BaseMenu.Positioner>
278
370
  </BaseMenu.Portal>
@@ -318,10 +410,40 @@ function ChevronEndIcon(props: IconProps) {
318
410
  )
319
411
  }
320
412
 
413
+ function SearchIcon(props: IconProps) {
414
+ return (
415
+ <svg
416
+ xmlns="http://www.w3.org/2000/svg"
417
+ viewBox="0 0 24 24"
418
+ fill="none"
419
+ stroke="currentColor"
420
+ strokeLinecap="round"
421
+ strokeLinejoin="round"
422
+ aria-hidden="true"
423
+ {...props}
424
+ >
425
+ <circle cx="10" cy="10" r="7" />
426
+ <path d="m21 21-6-6" />
427
+ </svg>
428
+ )
429
+ }
430
+
431
+ function ClearIcon(props: IconProps) {
432
+ return (
433
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 16 16" fill="currentColor" aria-hidden="true" {...props}>
434
+ <path d="M6.28 5.22a.75.75 0 0 0-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 1 0 1.06 1.06L10 11.06l3.72 3.72a.75.75 0 1 0 1.06-1.06L11.06 10l3.72-3.72a.75.75 0 0 0-1.06-1.06L10 8.94 6.28 5.22Z" />
435
+ </svg>
436
+ )
437
+ }
438
+
321
439
  export {
322
440
  DropdownMenu,
441
+ DropdownMenuFilterProvider,
323
442
  DropdownMenuTrigger,
324
443
  DropdownMenuContent,
444
+ DropdownMenuInput,
445
+ DropdownMenuEmpty,
446
+ DropdownMenuList,
325
447
  DropdownMenuGroup,
326
448
  DropdownMenuGroupLabel,
327
449
  DropdownMenuItem,
@@ -336,8 +458,12 @@ export {
336
458
  }
337
459
  export type {
338
460
  DropdownMenuProps,
461
+ DropdownMenuFilterProviderProps,
339
462
  DropdownMenuTriggerProps,
340
463
  DropdownMenuContentProps,
464
+ DropdownMenuInputProps,
465
+ DropdownMenuEmptyProps,
466
+ DropdownMenuListProps,
341
467
  DropdownMenuGroupProps,
342
468
  DropdownMenuGroupLabelProps,
343
469
  DropdownMenuItemProps,
@@ -3,7 +3,7 @@ import { cn } from '../../internal/utils'
3
3
 
4
4
  const base = [
5
5
  'relative inline-flex items-center gap-1.5 transform-gpu cursor-pointer font-medium outline-none',
6
- 'transition duration-250 ease-[cubic-bezier(0.175,0.885,0.32,1.5)]',
6
+ 'transition duration-250 ease-spring',
7
7
  'select-none not-data-popup-open:active:scale-[0.97] not-data-popup-open:active:duration-100 not-data-popup-open:active:ease-in-out not-data-popup-open:active:translate-y-px',
8
8
  'data-disabled:opacity-disabled data-disabled:pointer-events-none',
9
9
  'group-data-disabled/submenu-trigger:opacity-disabled group-data-disabled/submenu-trigger:pointer-events-none',
@@ -328,8 +328,8 @@ function NavigationMenuPositioner({
328
328
  morph && 'h-(--popup-height) w-(--popup-width)',
329
329
  'origin-(--transform-origin)',
330
330
  morph
331
- ? 'motion-safe:[transition:opacity_300ms_cubic-bezier(0.175,0.885,0.32,1.5),scale_300ms_cubic-bezier(0.175,0.885,0.32,1.5),width_300ms_cubic-bezier(0.22,1,0.36,1),height_300ms_cubic-bezier(0.22,1,0.36,1)]'
332
- : 'motion-safe:transition-[opacity,scale] motion-safe:duration-300 motion-safe:ease-[cubic-bezier(0.175,0.885,0.32,1.5)]',
331
+ ? 'motion-safe:[transition:opacity_300ms_var(--ease-spring),scale_300ms_var(--ease-spring),width_300ms_cubic-bezier(0.22,1,0.36,1),height_300ms_cubic-bezier(0.22,1,0.36,1)]'
332
+ : 'motion-safe:ease-spring motion-safe:transition-[opacity,scale] motion-safe:duration-300',
333
333
  'data-starting-style:motion-safe:scale-95 data-starting-style:motion-safe:opacity-0',
334
334
  'data-ending-style:motion-safe:scale-95 data-ending-style:motion-safe:opacity-0 data-ending-style:motion-safe:duration-150 data-ending-style:motion-safe:ease-out',
335
335
  className,
@@ -55,7 +55,7 @@ function PopoverContent({ className, arrow = true, children, ...props }: Popover
55
55
  'group-data-[side=inline-start]/popup:border-e-2',
56
56
  'group-data-[side=inline-end]/popup:border-s-2',
57
57
  ],
58
- 'motion-safe:origin-(--transform-origin) motion-safe:transition-[opacity,scale] motion-safe:duration-200 motion-safe:ease-[cubic-bezier(0.175,0.885,0.32,1.5)]',
58
+ 'motion-safe:ease-spring motion-safe:origin-(--transform-origin) motion-safe:transition-[opacity,scale] motion-safe:duration-200',
59
59
  'group-data-starting-style/popup:motion-safe:scale-90 group-data-starting-style/popup:motion-safe:opacity-0',
60
60
  'group-data-ending-style/popup:motion-safe:scale-95 group-data-ending-style/popup:motion-safe:opacity-0 group-data-ending-style/popup:motion-safe:duration-100 group-data-ending-style/popup:motion-safe:ease-out',
61
61
  className,
@@ -55,7 +55,7 @@ function PreviewCardContent({ className, arrow = true, children, ...props }: Pre
55
55
  'group-data-[side=inline-start]/popup:border-e-2',
56
56
  'group-data-[side=inline-end]/popup:border-s-2',
57
57
  ],
58
- 'motion-safe:origin-(--transform-origin) motion-safe:transition-[opacity,scale] motion-safe:duration-200 motion-safe:ease-[cubic-bezier(0.175,0.885,0.32,1.5)]',
58
+ 'motion-safe:ease-spring motion-safe:origin-(--transform-origin) motion-safe:transition-[opacity,scale] motion-safe:duration-200',
59
59
  'group-data-starting-style/popup:motion-safe:scale-90 group-data-starting-style/popup:motion-safe:opacity-0',
60
60
  'group-data-ending-style/popup:motion-safe:scale-95 group-data-ending-style/popup:motion-safe:opacity-0 group-data-ending-style/popup:motion-safe:duration-100 group-data-ending-style/popup:motion-safe:ease-out',
61
61
  className,
@@ -265,7 +265,7 @@ function SelectContent({ className, alignItemWithTrigger: alignOverride, childre
265
265
  'min-w-36',
266
266
  alignWithTrigger ? 'w-[calc(var(--anchor-width)+1rem)]' : 'w-(--anchor-width)',
267
267
  alignWithTrigger ? 'origin-center' : 'origin-(--transform-origin)',
268
- 'motion-safe:transition-[opacity,scale] motion-safe:duration-200 motion-safe:ease-[cubic-bezier(0.175,0.885,0.32,1.5)]',
268
+ 'motion-safe:ease-spring motion-safe:transition-[opacity,scale] motion-safe:duration-200',
269
269
  'data-starting-style:motion-safe:scale-90 data-starting-style:motion-safe:opacity-0',
270
270
  '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',
271
271
  className,
@@ -362,7 +362,7 @@ function SelectItem({ className, children, ...props }: SelectItemProps) {
362
362
  'before:bg-background-muted before:absolute before:inset-0 before:-z-10 before:rounded-[inherit] before:opacity-0',
363
363
  'active:translate-y-px active:scale-[0.98]',
364
364
  'data-highlighted:not-data-disabled:text-foreground-intense data-highlighted:not-data-disabled:before:opacity-100',
365
- 'motion-safe:transition motion-safe:duration-250 motion-safe:ease-[cubic-bezier(0.175,0.885,0.32,1.5)]',
365
+ 'motion-safe:ease-spring motion-safe:transition motion-safe:duration-250',
366
366
  'motion-safe:active:duration-100 motion-safe:active:ease-in-out',
367
367
  'motion-safe:before:transition-opacity motion-safe:before:duration-200 motion-safe:before:ease-out',
368
368
  'data-disabled:opacity-disabled data-disabled:pointer-events-none',
@@ -5,6 +5,11 @@ import { axe } from 'vitest-axe'
5
5
  import { Slider } from './slider'
6
6
 
7
7
  describe('Slider', () => {
8
+ it('keeps a surrounding Drawer from swiping on any drag that starts on the control', () => {
9
+ const { container } = render(<Slider thumbAriaLabel="Volume" />)
10
+ expect(container.querySelector('[data-slot="slider-control"]')).toHaveAttribute('data-base-ui-swipe-ignore', '')
11
+ })
12
+
8
13
  it('renders a single thumb when no value is provided', () => {
9
14
  render(<Slider thumbAriaLabel="Volume" />)
10
15
  const thumbs = screen.getAllByRole('slider')
@@ -19,6 +19,7 @@ const TOOLTIP_TILT_TRANSITION = {
19
19
 
20
20
  const TOOLTIP_POPUP_TRANSITION = {
21
21
  duration: 0.2,
22
+ // `--ease-spring` in styles.css, as numbers: Motion can't read a CSS variable.
22
23
  ease: [0.175, 0.885, 0.32, 1.5] satisfies [number, number, number, number],
23
24
  }
24
25
 
@@ -240,7 +241,7 @@ function Slider({
240
241
  className={cn(rootClasses, className)}
241
242
  {...rootProps}
242
243
  >
243
- <BaseSlider.Control data-slot="slider-control" className={controlClasses}>
244
+ <BaseSlider.Control data-slot="slider-control" data-base-ui-swipe-ignore="" className={controlClasses}>
244
245
  <BaseSlider.Track data-slot="slider-track" className={trackClasses}>
245
246
  <BaseSlider.Indicator data-slot="slider-indicator" className={indicatorClasses} />
246
247
  </BaseSlider.Track>
@@ -23,6 +23,22 @@ function stubRect(el: Element, width = 100) {
23
23
  }
24
24
 
25
25
  describe('Sparkline', () => {
26
+ it('claims horizontal drags from a surrounding Drawer only while it is interactive', () => {
27
+ const chart = (container: HTMLElement) => container.querySelector('[data-slot="sparkline-svg"]')!.parentElement
28
+ const { container: interactive } = render(
29
+ <Sparkline data={DATA}>
30
+ <SparklineChart />
31
+ </Sparkline>,
32
+ )
33
+ expect(chart(interactive)).toHaveAttribute('data-base-ui-swipe-ignore', 'x')
34
+ const { container: still } = render(
35
+ <Sparkline data={DATA}>
36
+ <SparklineChart indicator={false} />
37
+ </Sparkline>,
38
+ )
39
+ expect(chart(still)).not.toHaveAttribute('data-base-ui-swipe-ignore')
40
+ })
41
+
26
42
  it('renders a line path for the line variant', () => {
27
43
  const { container } = render(
28
44
  <Sparkline data={DATA}>
@@ -271,6 +271,7 @@ function SparklineChart({
271
271
  aria-label={ariaLabel ?? `${variant} chart`}
272
272
  className={cn('relative w-full', className)}
273
273
  style={{ height, touchAction: interactive ? 'pan-y' : undefined, ...style }}
274
+ data-base-ui-swipe-ignore={interactive ? 'x' : undefined}
274
275
  onPointerDown={interactive ? handlePointerDown : undefined}
275
276
  onPointerMove={interactive ? handlePointerMove : undefined}
276
277
  onPointerLeave={interactive ? () => setActiveIndex(null) : undefined}
@@ -99,7 +99,7 @@ const tabsTriggerVariants = cva(
99
99
  )
100
100
 
101
101
  const tabsTriggerInnerVariants = cva(
102
- 'relative isolate flex items-center data-[orientation=horizontal]:justify-center data-[orientation=vertical]:w-full data-[orientation=horizontal]:text-center data-[orientation=vertical]:text-start data-[orientation=horizontal]:whitespace-nowrap transform-gpu transition-transform duration-250 ease-[cubic-bezier(0.175,0.885,0.32,1.5)] motion-reduce:transition-none group-active/trigger:scale-[0.97] group-active/trigger:duration-100 group-active/trigger:ease-in-out group-active/trigger:translate-y-px',
102
+ 'relative isolate flex items-center data-[orientation=horizontal]:justify-center data-[orientation=vertical]:w-full data-[orientation=horizontal]:text-center data-[orientation=vertical]:text-start data-[orientation=horizontal]:whitespace-nowrap transform-gpu transition-transform duration-250 ease-spring motion-reduce:transition-none group-active/trigger:scale-[0.97] group-active/trigger:duration-100 group-active/trigger:ease-in-out group-active/trigger:translate-y-px',
103
103
  {
104
104
  variants: {
105
105
  variant: {
@@ -127,6 +127,14 @@ describe('Thumbnail', () => {
127
127
  expect(lifted.getAttribute('data-slot')).toBe('thumbnail-image')
128
128
  })
129
129
 
130
+ it('mounts the image on the first render with keepMounted instead of preloading it', () => {
131
+ const { container: preloaded } = render(<Thumbnail src="/peak.jpg" alt="Peak" />)
132
+ expect(preloaded.querySelector('[data-slot="thumbnail-image"]')).toBeNull()
133
+
134
+ const { container: inPlace } = render(<Thumbnail src="/peak.jpg" alt="Peak" keepMounted />)
135
+ expect(inPlace.querySelector('[data-slot="thumbnail-image"]')).toHaveAttribute('src', '/peak.jpg')
136
+ })
137
+
130
138
  it('swaps the underlying element via a render function', async () => {
131
139
  render(
132
140
  <Thumbnail
@@ -67,6 +67,11 @@ interface ThumbnailProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'si
67
67
  alt?: string
68
68
  /** Swap the `<img>` for another element - e.g. a Next.js `<Image>`. */
69
69
  render?: BaseImageProps['render']
70
+ /**
71
+ * Mount the image and let it load in place instead of preloading `src`. Set it for `loading="lazy"` and for image components such as Next.js `<Image>`, which otherwise download twice.
72
+ * @default false
73
+ */
74
+ keepMounted?: BaseImageProps['keepMounted']
70
75
  /** Fires as the image moves through its loading lifecycle. */
71
76
  onLoadingStatusChange?: BaseImageProps['onLoadingStatusChange']
72
77
  /** The icon to frame (icon variants). */
@@ -82,6 +87,7 @@ function Thumbnail({
82
87
  src,
83
88
  alt,
84
89
  render,
90
+ keepMounted,
85
91
  onLoadingStatusChange,
86
92
  children,
87
93
  ...props
@@ -121,6 +127,7 @@ function Thumbnail({
121
127
  src={src ?? lifted?.src}
122
128
  alt={alt ?? lifted?.alt ?? ''}
123
129
  render={render}
130
+ keepMounted={keepMounted}
124
131
  onLoadingStatusChange={onLoadingStatusChange}
125
132
  />
126
133
  <BaseAvatar.Fallback
@@ -49,7 +49,7 @@ function TooltipContent({ className, arrow = true, children, ...props }: Tooltip
49
49
  data-slot="tooltip-content"
50
50
  className={cn(
51
51
  'bg-background-inverse text-foreground-inverse rounded-xs px-3 py-1.5 text-xs shadow-md',
52
- 'motion-safe:origin-(--transform-origin) motion-safe:transition-[opacity,scale] motion-safe:duration-200 motion-safe:ease-[cubic-bezier(0.175,0.885,0.32,1.5)]',
52
+ 'motion-safe:ease-spring motion-safe:origin-(--transform-origin) motion-safe:transition-[opacity,scale] motion-safe:duration-200',
53
53
  'data-starting-style:motion-safe:scale-90 data-starting-style:motion-safe:opacity-0',
54
54
  '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',
55
55
  'data-instant:motion-safe:transition-none',
@@ -16,10 +16,6 @@ export interface UseMediaQueryOptions {
16
16
  * Next.js, Remix, Astro): on the server and the first client render it returns
17
17
  * `defaultValue`, then the real value resolves on hydration via
18
18
  * `useSyncExternalStore`.
19
- *
20
- * @example
21
- * const isDesktop = useMediaQuery('(min-width: 768px)')
22
- * return isDesktop ? <Dialog … /> : <Drawer … />
23
19
  */
24
20
  export function useMediaQuery(query: string, { defaultValue = false }: UseMediaQueryOptions = {}): boolean {
25
21
  const subscribe = useCallback(
package/src/index.ts CHANGED
@@ -25,6 +25,7 @@ export * from './components/color-slider/color-slider'
25
25
  export * from './components/color-swatch/color-swatch'
26
26
  export * from './components/color-swatch-picker/color-swatch-picker'
27
27
  export * from './components/combobox/combobox'
28
+ export * from './components/compare-slider/compare-slider'
28
29
  export * from './components/context-menu/context-menu'
29
30
  export * from './components/copy-button/copy-button'
30
31
  export * from './components/countdown/countdown'
@@ -1,7 +1,14 @@
1
1
  import * as React from 'react'
2
2
  import { render } from '@testing-library/react'
3
3
  import { describe, it, expect, vi } from 'vitest'
4
- import { composeRefs, useComposedRefs } from './utils'
4
+ import { cn, composeRefs, useComposedRefs } from './utils'
5
+
6
+ describe('cn', () => {
7
+ it('treats ease-spring as a timing function, so a later ease-* replaces it', () => {
8
+ expect(cn('ease-spring', 'ease-linear')).toBe('ease-linear')
9
+ expect(cn('motion-safe:ease-out', 'motion-safe:ease-spring')).toBe('motion-safe:ease-spring')
10
+ })
11
+ })
5
12
 
6
13
  describe('composeRefs', () => {
7
14
  it('assigns a node to object refs and calls function refs', () => {
@@ -1,7 +1,10 @@
1
1
  import { clsx, type ClassValue } from 'clsx'
2
- import { twMerge } from 'tailwind-merge'
2
+ import { extendTailwindMerge } from 'tailwind-merge'
3
3
  import * as React from 'react'
4
4
 
5
+ // Custom theme keys must be registered, or `ease-linear` would sit beside `ease-spring` instead of replacing it.
6
+ const twMerge = extendTailwindMerge({ extend: { theme: { ease: ['spring'] } } })
7
+
5
8
  export function cn(...inputs: ClassValue[]) {
6
9
  return twMerge(clsx(inputs))
7
10
  }