core/table Improve accessibility with semantic HTML and scope attributes#72582
core/table Improve accessibility with semantic HTML and scope attributes#72582firestar300 wants to merge 4 commits intoWordPress:trunkfrom
core/table Improve accessibility with semantic HTML and scope attributes#72582Conversation
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @firestar300! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
core/table Improve accessibility with semantic HTML and scope attributes
Adds a setting to allow users to position the table caption either at the top or bottom of the table. This change also migrates the caption element from <figcaption> to <caption> for improved accessibility.
Ensures that table header cells have the `scope` attribute set, improving accessibility by explicitly associating headers with their corresponding data cells. This enhancement is crucial for users relying on assistive technologies, as it provides semantic information about the table structure.
99bdc60 to
239ec04
Compare
Adds the `scope="col"` attribute to table header cells in the block's test state. This ensures that screen readers can correctly announce the column header for each cell, improving accessibility. Also updates e2e snapshots to reflect the changes.
239ec04 to
ca85d95
Compare
Adds the `scope="col"` attribute to table header cells (``) within the table header section if it's missing, enhancing accessibility. This ensures that screen readers can correctly announce the column headers for each cell, improving the user experience for users with disabilities.
|
Thanks for the contribution. I personally think it'd be good to break this PR up into smaller PRs - one per issue mentioned rather than a big PR that tries to solve it all at ones. Some of the changes here might be easier to ship than others. But also not everything in this PR is related (they're all a11y fixes, but I've tested the PR, and I think some of my concerns about using
This issue has been around a long time, it'd definitely be great to finally solve it. Sorry that I'm mostly mentioning problems! I personally think keeping the figure/figcaption and using Another option could be to make the block's markup different on the frontend and keeping the figcaption in the editor. |
|
Hi @talldan , Thank you for the thorough review. Summary of Key IssuesBased on your feedback, I now understand the main problems with the current approach:
Proposed Path ForwardPR 1: Add
|
What?
Improves accessibility of the Table block by adding proper semantic HTML structure and ARIA attributes.
Closes #72490
This PR implements three key accessibility improvements:
<figcaption>to<caption>element inside the<table>scope="col"attribute to header cells in<thead>scopeattribute when pasting HTML tablesWhy?
The Table block had several accessibility issues that prevented screen reader users from properly understanding table structure and relationships:
Issue 1: Incorrect caption element
<figcaption>outside the<table>element<caption>inside the<table>elementIssue 2: Missing
scopeattribute on header cells<th>elements had noscopeattribute<th>elements in<thead>now havescope="col"Screen reader experience comparison:
How?
1. Modified
save.jsandedit.js:<figcaption>(outside table) to<caption>(inside table)2. Modified
transforms.js:scopeattribute when pasting HTML tablesscopeattribute is now preserved alongside other attributes likecolspan,rowspan, andalign3. Modified
state.js:insertRow()function to automatically addscope="col"to<th>cells in<thead>sectionsinsertColumn()function to automatically addscope="col"to<th>cells in<thead>sections<tfoot>continues to use<td>cells by default (appropriate for notes and contextual information)4. Added caption position control:
captionSideattribute to store the caption position preferencestyle.scssto use the CSScaption-sideproperty.has-caption-topclass is applied to the figure wrapper, positioning the caption above the tablecaption-sideproperty ensures the caption is properly associated with the table regardless of visual positionTesting Instructions
Test 1: Caption element position
<caption>should be inside the<table>element (not as a sibling<figcaption>)Test 2: Creating a new table with header section
Test 3: Adding columns/rows to existing header section
<th>in the header section also hasscope="col"Test 4: Pasting HTML tables
<caption>andscope="col"attributes have been preservedTest 5: Caption position control
has-caption-top:has-caption-topclass is presentTesting Instructions for Keyboard
Screen Reader Testing (Recommended)
Markup
Before
After
Screenshots