[v10] Add option to make tables sortable#1654
[v10] Add option to make tables sortable#1654colinrotherham wants to merge 29 commits intosupport/10.xfrom
Conversation
7fcc8c4 to
724441e
Compare
|
Question of icons…
On the later point, when I was using sortable tables in my service, I used the following SVG: <svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 27 27">
<path fill="#212b32" d="m13 18.6-7-7.2c-.6-.5-.6-1.4 0-2 .5-.5 1.3-.5 2 0l6 6.2 6-6.2c.7-.5 1.5-.5 2 0 .6.6.6 1.5 0 2l-7 7.2c-.3.3-.6.4-1 .4s-.7-.1-1-.4Z"/>
</svg> |
724441e to
72a2926
Compare
Task list does the same. On the other hand the combined logo + service name link in the header has the focus style cover the whole clickable area, including the logo. |
|
Probably need an audit of focus styles… part of me wants to suggest making focus styles big and obvious, now that Firefox doesn’t show them on click (or can at least be avoided) |
|
Seems all the other components expand the click area by placing an absolutely positioned I've now removed that so that the focus is placed only on the natural sized buttons, and added a hover state to the header cells to illustrate how I'd like them to be, but of course this doesn't trigger the buttons. Can someone help me add a click event to the table heads? Or maybe there's a better way? I also notice a possible slight bug where the |
There's an event listener on the this.$head.addEventListener('click', this.onSortButtonClick.bind(this))But later on you'll see it ignores all clicks unless it bubbled up from a onSortButtonClick(event) {
const $target = /** @type {HTMLElement} */ (event.target)
const $button = $target.closest('button')
if (!$button?.parentElement) {
return
}
// …
}In theory you could change this code to allow clicks from non-clickable things But we shouldn't do really Is it a bad thing that only the |
76b6c3b to
1c1d476
Compare
|
Rebased with Table examples will now be in |
The MOJ one doesn't have any hover state. We’ve added a hover state (background colour change to grey) for the whole Would one option be to make button size expand to fill the entirety of the I also just spotted that the task list rows are using |
This is what I had first, which kinda worked but relied on some hacky CSS to get the button to grow to fill the I'm not sure on the best approach from a frontend dev perspective but what I want to achieve is the whole
Ohh, well spotted, will need to take a look at this. I think I was using pagination as my reference. |
|
@anandamaryon1 the task list trick is to use this to generate a bigger click area, but then the focus background colour only applies to the smaller .nhsuk-task-list__link::after {
content: "";
display: block;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}Bit of a hack but it seems to work?! There might be a better way though. |
1c1d476 to
42bd4e4
Compare
|
Sorry for the rebase, but I've updated this branch to pick up the new status check names |
This will just be using the regular table component
This lets us add a small amount of padding to the table headers
30fe6af to
4b17d95
Compare
|
@frankieroberto @anandamaryon1 I've updated this PR to target v10.x Can you please check the "link" colours and update if needed? Good to get this out sooner rather than later
|
|
|
Yep the link colours are OK for now (pre-v11). I don't think we need to change the "active" border-bottom colour, it can stay blue. We're doing pilot testing and UR on this over the next few weeks, so can't say yet whether it'll be v10 or v11 when it's ready to release. |










Description
This expands the existing Table component to enable a new option to make some or all of the columns sortable by clicking the column header.
This is partly inspired by sortable table component from MOJ Frontend.
The table sorting feature is done using JavaScript as a progressive enhancement. If javascript is unavailable or not supported, then the table remains in its initial state, and no sort buttons are added.
It works by adding
aria-sortattributes to the headers of columns that you want to be sortable.The
aria-sortattribute should be set toascendingordescendingon the 1 column which is initially sorted, andnoneon all other columns that you want to be sortable:By default, the JavaScript will sort the column numerically if all cells contain a number, or will otherwise sort them alphabetically (or reverse-alphabetical).
If you need to specify an alternative sort order, you can do this by setting
data-sort-valueattributes on individual cells:Screenshots
Checklist