Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/css/manage/_snippets-table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,27 @@
list-style: disc;
}

th.sortable a, th.sorted a {
th.sortable .list-table-sort-button,
th.sorted .list-table-sort-button {
display: flex;
flex-direction: row;
align-items: center;
inline-size: 100%;
margin: 0;
padding: 0;
border: none;
background: none;
font: inherit;
color: #2271b1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about the hard coded color #2271b1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm sure. It's our $accent color. We use this color in multiple places.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why not use the varable $accent?

cursor: pointer;
text-align: start;
}

th.sortable .list-table-sort-button:focus-visible,
th.sorted .list-table-sort-button:focus-visible {
outline: 2px solid #2271b1;
outline-offset: 2px;
border-radius: 2px;
}

.row-actions {
Expand Down Expand Up @@ -157,7 +175,6 @@

#wpbody-content & .column-name {
white-space: nowrap; /* prevents wrapping of snippet title */
vertical-align: top;
Comment thread
louiswol94 marked this conversation as resolved.
}

td.column-date, th.column-date {
Expand Down
41 changes: 26 additions & 15 deletions src/js/components/common/ListTable/TableHeadings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface TableHeadingsProps<T, K extends Key> extends Pick<ListTableProp
setSortDirection: Dispatch<SetStateAction<ListTableSortDirection>>
}

interface SortableColumnHeadingProps<T> {
interface SortableHeadingCellProps<T> {
column: ListTableColumn<T>
cellProps: ThHTMLAttributes<HTMLTableCellElement>
sortColumn: ListTableColumn<T> | undefined
Expand All @@ -22,11 +22,15 @@ interface SortableColumnHeadingProps<T> {
setSortDirection: Dispatch<SetStateAction<ListTableSortDirection>>
}

const SortableColumnHeading = <T, >({
column, cellProps, sortColumn, sortDirection, setSortColumn, setSortDirection
}: SortableColumnHeadingProps<T>) => {
const SortableHeadingCell = <T,>({
column,
cellProps,
sortColumn,
sortDirection,
setSortColumn,
setSortDirection
}: SortableHeadingCellProps<T>) => {
const isCurrent = column.id === sortColumn?.id

const nextSortDirection = isCurrent
? 'asc' === sortDirection ? 'desc' : 'asc'
: column.defaultSortDirection ?? 'asc'
Expand All @@ -39,11 +43,14 @@ const SortableColumnHeading = <T, >({
aria-sort={ariaSort}
className={classnames(cellProps.className, isCurrent ? 'sorted' : 'sortable', classDirection)}
>
<a href="#" onClick={event => {
event.preventDefault()
setSortColumn(column)
setSortDirection(nextSortDirection)
}}>
<button
type="button"
className="list-table-sort-button"
onClick={() => {
setSortColumn(column)
setSortDirection(nextSortDirection)
}}
>
<span>{column.title}</span>
<span className="sorting-indicators">
<span className="sorting-indicator asc" aria-hidden="true"></span>
Expand All @@ -54,7 +61,7 @@ const SortableColumnHeading = <T, >({
{/* translators: Hidden accessibility text. */}
{'asc' === nextSortDirection ? __('Sort ascending.', 'code-snippets') : __('Sort descending.', 'code-snippets')}
</span>}
</a>
</button>
</th>
)
}
Expand Down Expand Up @@ -87,7 +94,6 @@ export const TableHeadings = <T, K extends Key>({
{columns.map(column => {
const cellProps: ThHTMLAttributes<HTMLTableCellElement> = {
id: 'head' === which ? column.id.toString() : undefined,
key: column.id,
scope: 'col',
className: classnames(
'manage-column',
Expand All @@ -97,8 +103,13 @@ export const TableHeadings = <T, K extends Key>({
)
}

return column.sortedValue
? <SortableColumnHeading {...{ column, cellProps, sortColumn, sortDirection, setSortColumn, setSortDirection }} />
: <th {...cellProps}>{column.title}</th>
if (!column.sortedValue) {
return <th key={column.id} {...cellProps}>{column.title}</th>
}

return <SortableHeadingCell
key={column.id}
{...{ column, cellProps, sortColumn, sortDirection, setSortColumn, setSortDirection }}
/>
})}
</tr>
Loading