-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rudimentary support for table block cell scope attributes #16154
Conversation
a935166
to
2805d1e
Compare
@@ -10,6 +10,7 @@ const tableContentPasteSchema = { | |||
th: { | |||
allowEmpty: true, | |||
children: getPhrasingContentSchema(), | |||
attributes: [ 'scope' ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://www.w3schools.com/tags/att_td_scope.asp it seems scope attribute can also be used on td elements. Should we also add attributes: [ 'scope' ]
, to td? Currently when we paste a table with a scope on td elements the scope gets removed if we manually add a scope in the code editor it is persisted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @jorgefilipecosta. It does say on that page The <td> scope attribute is not supported in HTML5.
I think it might be better not to encourage future use of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I should make sure the attribute can't be output on td
s in both the save and edit functions as well 🤔.
I'll add another commit, should be easy to do.
<table class="wp-block-table"><thead><tr><th>Version</th><th>Musician</th><th>Date</th></tr></thead><tbody><tr><td><a href="https://wordpress.org/news/2003/05/wordpress-now-available/">.70</a></td><td>No musician chosen.</td><td>May 27, 2003</td></tr><tr><td><a href="https://wordpress.org/news/2004/01/wordpress-10/">1.0</a></td><td>Miles Davis</td><td>January 3, 2004</td></tr><tr><td>Lots of versions skipped, see <a href="https://codex.wordpress.org/WordPress_Versions">the full list</a></td><td>…</td><td>…</td></tr><tr><td><a href="https://wordpress.org/news/2015/12/clifford/">4.4</a></td><td>Clifford Brown</td><td>December 8, 2015</td></tr><tr><td><a href="https://wordpress.org/news/2016/04/coleman/">4.5</a></td><td>Coleman Hawkins</td><td>April 12, 2016</td></tr><tr><td><a href="https://wordpress.org/news/2016/08/pepper/">4.6</a></td><td>Pepper Adams</td><td>August 16, 2016</td></tr><tr><td><a href="https://wordpress.org/news/2016/12/vaughan/">4.7</a></td><td>Sarah Vaughan</td><td>December 6, 2016</td></tr></tbody></table> | ||
<!-- /wp:core/table --> | ||
<!-- wp:table --> | ||
<table class="wp-block-table"><thead><tr><th scope="col">Version</th><th scope="col">Musician</th><th scope="col">Date</th></tr></thead><tbody><tr><td><a href="https://wordpress.org/news/2003/05/wordpress-now-available/">.70</a></td><td>No musician chosen.</td><td>May 27, 2003</td></tr><tr><td><a href="https://wordpress.org/news/2004/01/wordpress-10/">1.0</a></td><td>Miles Davis</td><td>January 3, 2004</td></tr><tr><td>Lots of versions skipped, see <a href="https://codex.wordpress.org/WordPress_Versions">the full list</a></td><td>…</td><td>…</td></tr><tr><td><a href="https://wordpress.org/news/2015/12/clifford/">4.4</a></td><td>Clifford Brown</td><td>December 8, 2015</td></tr><tr><td><a href="https://wordpress.org/news/2016/04/coleman/">4.5</a></td><td>Coleman Hawkins</td><td>April 12, 2016</td></tr><tr><td><a href="https://wordpress.org/news/2016/08/pepper/">4.6</a></td><td>Pepper Adams</td><td>August 16, 2016</td></tr><tr><td><a href="https://wordpress.org/news/2016/12/vaughan/">4.7</a></td><td>Sarah Vaughan</td><td>December 6, 2016</td></tr></tbody></table> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, the scope is not added, I feel by default the test fixture should also not contain scope attributes. What if we add a dedicated fixture to test table scopes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I've moved the test into its own fixture.
Managed to get the tests to pass (realised I had to clear both the master and PR cache in travis), so hopefully this one is good to go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great.
Description
Related #15283
Currently, if a user tries to paste table html that includes the scope attribute on table cells, this content is stripped out by Gutenberg.
As mentioned in #15283, the scope attributes are import for users of accessibility software as they help inform the context of a table cell.
While this PR doesn't expose any UI capability for editing this attribute (apart from the HTML editor), it at least ensures gutenberg doesn't worsen the accessibility of tables pasted into it or edited manually.
How has this been tested?
Updated
full-content
tests to include this attribute.Manual testing:
Pasting
th
element correctly retains thescope
attributeth
element correctly retains thescope
attributeEditing HTML
scope="col"
attribute to the firstth
elementth
element correctly retains thescope
attributeth
element correctly retains thescope
attributeScreenshots
Types of changes
New feature (non-breaking change which adds functionality)
Checklist: