fix(core): add scope="col" to Table column headers#3715
Merged
Conversation
|
@bhamodi is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
ca8fb78 to
1045d87
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BaseTablerenders every column header as a bare<th>with noscope. Inpackages/core/src/Table/BaseTable.tsxthe per-columninitialHeaderHtmlProps(around line 375) set onlydata-column-key(plus an optionaltextAlignstyle) —scopewas never emitted, even thoughTableHeaderCell(packages/core/src/Table/TableHeaderCell.tsx:40) already declaresscope?: 'col' | 'row' | 'colgroup' | 'rowgroup'and forwards it to the<th>.Without
scope="col", assistive technology has to guess how header cells relate to data cells. Explicitscopeis the reliable, spec-blessed association: it satisfies WCAG 2.1 SC 1.3.1 Info and Relationships (Level A) via technique H63 (using thescopeattribute to associate header and data cells), and matches the ARIA APG data-grid expectation that column headers carry thecolumnheadersemantics.The fix defaults
scope: 'col'ininitialHeaderHtmlProps, so every column header renders<th scope="col">.Merge order / override
initialHeaderHtmlPropsis the initial value fed into thetransformHeaderCellplugin pipeline, which runs before the props are merged onto the<th>. A plugin that writeshtmlProps.scopespreads over the default ({...props.htmlProps, scope: ...}), and that value is preserved through the finalmergedHtmlPropsspread and forwarded byTableHeaderCell. So a consumer-providedscopestill wins. The new override test locks this in.Changes
packages/core/src/Table/BaseTable.tsx: defaultscope: 'col'ininitialHeaderHtmlProps.packages/core/src/Table/Table.test.tsx: added two tests underBaseTable— one asserting everycolumnheaderhasscope="col", one asserting a plugin'stransformHeaderCellscope override wins (queried viathead thsince<th scope="row">resolves to therowheaderrole, notcolumnheader).Test plan
node_modules/.bin/vitest run --root . packages/core/src/Table— 338 pass (16 files), including the 2 new tests (was 336).getAttribute("scope") === nullon the default headers), proving they catch the gap. The override test's first assertion (plugin-setscope="row") passed pre-fix, confirming the plugin scope already flows through the merge.tsc --project packages/core/tsconfig.json --noEmit— clean.eslint packages/core/src/Table/BaseTable.tsx packages/core/src/Table/Table.test.tsx— clean.Notes
Found during a broader a11y audit of the Table component. Scoped to this one fix — separate findings (e.g. caption/label props, row-expansion semantics) are intentionally left out.
Table.doc.mjsdoesn't document headerscopesemantics, so no doc change was needed.