Skip to content

Commit

Permalink
Use table layout in templates list screen (#36707)
Browse files Browse the repository at this point in the history
* Use table layout

* Add explicit aria roles

* Add comments
  • Loading branch information
kevin940726 authored and noisysocks committed Nov 28, 2021
1 parent e803792 commit 3b1943a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 38 deletions.
23 changes: 13 additions & 10 deletions packages/edit-site/src/components/list/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
margin: 0;
overflow: hidden;

li {
tr {
display: flex;
align-items: center;
padding: $grid-unit-20;
Expand All @@ -78,36 +78,39 @@
padding: $grid-unit-30 $grid-unit-40;
}

// Template.
.edit-site-list-table-column:nth-child(1) {
width: calc(60% - 36px);
flex-grow: 1;
display: flex;
flex-direction: column;
align-items: flex-start;

a {
display: block;
display: inline-block;
text-decoration: none;
font-weight: 500;
margin-bottom: $grid-unit-05;
}
}

// Added by.
.edit-site-list-table-column:nth-child(2) {
width: calc(40% - 36px);
}

// Actions.
.edit-site-list-table-column:nth-child(3) {
min-width: $button-size;
flex-shrink: 0;
}
}

li.edit-site-list-table-head {
border-bottom: $border-width solid $gray-200;
tr.edit-site-list-table-head {
font-size: 16px;
font-weight: 500;
font-weight: 600;
text-align: left;
color: $black;
color: #050505;
border-top: none;

& + li {
border-top: 0;
}
}
}
70 changes: 42 additions & 28 deletions packages/edit-site/src/components/list/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { store as coreStore } from '@wordpress/core-data';
import { __, sprintf } from '@wordpress/i18n';
import {
VisuallyHidden,
FlexItem,
__experimentalHStack as HStack,
__experimentalHeading as Heading,
DropdownMenu,
MenuGroup,
MenuItem,
Expand Down Expand Up @@ -77,23 +74,40 @@ export default function Table( { templateType } ) {
}

return (
<ul className="edit-site-list-table">
<HStack className="edit-site-list-table-head" as="li">
<FlexItem className="edit-site-list-table-column">
<Heading level={ 4 }>{ __( 'Template' ) }</Heading>
</FlexItem>
<FlexItem className="edit-site-list-table-column">
<Heading level={ 4 }>{ __( 'Added by' ) }</Heading>
</FlexItem>
<FlexItem className="edit-site-list-table-column">
<VisuallyHidden>{ __( 'Actions' ) }</VisuallyHidden>
</FlexItem>
</HStack>
// These explicit aria roles are needed for Safari.
// See https://developer.mozilla.org/en-US/docs/Web/CSS/display#tables
<table className="edit-site-list-table" role="table">
<thead>
<tr className="edit-site-list-table-head" role="row">
<th
className="edit-site-list-table-column"
role="columnheader"
>
{ __( 'Template' ) }
</th>
<th
className="edit-site-list-table-column"
role="columnheader"
>
{ __( 'Added by' ) }
</th>
<th
className="edit-site-list-table-column"
role="columnheader"
>
<VisuallyHidden>{ __( 'Actions' ) }</VisuallyHidden>
</th>
</tr>
</thead>

{ templates.map( ( template ) => (
<li key={ template.id }>
<HStack className="edit-site-list-table-row">
<FlexItem className="edit-site-list-table-column">
<tbody>
{ templates.map( ( template ) => (
<tr
key={ template.id }
className="edit-site-list-table-row"
role="row"
>
<td className="edit-site-list-table-column" role="cell">
<a
href={ addQueryArgs( window.location.href, {
postId: template.id,
Expand All @@ -103,12 +117,12 @@ export default function Table( { templateType } ) {
{ template.title.rendered }
</a>
{ template.description }
</FlexItem>
</td>

<FlexItem className="edit-site-list-table-column">
<td className="edit-site-list-table-column" role="cell">
{ template.theme }
</FlexItem>
<FlexItem className="edit-site-list-table-column">
</td>
<td className="edit-site-list-table-column" role="cell">
{ isTemplateRemovable( template ) && (
<DropdownMenu
icon={ moreVertical }
Expand All @@ -123,10 +137,10 @@ export default function Table( { templateType } ) {
) }
</DropdownMenu>
) }
</FlexItem>
</HStack>
</li>
) ) }
</ul>
</td>
</tr>
) ) }
</tbody>
</table>
);
}

0 comments on commit 3b1943a

Please sign in to comment.