Skip to content

fix(ui-table): don't stringify non-string captions on v1 - #2836

Merged
matyasf merged 1 commit into
masterfrom
fix/ui-table-element-caption
Dec 2, 2026
Merged

matyasf merged 1 commit into
masterfrom
fix/ui-table-element-caption

Conversation

@aaronshaf

Copy link
Copy Markdown
Member

Summary

A sorted v1 Table with a ReactNode caption renders [object Object] Sorted by Foo (ascending) into its <caption>, its aria-label and the live region announcement.

getCaptionText casts caption to a string and concatenates the sort text onto it. The caption prop docs already say a plain ReactNode is rendered as-is and the sort state is ignored; the v1 code didn't do that. v2 is unaffected (caption must be a function there).

Found in canvas-lms, where the accessibility checker passes <ScreenReaderContent> as the caption (being fixed on their side to pass a string).

Changes

  • Table/v1/index.tsx: getCaptionText returns non-string captions unchanged. aria-label and the live region text are only set when the caption is a string; the <caption> element still names the table.
  • Table/v1/__tests__/Table.test.tsx: add a sorted ReactNode caption test.

Test Plan

  • The new test fails on unpatched source ([object Object] Sorted by Foo (ascending)) and passes with the fix.
  • vitest --project browser packages/ui-table/src/Table/v1: 4 passed. ts:check clean for ui-table.

Not covered: the " Sorted by X (direction)" suffix is still hardcoded English for string captions. The function caption form is the localizable path.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.2

QR code for preview link

🚀 View preview at
https://instructure.design/pr-preview/pr-2836/

Built to branch gh-pages at 2026-12-02 15:38 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

github-actions Bot pushed a commit that referenced this pull request Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Visual regression report

Cypress suite: ✅ Passing

Visual diff: ✅ No changes.

Status Count
Unchanged 111
Changed 0
New 0
Removed 0

Accessibility (axe): ✅ No violations.

📊 View full report — click a screenshot's ⚠ badge to see each violation boxed on the image, with the offending element named and contrast failures shown as color swatches.

Baselines come from the visual-baselines branch. They refresh on every merge to master. The Cypress suite line covers the a11y and console-error assertions — a ❌ there means the suite found real issues even if the visual diff is clean.

`getCaptionText` cast `caption` to a string, so a sorted v1 Table with a
ReactNode caption rendered "[object Object] Sorted by Foo (ascending)"
into its <caption>, its aria-label and the live region announcement.

Return non-string captions unchanged, as the prop docs already say
("a plain ReactNode is rendered as-is and the sort state is ignored").
Only set aria-label and the live region text when the caption is a
string; the <caption> element still names the table.
@matyasf
matyasf force-pushed the fix/ui-table-element-caption branch from 5ee4b47 to 04a442b Compare December 2, 2026 15:34
@matyasf
matyasf self-requested a review December 2, 2026 15:35
@matyasf
matyasf requested a review from balzss December 2, 2026 15:35
@matyasf
matyasf merged commit 1712f02 into master Dec 2, 2026
11 checks passed
@matyasf
matyasf deleted the fix/ui-table-element-caption branch December 2, 2026 15:39
github-actions Bot pushed a commit that referenced this pull request Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants