@appica/ui-react 1.3.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 (77) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/agent-rules.md +2 -0
  3. package/appica.css +1 -1
  4. package/dist/components/autocomplete/autocomplete.d.ts.map +1 -1
  5. package/dist/components/autocomplete/autocomplete.js +1 -5
  6. package/dist/components/autocomplete/autocomplete.js.map +1 -1
  7. package/dist/components/breadcrumb/breadcrumb.js +1 -1
  8. package/dist/components/breadcrumb/breadcrumb.js.map +1 -1
  9. package/dist/components/carousel/carousel.d.ts +2 -2
  10. package/dist/components/carousel/carousel.d.ts.map +1 -1
  11. package/dist/components/carousel/carousel.js +151 -32
  12. package/dist/components/carousel/carousel.js.map +1 -1
  13. package/dist/components/combobox/combobox.d.ts.map +1 -1
  14. package/dist/components/combobox/combobox.js +1 -5
  15. package/dist/components/combobox/combobox.js.map +1 -1
  16. package/dist/components/copy-button/copy-button.d.ts +2 -2
  17. package/dist/components/copy-button/copy-button.d.ts.map +1 -1
  18. package/dist/components/copy-button/copy-button.js +49 -46
  19. package/dist/components/copy-button/copy-button.js.map +1 -1
  20. package/dist/components/date-field/date-field.d.ts.map +1 -1
  21. package/dist/components/date-field/date-field.js +7 -0
  22. package/dist/components/date-field/date-field.js.map +1 -1
  23. package/dist/components/date-picker/date-picker.d.ts +10 -0
  24. package/dist/components/date-picker/date-picker.d.ts.map +1 -1
  25. package/dist/components/date-picker/date-picker.js +14 -0
  26. package/dist/components/date-picker/date-picker.js.map +1 -1
  27. package/dist/components/field/field.d.ts.map +1 -1
  28. package/dist/components/field/field.js +1 -0
  29. package/dist/components/field/field.js.map +1 -1
  30. package/dist/components/loader/loader.d.ts +1 -1
  31. package/dist/components/loader/loader.d.ts.map +1 -1
  32. package/dist/components/loader/loader.js +7 -5
  33. package/dist/components/loader/loader.js.map +1 -1
  34. package/dist/components/number-field/number-field.d.ts +1 -1
  35. package/dist/components/number-field/number-field.d.ts.map +1 -1
  36. package/dist/components/number-field/number-field.js +7 -0
  37. package/dist/components/number-field/number-field.js.map +1 -1
  38. package/dist/components/pagination/pagination.d.ts.map +1 -1
  39. package/dist/components/pagination/pagination.js +1 -2
  40. package/dist/components/pagination/pagination.js.map +1 -1
  41. package/dist/components/spinner/spinner.d.ts +1 -1
  42. package/dist/components/spinner/spinner.d.ts.map +1 -1
  43. package/dist/components/spinner/spinner.js +7 -5
  44. package/dist/components/spinner/spinner.js.map +1 -1
  45. package/dist/components/time-field/time-field.d.ts.map +1 -1
  46. package/dist/components/time-field/time-field.js +7 -0
  47. package/dist/components/time-field/time-field.js.map +1 -1
  48. package/package.json +11 -11
  49. package/src/components/autocomplete/autocomplete.test.tsx +33 -0
  50. package/src/components/autocomplete/autocomplete.tsx +1 -5
  51. package/src/components/breadcrumb/breadcrumb.test.tsx +57 -2
  52. package/src/components/breadcrumb/breadcrumb.tsx +1 -1
  53. package/src/components/carousel/carousel.test.tsx +512 -12
  54. package/src/components/carousel/carousel.tsx +171 -33
  55. package/src/components/chip/chip.test.tsx +4 -5
  56. package/src/components/combobox/combobox.test.tsx +33 -0
  57. package/src/components/combobox/combobox.tsx +1 -5
  58. package/src/components/context-menu/context-menu.test.tsx +2 -1
  59. package/src/components/copy-button/copy-button.test.tsx +68 -3
  60. package/src/components/copy-button/copy-button.tsx +49 -43
  61. package/src/components/date-field/date-field.test.tsx +82 -0
  62. package/src/components/date-field/date-field.tsx +7 -0
  63. package/src/components/date-picker/date-picker.test.tsx +70 -0
  64. package/src/components/date-picker/date-picker.tsx +26 -0
  65. package/src/components/dropdown-menu/dropdown-menu.test.tsx +2 -1
  66. package/src/components/field/field.test.tsx +34 -0
  67. package/src/components/field/field.tsx +1 -0
  68. package/src/components/loader/loader.test.tsx +17 -4
  69. package/src/components/loader/loader.tsx +2 -2
  70. package/src/components/number-field/number-field.test.tsx +59 -0
  71. package/src/components/number-field/number-field.tsx +8 -0
  72. package/src/components/pagination/pagination.test.tsx +83 -0
  73. package/src/components/pagination/pagination.tsx +1 -2
  74. package/src/components/spinner/spinner.test.tsx +17 -4
  75. package/src/components/spinner/spinner.tsx +2 -2
  76. package/src/components/time-field/time-field.test.tsx +64 -0
  77. package/src/components/time-field/time-field.tsx +7 -0
@@ -43,7 +43,6 @@ function Pagination({ className, variant = 'outline', size = 'md', ...props }: P
43
43
  return (
44
44
  <PaginationContext.Provider value={ctx}>
45
45
  <nav
46
- role="navigation"
47
46
  aria-label="pagination"
48
47
  data-slot="pagination"
49
48
  className={cn('data-disabled:opacity-disabled flex w-fit', className)}
@@ -103,7 +102,7 @@ function PaginationLink({ className, active = false, disabled = false, render, .
103
102
  'data-slot': 'pagination-link',
104
103
  'data-active': active || undefined,
105
104
  'aria-current': active ? 'page' : undefined,
106
- ...focusableProps(disabled),
105
+ ...(active && !disabled ? {} : focusableProps(disabled)),
107
106
  className: cn(
108
107
  buttonVariants({ variant, size }),
109
108
  LINK_SIZE_OVERRIDES[size],
@@ -4,14 +4,27 @@ import { axe } from 'vitest-axe'
4
4
  import { Spinner } from './spinner'
5
5
 
6
6
  describe('Spinner', () => {
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(<Spinner />)
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(<Spinner aria-label="Fetching results" />)
14
- expect(screen.getByRole('status')).toHaveAttribute('aria-label', 'Fetching results')
16
+ const status = screen.getByRole('status')
17
+ expect(status).toHaveTextContent('Fetching results')
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
+ <Spinner 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', () => {
@@ -194,7 +194,7 @@ const VARIANT_COMPONENTS: Record<SpinnerVariant, React.ComponentType<VariantInne
194
194
  function Spinner({
195
195
  variant = 'circular',
196
196
  currentColor = false,
197
- 'aria-label': ariaLabel = 'Loading',
197
+ 'aria-label': label = 'Loading',
198
198
  className,
199
199
  ...props
200
200
  }: SpinnerProps) {
@@ -208,7 +208,6 @@ function Spinner({
208
208
  <span
209
209
  data-slot="spinner"
210
210
  role="status"
211
- aria-label={ariaLabel}
212
211
  className={cn('inline-flex shrink-0 items-center justify-center align-middle', SPINNER_SIZE, className)}
213
212
  {...props}
214
213
  >
@@ -219,6 +218,7 @@ function Spinner({
219
218
  {inner}
220
219
  </LazyMotion>
221
220
  )}
221
+ <span className="sr-only">{label}</span>
222
222
  </span>
223
223
  )
224
224
  }
@@ -1,7 +1,9 @@
1
+ import * as React from 'react'
1
2
  import { render, screen, fireEvent } from '@testing-library/react'
2
3
  import userEvent from '@testing-library/user-event'
3
4
  import { describe, it, expect, vi } from 'vitest'
4
5
  import { axe } from 'vitest-axe'
6
+ import { Field, FieldDescription, FieldError, FieldLabel } from '../field/field'
5
7
  import { TimeField } from './time-field'
6
8
 
7
9
  function getSegments(name: 'hour' | 'minute' | 'second' | 'period') {
@@ -346,6 +348,68 @@ describe('TimeField', () => {
346
348
  expect(root).toHaveAttribute('data-disabled')
347
349
  })
348
350
 
351
+ describe('inside a Field', () => {
352
+ function renderInField(props: React.ComponentProps<typeof TimeField> = {}, invalid = false) {
353
+ return render(
354
+ <Field invalid={invalid}>
355
+ <FieldLabel>Start time</FieldLabel>
356
+ <TimeField defaultValue="09:30" {...props} />
357
+ <FieldDescription>Local time.</FieldDescription>
358
+ <FieldError match>Enter a valid time.</FieldError>
359
+ </Field>,
360
+ )
361
+ }
362
+
363
+ it('takes its accessible name from the FieldLabel', () => {
364
+ renderInField()
365
+ const group = screen.getByRole('group', { name: 'Start time' })
366
+ expect(group).toHaveAttribute('data-slot', 'time-field')
367
+ expect(screen.getByText('Start time')).not.toHaveAttribute('for')
368
+ })
369
+
370
+ it('is described by the FieldDescription', () => {
371
+ renderInField()
372
+ const description = screen.getByText('Local time.')
373
+ expect(screen.getByRole('group', { name: 'Start time' })).toHaveAttribute(
374
+ 'aria-describedby',
375
+ expect.stringContaining(description.id),
376
+ )
377
+ })
378
+
379
+ it('is described by the FieldError and marks every segment invalid', () => {
380
+ renderInField({ format: 'hh:mm a' }, true)
381
+ const group = screen.getByRole('group', { name: 'Start time' })
382
+ const error = screen.getByText('Enter a valid time.')
383
+ expect(group).toHaveAttribute('aria-describedby', expect.stringContaining(error.id))
384
+ expect(group).toHaveAttribute('aria-invalid', 'true')
385
+ const segments = screen.getAllByRole('spinbutton')
386
+ expect(segments).toHaveLength(3)
387
+ for (const segment of segments) {
388
+ expect(segment).toHaveAttribute('aria-invalid', 'true')
389
+ }
390
+ })
391
+
392
+ it('lets consumer aria-label and aria-describedby win over the Field wiring', () => {
393
+ renderInField({ 'aria-label': 'Departure', 'aria-describedby': 'custom-hint' })
394
+ const group = screen.getByRole('group', { name: 'Departure' })
395
+ expect(group).not.toHaveAttribute('aria-labelledby')
396
+ expect(group).toHaveAttribute('aria-describedby', 'custom-hint')
397
+ })
398
+
399
+ it('lets a consumer aria-invalid win on the group and segments', () => {
400
+ renderInField({ 'aria-invalid': false }, true)
401
+ expect(screen.getByRole('group', { name: 'Start time' })).toHaveAttribute('aria-invalid', 'false')
402
+ for (const segment of screen.getAllByRole('spinbutton')) {
403
+ expect(segment).toHaveAttribute('aria-invalid', 'false')
404
+ }
405
+ })
406
+
407
+ it('has no accessibility violations when labeled, described and invalid', async () => {
408
+ const { container } = renderInField({}, true)
409
+ expect(await axe(container)).toHaveNoViolations()
410
+ })
411
+ })
412
+
349
413
  it('renders startSlot and endSlot containers', () => {
350
414
  const { container } = render(
351
415
  <TimeField
@@ -3,6 +3,7 @@
3
3
  import * as React from 'react'
4
4
  import { type VariantProps } from 'class-variance-authority'
5
5
  import { useFieldRootContext } from '@base-ui/react/internals/field-root-context'
6
+ import { useLabelableContext, useLabelableId } from '@base-ui/react/internals/labelable-provider'
6
7
  import { cn } from '../../internal/utils'
7
8
  import { inputVariants } from '../input/input-variants'
8
9
 
@@ -256,6 +257,9 @@ function TimeField({
256
257
  const name = nameProp ?? field.name
257
258
  const ariaInvalid = rest['aria-invalid']
258
259
  const invalid = ariaInvalid === true || ariaInvalid === 'true' || field.invalid === true
260
+ const resolvedAriaInvalid = ariaInvalid ?? (invalid || undefined)
261
+ const { labelId, getDescriptionProps } = useLabelableContext()
262
+ useLabelableId({ id: null })
259
263
 
260
264
  const nodes = React.useMemo(() => parseFormat(format), [format])
261
265
  const segmentCount = React.useMemo(() => nodes.reduce((n, x) => n + (x.kind === 'segment' ? 1 : 0), 0), [nodes])
@@ -563,6 +567,8 @@ function TimeField({
563
567
  data-invalid={invalid || undefined}
564
568
  aria-invalid={invalid || undefined}
565
569
  aria-disabled={disabled || undefined}
570
+ aria-labelledby={rest['aria-label'] == null ? labelId : undefined}
571
+ aria-describedby={getDescriptionProps({})['aria-describedby']}
566
572
  role="group"
567
573
  ref={ref}
568
574
  className={cn(
@@ -625,6 +631,7 @@ function TimeField({
625
631
  spellCheck={false}
626
632
  aria-label={ariaLabel(node.type)}
627
633
  aria-readonly={readOnly || undefined}
634
+ aria-invalid={resolvedAriaInvalid}
628
635
  aria-valuemin={isPeriod ? 0 : range.min}
629
636
  aria-valuemax={isPeriod ? 1 : range.max}
630
637
  aria-valuenow={isPeriod ? periodAriaNow : (partVal ?? undefined)}