-
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
Make tables accessible at high zoom levels #16324
Changes from all commits
59f5581
1568a29
c63d77b
d70a446
7bc57f9
0331420
c42a622
fc5b4f7
1d54bf2
caf8d1c
d0b7651
f8d31dc
7519de8
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { RichText, getColorClassName } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
|
||
const supports = { | ||
align: true, | ||
}; | ||
|
||
const deprecated = [ | ||
{ | ||
attributes: metadata.attributes, | ||
supports, | ||
save( { attributes } ) { | ||
const { | ||
hasFixedLayout, | ||
head, | ||
body, | ||
foot, | ||
backgroundColor, | ||
} = attributes; | ||
const isEmpty = ! head.length && ! body.length && ! foot.length; | ||
|
||
if ( isEmpty ) { | ||
return null; | ||
} | ||
|
||
const backgroundClass = getColorClassName( 'background-color', backgroundColor ); | ||
|
||
const classes = classnames( backgroundClass, { | ||
'has-fixed-layout': hasFixedLayout, | ||
'has-background': !! backgroundClass, | ||
} ); | ||
|
||
const Section = ( { type, rows } ) => { | ||
if ( ! rows.length ) { | ||
return null; | ||
} | ||
|
||
const Tag = `t${ type }`; | ||
|
||
return ( | ||
<Tag> | ||
{ rows.map( ( { cells }, rowIndex ) => ( | ||
<tr key={ rowIndex }> | ||
{ cells.map( ( { content, tag, scope }, cellIndex ) => | ||
<RichText.Content | ||
tagName={ tag } | ||
value={ content } | ||
key={ cellIndex } | ||
scope={ tag === 'th' ? scope : undefined } | ||
/> | ||
) } | ||
</tr> | ||
) ) } | ||
</Tag> | ||
); | ||
}; | ||
|
||
return ( | ||
<table className={ classes }> | ||
<Section type="head" rows={ head } /> | ||
<Section type="body" rows={ body } /> | ||
<Section type="foot" rows={ foot } /> | ||
</table> | ||
); | ||
}, | ||
}, | ||
]; | ||
|
||
export default deprecated; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,21 @@ | |
$subtle-pale-blue: #e7f5fe; | ||
$subtle-pale-pink: #fcf0ef; | ||
|
||
overflow-x: auto; | ||
|
||
table { | ||
width: 100%; | ||
} | ||
|
||
// Fixed layout toggle | ||
&.has-fixed-layout { | ||
.has-fixed-layout { | ||
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. Seeing some inconsistencies between the editor and the post when it comes to the fixed layout. The editor seems to wrap long text, but when viewing the post text isn't wrapped. 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. Fixed 😅 |
||
table-layout: fixed; | ||
width: 100%; | ||
|
||
td, | ||
th { | ||
word-break: break-all; | ||
} | ||
} | ||
|
||
&.alignleft, | ||
|
@@ -17,25 +28,30 @@ | |
// The table element needs to be kept as display table | ||
// for table features to work reliably. | ||
display: table; | ||
|
||
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. ❤️ |
||
// Table cannot be 100% width if it is aligned, so set | ||
// width as auto. | ||
width: auto; | ||
|
||
td, | ||
th { | ||
// Aligned tables shouldn't scroll horizontally so we need their contents to wrap. | ||
word-break: break-all; | ||
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 is this needed? Does it deserve a comment? 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. Assuming we don't want tables to horizontally scroll when they are aligned, we need table content to break. Added comment. |
||
} | ||
} | ||
|
||
&.has-subtle-light-gray-background-color { | ||
.has-subtle-light-gray-background-color { | ||
background-color: $subtle-light-gray; | ||
} | ||
|
||
&.has-subtle-pale-green-background-color { | ||
.has-subtle-pale-green-background-color { | ||
background-color: $subtle-pale-green; | ||
} | ||
|
||
&.has-subtle-pale-blue-background-color { | ||
.has-subtle-pale-blue-background-color { | ||
background-color: $subtle-pale-blue; | ||
} | ||
|
||
&.has-subtle-pale-pink-background-color { | ||
.has-subtle-pale-pink-background-color { | ||
background-color: $subtle-pale-pink; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
.wp-block-table { | ||
width: 100%; | ||
min-width: $break-mobile / 2; | ||
border-collapse: collapse; | ||
|
||
td, | ||
th { | ||
padding: 0.5em; | ||
border: 1px solid; | ||
word-break: break-all; | ||
word-break: normal; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<!-- wp:core/table --> | ||
<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> | ||
<figure class="wp-block-table"><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></figure> | ||
<!-- /wp:core/table --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<!-- wp:table --> | ||
<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> | ||
<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></figure> | ||
<!-- /wp:table --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!-- wp:core/table --> | ||
<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 --> |
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 be great to add a test fixture for this deprecation. There are some examples of them in the folder with the fixtures (some have
__deprecated
in the filename):https://github.com/WordPress/gutenberg/tree/master/packages/e2e-tests/fixtures/blocks
It should just be a matter of grabbing the block HTML from
master
(including the comment delimeters) and pasting it into a new html file, then regenerating the fixtures. If the deprecation works it'll output a valid block.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.
Done, thanks for the reminder!