-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 table block caption #15554
Add table block caption #15554
Changes from all commits
9aaa961
3e05aff
1793afb
8f5d4ec
65e2063
91c3e80
0265104
f3ae751
a0adac7
9181248
6474a17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -483,9 +483,16 @@ export class TableEdit extends Component { | |
className, | ||
backgroundColor, | ||
setBackgroundColor, | ||
setAttributes, | ||
} = this.props; | ||
const { initialRowCount, initialColumnCount } = this.state; | ||
const { hasFixedLayout, head, body, foot } = attributes; | ||
const { | ||
hasFixedLayout, | ||
caption, | ||
head, | ||
body, | ||
foot, | ||
} = attributes; | ||
const isEmpty = isEmptyTableSection( head ) && isEmptyTableSection( body ) && isEmptyTableSection( foot ); | ||
const Section = this.renderSection; | ||
|
||
|
@@ -582,6 +589,14 @@ export class TableEdit extends Component { | |
<Section name="body" rows={ body } /> | ||
<Section name="foot" rows={ foot } /> | ||
</table> | ||
<RichText | ||
tagName="figcaption" | ||
placeholder={ __( 'Write caption…' ) } | ||
value={ caption } | ||
onChange={ ( value ) => setAttributes( { caption: value } ) } | ||
// Deselect the selected table cell when the caption is focused. | ||
unstableOnFocus={ () => this.setState( { selectedCell: null } ) } | ||
/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't like this hack with the separate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not wrap the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Would love you to have a look at #17607, which will allow the table block to omit the wrapper div. |
||
</figure> | ||
</> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,8 @@ | |
border: 1px solid; | ||
word-break: normal; | ||
} | ||
|
||
figcaption { | ||
@include caption-style-theme(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"isValid": true, | ||
"attributes": { | ||
"hasFixedLayout": false, | ||
"caption": "", | ||
"head": [ | ||
{ | ||
"cells": [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!-- wp:core/table --> | ||
<figure class="wp-block-table"><table class=""><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><figcaption>A table for testing</figcaption></figure> | ||
<!-- /wp:core/table --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
[ | ||
{ | ||
"clientId": "_clientId_0", | ||
"name": "core/table", | ||
"isValid": true, | ||
"attributes": { | ||
"hasFixedLayout": false, | ||
"caption": "A table for testing", | ||
"head": [ | ||
{ | ||
"cells": [ | ||
{ | ||
"content": "Version", | ||
"tag": "th" | ||
}, | ||
{ | ||
"content": "Musician", | ||
"tag": "th" | ||
}, | ||
{ | ||
"content": "Date", | ||
"tag": "th" | ||
} | ||
] | ||
} | ||
], | ||
"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": "<figure class=\"wp-block-table\"><table class=\"\"><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><figcaption>A table for testing</figcaption></figure>" | ||
} | ||
] |
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.
Would it be possible to filter out the new attributes, instead of duplicating the whole object?
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'm not a fan of that approach as it seems quite error prone for someone adding a new deprecation or attribute. Once these attributes are defined for a deprecation ideally they won't ever change.