@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
@@ -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,
@@ -146,7 +150,8 @@ describe('DropdownMenu', () => {
146
150
  const user = setupUser()
147
151
  render(<BasicMenu />)
148
152
  await user.click(screen.getByRole('button', { name: 'Open' }))
149
- await screen.findByRole('menuitem', { name: 'Profile' })
153
+ const menu = await screen.findByRole('menu')
154
+ await waitFor(() => expect(menu.contains(document.activeElement)).toBe(true))
150
155
  await user.keyboard('{ArrowDown}')
151
156
  await waitFor(() => {
152
157
  const profile = screen.getByRole('menuitem', { name: 'Profile' })
@@ -252,4 +257,188 @@ describe('DropdownMenu', () => {
252
257
  const { container } = render(<BasicMenu />)
253
258
  expect(await axe(container)).toHaveNoViolations()
254
259
  })
260
+
261
+ it('reports highlight changes through onItemHighlighted', async () => {
262
+ const user = setupUser()
263
+ const onItemHighlighted = vi.fn()
264
+ render(
265
+ <DropdownMenu onItemHighlighted={onItemHighlighted}>
266
+ <DropdownMenuTrigger>Open</DropdownMenuTrigger>
267
+ <DropdownMenuContent>
268
+ <DropdownMenuItem>Profile</DropdownMenuItem>
269
+ <DropdownMenuItem>Settings</DropdownMenuItem>
270
+ </DropdownMenuContent>
271
+ </DropdownMenu>,
272
+ )
273
+ await user.click(screen.getByRole('button', { name: 'Open' }))
274
+ await screen.findByRole('menuitem', { name: 'Profile' })
275
+ await user.keyboard('{ArrowDown}')
276
+ await waitFor(() => {
277
+ expect(onItemHighlighted).toHaveBeenCalledWith(
278
+ screen.getByRole('menuitem', { name: 'Profile' }),
279
+ expect.objectContaining({ reason: 'keyboard', event: expect.any(KeyboardEvent) }),
280
+ )
281
+ })
282
+ })
283
+
284
+ it('List: keeps content beside the list out of the menu role', async () => {
285
+ const user = setupUser()
286
+ render(
287
+ <DropdownMenu>
288
+ <DropdownMenuTrigger>Open</DropdownMenuTrigger>
289
+ <DropdownMenuContent>
290
+ <p>Signed in as Sarah</p>
291
+ <DropdownMenuList>
292
+ <DropdownMenuItem>Profile</DropdownMenuItem>
293
+ </DropdownMenuList>
294
+ </DropdownMenuContent>
295
+ </DropdownMenu>,
296
+ )
297
+ await user.click(screen.getByRole('button', { name: 'Open' }))
298
+ const menu = await screen.findByRole('menu')
299
+ expect(menu).toContainElement(screen.getByRole('menuitem', { name: 'Profile' }))
300
+ expect(menu).not.toContainElement(screen.getByText('Signed in as Sarah'))
301
+ })
302
+ })
303
+
304
+ function FilterMenu({ onDuplicate, autoHighlight }: { onDuplicate?: () => void; autoHighlight?: boolean } = {}) {
305
+ return (
306
+ <DropdownMenuFilterProvider {...(autoHighlight && { autoHighlight })}>
307
+ <DropdownMenu>
308
+ <DropdownMenuTrigger>Actions</DropdownMenuTrigger>
309
+ <DropdownMenuContent>
310
+ <DropdownMenuInput aria-label="Filter actions" placeholder="Filter actions" />
311
+ <DropdownMenuEmpty>No actions found.</DropdownMenuEmpty>
312
+ <DropdownMenuList>
313
+ <DropdownMenuGroup>
314
+ <DropdownMenuGroupLabel>File</DropdownMenuGroupLabel>
315
+ <DropdownMenuItem>Rename</DropdownMenuItem>
316
+ <DropdownMenuItem onClick={onDuplicate}>Duplicate</DropdownMenuItem>
317
+ </DropdownMenuGroup>
318
+ <DropdownMenuSeparator />
319
+ <DropdownMenuGroup data-testid="share-group">
320
+ <DropdownMenuGroupLabel>Share</DropdownMenuGroupLabel>
321
+ <DropdownMenuItem>Copy link</DropdownMenuItem>
322
+ </DropdownMenuGroup>
323
+ </DropdownMenuList>
324
+ </DropdownMenuContent>
325
+ </DropdownMenu>
326
+ </DropdownMenuFilterProvider>
327
+ )
328
+ }
329
+
330
+ describe('DropdownMenu filtering', () => {
331
+ it('focuses the search field when opened with a click', async () => {
332
+ const user = setupUser()
333
+ render(<FilterMenu />)
334
+ await user.click(screen.getByRole('button', { name: 'Actions' }))
335
+ const input = await screen.findByRole('searchbox', { name: 'Filter actions' })
336
+ await waitFor(() => expect(input).toHaveFocus())
337
+ })
338
+
339
+ it('narrows the items to the matches and hides groups left empty', async () => {
340
+ const user = setupUser()
341
+ render(<FilterMenu />)
342
+ await user.click(screen.getByRole('button', { name: 'Actions' }))
343
+ await user.type(await screen.findByRole('searchbox', { name: 'Filter actions' }), 'ren')
344
+ await waitFor(() => {
345
+ expect(screen.getAllByRole('menuitem').map((item) => item.textContent)).toEqual(['Rename'])
346
+ })
347
+ expect(screen.getByTestId('share-group')).not.toBeVisible()
348
+ })
349
+
350
+ it('announces the empty message once nothing matches', async () => {
351
+ const user = setupUser()
352
+ render(<FilterMenu />)
353
+ await user.click(screen.getByRole('button', { name: 'Actions' }))
354
+ expect(screen.queryByText('No actions found.')).toBeNull()
355
+ await user.type(await screen.findByRole('searchbox', { name: 'Filter actions' }), 'zzz')
356
+ expect(await screen.findByRole('status')).toHaveTextContent('No actions found.')
357
+ expect(screen.queryAllByRole('menuitem')).toHaveLength(0)
358
+ })
359
+
360
+ it('selects a match with the keyboard while focus stays in the field', async () => {
361
+ const user = setupUser()
362
+ const onDuplicate = vi.fn()
363
+ render(<FilterMenu onDuplicate={onDuplicate} />)
364
+ await user.click(screen.getByRole('button', { name: 'Actions' }))
365
+ const input = await screen.findByRole('searchbox', { name: 'Filter actions' })
366
+ await user.type(input, 'dup')
367
+ await user.keyboard('{ArrowDown}')
368
+ await waitFor(() => {
369
+ expect(screen.getByRole('menuitem', { name: 'Duplicate' })).toHaveAttribute('data-highlighted')
370
+ })
371
+ expect(input).toHaveFocus()
372
+ await user.keyboard('{Enter}')
373
+ expect(onDuplicate).toHaveBeenCalledTimes(1)
374
+ })
375
+
376
+ it('highlights the first match as you type with autoHighlight', async () => {
377
+ const user = setupUser()
378
+ render(<FilterMenu autoHighlight />)
379
+ await user.click(screen.getByRole('button', { name: 'Actions' }))
380
+ await user.type(await screen.findByRole('searchbox', { name: 'Filter actions' }), 'link')
381
+ await waitFor(() => {
382
+ expect(screen.getByRole('menuitem', { name: 'Copy link' })).toHaveAttribute('data-highlighted')
383
+ })
384
+ })
385
+
386
+ it('clears the query from the clear button', async () => {
387
+ const user = setupUser()
388
+ render(<FilterMenu />)
389
+ await user.click(screen.getByRole('button', { name: 'Actions' }))
390
+ const input = await screen.findByRole('searchbox', { name: 'Filter actions' })
391
+ expect(document.querySelector('[data-slot="dropdown-menu-clear"]')).toBeNull()
392
+ await user.type(input, 'ren')
393
+ const clear = document.querySelector<HTMLButtonElement>('[data-slot="dropdown-menu-clear"]')
394
+ expect(clear).not.toBeNull()
395
+ await user.click(clear!)
396
+ expect(input).toHaveValue('')
397
+ await waitFor(() => expect(screen.getAllByRole('menuitem')).toHaveLength(3))
398
+ })
399
+
400
+ it('filters a submenu wrapped in its own provider', async () => {
401
+ const user = setupUser()
402
+ render(
403
+ <DropdownMenu>
404
+ <DropdownMenuTrigger>Open</DropdownMenuTrigger>
405
+ <DropdownMenuContent>
406
+ <DropdownMenuItem>Rename</DropdownMenuItem>
407
+ <DropdownMenuFilterProvider>
408
+ <DropdownMenuSub>
409
+ <DropdownMenuSubTrigger>Move to</DropdownMenuSubTrigger>
410
+ <DropdownMenuSubContent>
411
+ <DropdownMenuInput aria-label="Filter folders" />
412
+ <DropdownMenuList>
413
+ <DropdownMenuItem>Documents</DropdownMenuItem>
414
+ <DropdownMenuItem>Downloads</DropdownMenuItem>
415
+ <DropdownMenuItem>Projects</DropdownMenuItem>
416
+ </DropdownMenuList>
417
+ </DropdownMenuSubContent>
418
+ </DropdownMenuSub>
419
+ </DropdownMenuFilterProvider>
420
+ </DropdownMenuContent>
421
+ </DropdownMenu>,
422
+ )
423
+ await user.click(screen.getByRole('button', { name: 'Open' }))
424
+ expect(screen.queryByRole('searchbox')).toBeNull()
425
+ await screen.findByRole('menuitem', { name: /Move to/ })
426
+ await user.keyboard('{ArrowDown}{ArrowDown}{ArrowRight}')
427
+ const input = await screen.findByRole('searchbox', { name: 'Filter folders' })
428
+ await waitFor(() => expect(input).toHaveFocus())
429
+ await user.keyboard('do')
430
+ await waitFor(() => {
431
+ expect(screen.queryByRole('menuitem', { name: 'Projects' })).toBeNull()
432
+ })
433
+ expect(screen.getByRole('menuitem', { name: 'Documents' })).toBeInTheDocument()
434
+ expect(screen.getByRole('menuitem', { name: 'Downloads' })).toBeInTheDocument()
435
+ })
436
+
437
+ it('has no a11y violations while open', async () => {
438
+ const user = setupUser()
439
+ render(<FilterMenu />)
440
+ await user.click(screen.getByRole('button', { name: 'Actions' }))
441
+ await user.type(await screen.findByRole('searchbox', { name: 'Filter actions' }), 're')
442
+ expect(await axe(document.body)).toHaveNoViolations()
443
+ })
255
444
  })
@@ -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,
@@ -1,4 +1,5 @@
1
1
  import { render, screen } from '@testing-library/react'
2
+ import userEvent from '@testing-library/user-event'
2
3
  import { describe, it, expect } from 'vitest'
3
4
  import { axe } from 'vitest-axe'
4
5
  import { Field as BaseField } from '@base-ui/react/field'
@@ -42,6 +43,27 @@ describe('Field', () => {
42
43
  expect(screen.getByText('Email is required')).toBeInTheDocument()
43
44
  })
44
45
 
46
+ it('wraps FieldError in a polite live region so a new error is announced', async () => {
47
+ const user = userEvent.setup()
48
+ const { container } = render(
49
+ <Field validationMode="onBlur">
50
+ <FieldLabel>Email</FieldLabel>
51
+ <BaseField.Control type="email" required defaultValue="" />
52
+ <FieldError match="valueMissing">Email is required</FieldError>
53
+ </Field>,
54
+ )
55
+
56
+ const region = container.querySelector('[aria-live="polite"]')
57
+ expect(region).toBeInTheDocument()
58
+ expect(screen.queryByText('Email is required')).not.toBeInTheDocument()
59
+
60
+ await user.type(screen.getByLabelText('Email'), 'a')
61
+ await user.clear(screen.getByLabelText('Email'))
62
+ await user.tab()
63
+
64
+ expect(region).toContainElement(await screen.findByText('Email is required'))
65
+ })
66
+
45
67
  it('exposes validity state via FieldValidity render prop', () => {
46
68
  render(
47
69
  <Field invalid>
@@ -81,4 +103,16 @@ describe('Field', () => {
81
103
  )
82
104
  expect(await axe(container)).toHaveNoViolations()
83
105
  })
106
+
107
+ it('has no accessibility violations with an error shown', async () => {
108
+ const { container } = render(
109
+ <Field invalid>
110
+ <FieldLabel>Email</FieldLabel>
111
+ <BaseField.Control type="email" defaultValue="" />
112
+ <FieldDescription>We never share your email.</FieldDescription>
113
+ <FieldError match>Email is required</FieldError>
114
+ </Field>,
115
+ )
116
+ expect(await axe(container)).toHaveNoViolations()
117
+ })
84
118
  })
@@ -41,6 +41,7 @@ type FieldErrorProps = React.ComponentProps<typeof BaseField.Error>
41
41
  function FieldError({ className, ...props }: FieldErrorProps) {
42
42
  return (
43
43
  <div
44
+ aria-live="polite"
44
45
  className={cn(
45
46
  'grid grid-rows-[0fr]',
46
47
  'has-[[data-slot=field-error]:not([data-starting-style]):not([data-ending-style])]:grid-rows-[1fr]',
@@ -4,14 +4,27 @@ import { axe } from 'vitest-axe'
4
4
  import { Loader } from './loader'
5
5
 
6
6
  describe('Loader', () => {
7
- it('exposes a status region with a default accessible name', () => {
7
+ it('exposes a status region that reads "Loading" as text by default', () => {
8
8
  render(<Loader />)
9
- expect(screen.getByRole('status')).toHaveAttribute('aria-label', 'Loading')
9
+ const status = screen.getByRole('status')
10
+ expect(status).toHaveTextContent('Loading')
11
+ expect(status).not.toHaveAttribute('aria-label')
10
12
  })
11
13
 
12
- it('forwards a custom aria-label', () => {
14
+ it('renders a custom aria-label as the status text', () => {
13
15
  render(<Loader aria-label="Uploading attachment" />)
14
- expect(screen.getByRole('status')).toHaveAttribute('aria-label', 'Uploading attachment')
16
+ const status = screen.getByRole('status')
17
+ expect(status).toHaveTextContent('Uploading attachment')
18
+ expect(status).not.toHaveAttribute('aria-label')
19
+ })
20
+
21
+ it('contributes its label to the name of a surrounding button', () => {
22
+ render(
23
+ <button type="button">
24
+ <Loader aria-label="Saving" currentColor />
25
+ </button>,
26
+ )
27
+ expect(screen.getByRole('button', { name: 'Saving' })).toBeInTheDocument()
15
28
  })
16
29
 
17
30
  it('renders the status region as a <span> so it nests inside <p> without invalid HTML', () => {
@@ -138,7 +138,7 @@ const VARIANT_COMPONENTS: Record<LoaderVariant, React.ComponentType<VariantInner
138
138
  function Loader({
139
139
  variant = 'bar',
140
140
  currentColor = false,
141
- 'aria-label': ariaLabel = 'Loading',
141
+ 'aria-label': label = 'Loading',
142
142
  className,
143
143
  ...props
144
144
  }: LoaderProps) {
@@ -152,7 +152,6 @@ function Loader({
152
152
  <span
153
153
  data-slot="loader"
154
154
  role="status"
155
- aria-label={ariaLabel}
156
155
  className={cn('inline-flex shrink-0 items-center justify-center align-middle', LOADER_SIZE, className)}
157
156
  {...props}
158
157
  >
@@ -163,6 +162,7 @@ function Loader({
163
162
  {inner}
164
163
  </LazyMotion>
165
164
  )}
165
+ <span className="sr-only">{label}</span>
166
166
  </span>
167
167
  )
168
168
  }
@@ -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,
@@ -3,6 +3,7 @@ import { render, screen, waitFor } from '@testing-library/react'
3
3
  import userEvent from '@testing-library/user-event'
4
4
  import { describe, it, expect, vi } from 'vitest'
5
5
  import { axe } from 'vitest-axe'
6
+ import { Field, FieldLabel } from '../field/field'
6
7
  import { NumberField } from './number-field'
7
8
 
8
9
  function renderWithLabel(props: React.ComponentProps<typeof NumberField> = {}, labelText = 'Qty', id = 'qty') {
@@ -221,4 +222,62 @@ describe('NumberField', () => {
221
222
  const { container } = renderWithLabel({}, 'Quantity', 'qty-a11y')
222
223
  expect(await axe(container)).toHaveNoViolations()
223
224
  })
225
+
226
+ describe('accessible name', () => {
227
+ function getRoot(container: HTMLElement) {
228
+ return container.querySelector('[data-slot="number-field"]')
229
+ }
230
+
231
+ it('names the input from a root aria-label, not the root', () => {
232
+ const { container } = render(<NumberField defaultValue={1} aria-label="Quantity" />)
233
+ expect(screen.getByRole('textbox', { name: 'Quantity' })).toHaveAttribute('data-slot', 'number-field-input')
234
+ expect(getRoot(container)).not.toHaveAttribute('aria-label')
235
+ })
236
+
237
+ it('names the input from a root aria-labelledby, not the root', () => {
238
+ const { container } = render(
239
+ <>
240
+ <span id="qty-label">Quantity</span>
241
+ <NumberField defaultValue={1} aria-labelledby="qty-label" />
242
+ </>,
243
+ )
244
+ expect(screen.getByRole('textbox', { name: 'Quantity' })).toHaveAttribute('aria-labelledby', 'qty-label')
245
+ expect(getRoot(container)).not.toHaveAttribute('aria-labelledby')
246
+ })
247
+
248
+ it('keeps the input label from inputProps over the root label', () => {
249
+ const { container } = render(
250
+ <NumberField defaultValue={1} aria-label="Root label" inputProps={{ 'aria-label': 'Seats' }} />,
251
+ )
252
+ expect(screen.getByRole('textbox', { name: 'Seats' })).toBeInTheDocument()
253
+ expect(getRoot(container)).not.toHaveAttribute('aria-label')
254
+ })
255
+
256
+ it('keeps the FieldLabel over the root label inside a Field', () => {
257
+ const { container } = render(
258
+ <Field>
259
+ <FieldLabel>Seats</FieldLabel>
260
+ <NumberField defaultValue={1} aria-label="Root label" />
261
+ </Field>,
262
+ )
263
+ const input = screen.getByRole('textbox', { name: 'Seats' })
264
+ expect(input).not.toHaveAttribute('aria-label')
265
+ expect(getRoot(container)).not.toHaveAttribute('aria-label')
266
+ })
267
+
268
+ it('has no accessibility violations when labeled by a root aria-label', async () => {
269
+ const { container } = render(<NumberField defaultValue={1} aria-label="Quantity" />)
270
+ expect(await axe(container)).toHaveNoViolations()
271
+ })
272
+
273
+ it('has no accessibility violations inside a Field', async () => {
274
+ const { container } = render(
275
+ <Field>
276
+ <FieldLabel>Seats</FieldLabel>
277
+ <NumberField defaultValue={1} />
278
+ </Field>,
279
+ )
280
+ expect(await axe(container)).toHaveNoViolations()
281
+ })
282
+ })
224
283
  })
@@ -2,6 +2,7 @@
2
2
 
3
3
  import * as React from 'react'
4
4
  import { NumberField as BaseNumberField, type NumberFieldRoot } from '@base-ui/react/number-field'
5
+ import { useLabelableContext } from '@base-ui/react/internals/labelable-provider'
5
6
  import { type VariantProps } from 'class-variance-authority'
6
7
  import { AnimatePresence, LazyMotion, domAnimation, m } from 'motion/react'
7
8
  import { cn } from '../../internal/utils'
@@ -118,6 +119,8 @@ function NumberField({
118
119
  min,
119
120
  placeholder = ' ',
120
121
  inputProps,
122
+ 'aria-label': ariaLabel,
123
+ 'aria-labelledby': ariaLabelledBy,
121
124
  ...rootProps
122
125
  }: NumberFieldProps) {
123
126
  const resolvedVariant: NumberFieldVariant = variant
@@ -129,6 +132,10 @@ function NumberField({
129
132
  const ariaInvalid = rootProps['aria-invalid']
130
133
  const invalid = ariaInvalid === true || ariaInvalid === 'true'
131
134
 
135
+ const { labelId } = useLabelableContext()
136
+ const inputHasName = inputProps?.['aria-label'] != null || inputProps?.['aria-labelledby'] != null
137
+ const forwardedName = inputHasName || labelId ? {} : { 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy }
138
+
132
139
  const reduced = useReducedMotion()
133
140
 
134
141
  const formatter = React.useMemo(() => {
@@ -238,6 +245,7 @@ function NumberField({
238
245
  <BaseNumberField.Input
239
246
  data-slot="number-field-input"
240
247
  placeholder={placeholder}
248
+ {...forwardedName}
241
249
  {...inputProps}
242
250
  onPointerDown={(e) => {
243
251
  inputProps?.onPointerDown?.(e)