Skip to content

Commit

Permalink
Add rudimentary support for table block cell scope attributes (#16154)
Browse files Browse the repository at this point in the history
* Add rudimentary support for table block cell scope attributes

* Incorporate testing for scope property on table cells into full-content test

* Revert "Incorporate testing for scope property on table cells into full-content test"

This reverts commit 2805d1e.

* Use separate fixture for table scope tests

* Ensure scope cannot be used on td elements

* Attempt to get block transforms tests to pass
  • Loading branch information
talldan authored and ellatrix committed Jul 4, 2019
1 parent 907c96b commit 367480b
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 2 deletions.
15 changes: 15 additions & 0 deletions packages/block-library/src/table/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"type": "string",
"default": "td",
"source": "tag"
},
"scope": {
"type": "string",
"source": "attribute",
"attribute": "scope"
}
}
}
Expand All @@ -54,6 +59,11 @@
"type": "string",
"default": "td",
"source": "tag"
},
"scope": {
"type": "string",
"source": "attribute",
"attribute": "scope"
}
}
}
Expand All @@ -79,6 +89,11 @@
"type": "string",
"default": "td",
"source": "tag"
},
"scope": {
"type": "string",
"source": "attribute",
"attribute": "scope"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/table/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export class TableEdit extends Component {
<Tag>
{ rows.map( ( { cells }, rowIndex ) => (
<tr key={ rowIndex }>
{ cells.map( ( { content, tag: CellTag }, columnIndex ) => {
{ cells.map( ( { content, tag: CellTag, scope }, columnIndex ) => {
const isSelected = selectedCell && (
type === selectedCell.section &&
rowIndex === selectedCell.rowIndex &&
Expand All @@ -382,6 +382,7 @@ export class TableEdit extends Component {
<CellTag
key={ columnIndex }
className={ cellClasses }
scope={ CellTag === 'th' ? scope : undefined }
>
<RichText
className="wp-block-table__cell-content"
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/table/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ export default function save( { attributes } ) {
<Tag>
{ rows.map( ( { cells }, rowIndex ) => (
<tr key={ rowIndex }>
{ cells.map( ( { content, tag }, cellIndex ) =>
{ cells.map( ( { content, tag, scope }, cellIndex ) =>
<RichText.Content
tagName={ tag }
value={ content }
key={ cellIndex }
scope={ tag === 'th' ? scope : undefined }
/>
) }
</tr>
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/table/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const tableContentPasteSchema = {
th: {
allowEmpty: true,
children: getPhrasingContentSchema(),
attributes: [ 'scope' ],
},
td: {
allowEmpty: true,
Expand Down
6 changes: 6 additions & 0 deletions packages/e2e-tests/fixtures/block-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ export const EXPECTED_TRANSFORMS = {
'Group',
],
},
'core__table__scope-attribute': {
originalBlock: 'Table',
availableTransforms: [
'Group',
],
},
'core__tag-cloud': {
originalBlock: 'Tag Cloud',
availableTransforms: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- 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>
<!-- /wp:table -->
148 changes: 148 additions & 0 deletions packages/e2e-tests/fixtures/blocks/core__table__scope-attribute.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
[
{
"clientId": "_clientId_0",
"name": "core/table",
"isValid": true,
"attributes": {
"hasFixedLayout": false,
"head": [
{
"cells": [
{
"content": "Version",
"tag": "th",
"scope": "col"
},
{
"content": "Musician",
"tag": "th",
"scope": "col"
},
{
"content": "Date",
"tag": "th",
"scope": "col"
}
]
}
],
"body": [
{
"cells": [
{
"content": "<a href=\"https://wordpress.org/news/2003/05/wordpress-now-available/\">.70</a>",
"tag": "td"
},
{
"content": "No musician chosen.",
"tag": "td"
},
{
"content": "May 27, 2003",
"tag": "td"
}
]
},
{
"cells": [
{
"content": "<a href=\"https://wordpress.org/news/2004/01/wordpress-10/\">1.0</a>",
"tag": "td"
},
{
"content": "Miles Davis",
"tag": "td"
},
{
"content": "January 3, 2004",
"tag": "td"
}
]
},
{
"cells": [
{
"content": "Lots of versions skipped, see <a href=\"https://codex.wordpress.org/WordPress_Versions\">the full list</a>",
"tag": "td"
},
{
"content": "",
"tag": "td"
},
{
"content": "",
"tag": "td"
}
]
},
{
"cells": [
{
"content": "<a href=\"https://wordpress.org/news/2015/12/clifford/\">4.4</a>",
"tag": "td"
},
{
"content": "Clifford Brown",
"tag": "td"
},
{
"content": "December 8, 2015",
"tag": "td"
}
]
},
{
"cells": [
{
"content": "<a href=\"https://wordpress.org/news/2016/04/coleman/\">4.5</a>",
"tag": "td"
},
{
"content": "Coleman Hawkins",
"tag": "td"
},
{
"content": "April 12, 2016",
"tag": "td"
}
]
},
{
"cells": [
{
"content": "<a href=\"https://wordpress.org/news/2016/08/pepper/\">4.6</a>",
"tag": "td"
},
{
"content": "Pepper Adams",
"tag": "td"
},
{
"content": "August 16, 2016",
"tag": "td"
}
]
},
{
"cells": [
{
"content": "<a href=\"https://wordpress.org/news/2016/12/vaughan/\">4.7</a>",
"tag": "td"
},
{
"content": "Sarah Vaughan",
"tag": "td"
},
{
"content": "December 6, 2016",
"tag": "td"
}
]
}
],
"foot": []
},
"innerBlocks": [],
"originalContent": "<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>"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"blockName": "core/table",
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n<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>\n",
"innerContent": [
"\n<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>\n"
]
},
{
"blockName": null,
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n",
"innerContent": [
"\n"
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- 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>
<!-- /wp:table -->

0 comments on commit 367480b

Please sign in to comment.