Skip to content

Commit

Permalink
Try using a figcaption for the table caption
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed May 10, 2019
1 parent 42623d6 commit b5f00dd
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 43 deletions.
2 changes: 1 addition & 1 deletion packages/block-library/src/table/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"caption": {
"type": "string",
"source": "html",
"selector": "caption"
"selector": "figcaption"
},
"head": {
"type": "array",
Expand Down
32 changes: 17 additions & 15 deletions packages/block-library/src/table/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,21 +488,23 @@ export class TableEdit extends Component {
] }
/>
</InspectorControls>
<table className={ classes }>
<caption>{ caption }</caption>
<Section type="head" rows={ head } />
<Section type="body" rows={ body } />
<Section type="foot" rows={ foot } />
</table>
<RichText
className={ classnames( 'wp-block-table__caption-content', {
'is-visible': isSelected || caption,
} ) }
tagName="p"
placeholder={ __( 'Write caption…' ) }
value={ caption }
onChange={ ( value ) => setAttributes( { caption: value } ) }
/>
<figure className={ classes }>
<table>
<Section type="head" rows={ head } />
<Section type="body" rows={ body } />
<Section type="foot" rows={ foot } />
</table>
<RichText
className={ classnames( 'wp-block-table__caption', {
'is-visible': isSelected || caption,
} ) }
tagName="figcaption"
aria-label={ __( 'Edit caption' ) }
placeholder={ __( 'Write caption…' ) }
value={ caption }
onChange={ ( value ) => setAttributes( { caption: value } ) }
/>
</figure>
</>
);
}
Expand Down
7 changes: 1 addition & 6 deletions packages/block-library/src/table/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@
padding: 0.5em;
}

caption {
visibility: hidden;
height: 0;
}

&__caption-content {
&__caption {
@include caption-style-theme();
overflow: hidden;
height: 0;
Expand Down
14 changes: 8 additions & 6 deletions packages/block-library/src/table/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ export default function save( { attributes } ) {
};

return (
<table className={ classes }>
{ !! caption && <RichText.Content tagName="caption" value={ caption } /> }
<Section type="head" rows={ head } />
<Section type="body" rows={ body } />
<Section type="foot" rows={ foot } />
</table>
<figure>
<table className={ classes }>
<Section type="head" rows={ head } />
<Section type="body" rows={ body } />
<Section type="foot" rows={ foot } />
</table>
<RichText.Content tagName="figcaption" value={ caption } />
</figure>
);
}
26 changes: 14 additions & 12 deletions packages/block-library/src/table/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@
&.alignleft,
&.aligncenter,
&.alignright {
// Override default display property for align styles.
// The table element needs to be kept as display table
// for table features to work reliably.
display: table;

// Table cannot be 100% width if it is aligned, so set
// width as auto.
width: auto;
table {
// Table cannot be 100% width if it is aligned, so set
// width as auto.
width: auto;
}
}

&.has-subtle-light-gray-background-color {
Expand All @@ -41,9 +38,12 @@

// "Stripes" style variation.
&.is-style-stripes {
border-spacing: 0;
border-collapse: inherit;
background-color: transparent;
table {
border-spacing: 0;
border-collapse: inherit;
background-color: transparent;
border-bottom: 1px solid $light-gray-200;
}

tbody tr:nth-child(odd) {
background-color: $light-gray-200;
Expand Down Expand Up @@ -77,7 +77,9 @@
td {
border-color: transparent;
}
}

border-bottom: 1px solid $light-gray-200;
figure {
margin: 0;
}
}
8 changes: 5 additions & 3 deletions packages/block-library/src/table/theme.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.wp-block-table {
width: 100%;
min-width: $break-mobile / 2;
border-collapse: collapse;
table {
width: 100%;
min-width: $break-mobile / 2;
border-collapse: collapse;
}

td,
th {
Expand Down

0 comments on commit b5f00dd

Please sign in to comment.