Skip to content
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

va-table: add sorting variation #1358

Merged
merged 17 commits into from
Oct 23, 2024
Merged

va-table: add sorting variation #1358

merged 17 commits into from
Oct 23, 2024

Conversation

it-harrison
Copy link
Contributor

@it-harrison it-harrison commented Oct 7, 2024

Chromatic

https://sortable-table--65a6e2ed2314f7b8f98609d8.chromatic.com


Description

This PR makes the va-table sortable by means of a sortable prop.
Key points:

  • the table can be sorted asc/desc by any column so long as the data in the column is numeric, date, or string
  • the data projected into each table slot must be a string, not a component

Closes 2771

QA Checklist

  • Component maintains 1:1 parity with design mocks
  • Text is consistent with what's been provided in the mocks
  • Component behaves as expected across breakpoints
  • Accessibility expert has signed off on code changes (if applicable. If not applicable provide reason why)
  • Designer has signed off on changes (if applicable. If not applicable provide reason why)
  • Tab order and focus state work as expected
  • Changes have been tested against screen readers (if applicable. If not applicable provide reason why)
  • New components are covered by e2e tests; updates to existing components are covered by existing test suite
  • Changes have been tested in vets-website using Verdaccio (if applicable. If not applicable provide reason why)

Screenshots

Screenshot 2024-10-07 at 7 29 44 PM

Acceptance criteria

  • QA checklist has been completed
  • Screenshots have been attached that cover desktop and mobile screens

Definition of done

  • Documentation has been updated, if applicable
  • A link has been provided to the originating GitHub issue (or connected to it via ZenHub)

@it-harrison it-harrison added the minor For a minor Semantic Version change label Oct 8, 2024
@it-harrison it-harrison marked this pull request as ready for review October 8, 2024 00:34
@it-harrison it-harrison requested a review from a team as a code owner October 8, 2024 00:34
@powellkerry
Copy link
Contributor

powellkerry commented Oct 8, 2024

I have a couple concerns:

  • Headings disappear on smaller screens, this is what the behavior in prod is currently. It seems like you should be able to sort table data on all screens, especially smaller screens where there is less real-estate and you want to be able to find things faster, but that is not currently possible. This may be a conversation to have with USWDS and design
  • The screen reader announces the sort buttons on focus as "table groups" and the instructions on how to interact are not typical for a button and don't work. I think the buttons should have more descriptive instructions and get announced as buttons. @rsmithadhoc might be able to help better on that.
  • The label should also probably be major for this PR as it adds functionality

@rsmithadhoc
Copy link
Contributor

  • The screen reader announces the sort buttons on focus as "table groups" and the instructions on how to interact are not typical for a button and don't work. I think the buttons should have more descriptive instructions and get announced as buttons. @rsmithadhoc might be able to help better on that.

I believe those will need to be wrapped in a <button>. This should also have a title attribute with text saying "Click to sort by (column name) in (ascending/descending) order", that will read it out on a screen reader and also show a tooltip on hover.

@@ -47,6 +47,22 @@ export class VaTableInner {
*/
@Prop() stacked?: boolean = false;

@Prop() sortdir?: string = null;

@Prop() sortindex?: number = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

If sortdir and sortindex are public properties, can we add documentation comments for them to explain how they work? Would it also be valuable to add a story that demonstrates them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamigibbs - good call - they don't need to be props, I have handled this using data- attrs and State in a refactor

composed: true,
bubbles: true,
})
sortTable: EventEmitter;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this event just for internal component use? Or do we think there's a reason that a team would want to be listening for this event so they could do something with it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamigibbs it should only be useful internally

@@ -0,0 +1,12 @@
import { CompareFuncReturn } from "./utils";

export function alphaSort(sortdir: string): CompareFuncReturn {
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this function do? Could we add some documenting comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamigibbs fixed!

@@ -0,0 +1,37 @@
export const months = {
"january": 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little torn about keeping utility functions and constants in a specific component because we already have a shared place for things related to dates and utilities.

I wonder if anyone else has any thoughts about the location?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamigibbs I wondered this too - I moved the constants to higher level utils folder because there is a chance of some other component using them

return month ? month : new Date(string).getTime();
}

export function dateSort(sortdir: string): CompareFuncReturn {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a small comment about what this function is doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamigibbs - fixed!

@@ -33,6 +45,14 @@ caption {
margin-bottom: .75rem;
}

.th-sort-header {
background-color: var(--vads-color-primary-alt-light) !important;
Copy link
Contributor

@jamigibbs jamigibbs Oct 9, 2024

Choose a reason for hiding this comment

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

Are there any specific USWDS classes from their table module that could be used instead of custom CSS? Same question for the .sorted-data class below too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamigibbs - yes there are! fixed!

@jamigibbs jamigibbs requested review from a team and rsmithadhoc October 9, 2024 13:46
@jamigibbs
Copy link
Contributor

Headings disappear on smaller screens, this is what the behavior in prod is currently. It seems like you should be able to sort table data on all screens, especially smaller screens where there is less real-estate and you want to be able to find things faster, but that is not currently possible. This may be a conversation to have with USWDS and design

@powellkerry Is what you're describing the same thing as this issue?

@it-harrison
Copy link
Contributor Author

https://sortable-table--65a6e2ed2314f7b8f98609d8.chromatic.com

@powellkerry @jamigibbs good call on the disappearing headers; I pushed a commit so that they don't disappear for a sortable table

@it-harrison
Copy link
Contributor Author

  • The screen reader announces the sort buttons on focus as "table groups" and the instructions on how to interact are not typical for a button and don't work. I think the buttons should have more descriptive instructions and get announced as buttons. @rsmithadhoc might be able to help better on that.

I believe those will need to be wrapped in a <button>. This should also have a title attribute with text saying "Click to sort by (column name) in (ascending/descending) order", that will read it out on a screen reader and also show a tooltip on hover.

@rsmithadhoc instead of a button I used a span with a role="button" so that I didn't have to style the button - VoiceOver was the same but want to make sure this is okay.

@it-harrison it-harrison added the major Major change in semantic versioning label Oct 11, 2024
@rsmithadhoc
Copy link
Contributor

rsmithadhoc commented Oct 15, 2024

  • The screen reader announces the sort buttons on focus as "table groups" and the instructions on how to interact are not typical for a button and don't work. I think the buttons should have more descriptive instructions and get announced as buttons. @rsmithadhoc might be able to help better on that.

I believe those will need to be wrapped in a <button>. This should also have a title attribute with text saying "Click to sort by (column name) in (ascending/descending) order", that will read it out on a screen reader and also show a tooltip on hover.

@rsmithadhoc instead of a button I used a span with a role="button" so that I didn't have to style the button - VoiceOver was the same but want to make sure this is okay.

@it-harrison It should be okay functionality-wise, Andrew ran into issues recently with linting and explicitly defining a role, so that linting rule had to be disabled. I believe the outcome was that the rule had to be disabled in a handful of vets-website tests, but ideally to remove that in the future and use the actual element. I'm not sure if we would want to expand on those one-off rule disables if we don't have to. But just know you might see issues in vets-website. Here's the Slack thread on that: https://dsva.slack.com/archives/G01BJ3ESXL4/p1727383688504589?thread_ts=1727380266.191099&cid=G01BJ3ESXL4

I'll give my approval, I also have department-of-veterans-affairs/vets-design-system-documentation#2772 to give it a full a11y review as well.

Copy link
Contributor

@jamigibbs jamigibbs left a comment

Choose a reason for hiding this comment

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

Good updates so far, Ian! I have just a few more observations/questions:

}
return (
<span
role="button"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think USWDS is using a button with styling classes. Can we do that too here instead of using a span?

Screenshot 2024-10-15 at 11 27 36 AM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamigibbs - I switched to button but had to style it since the styles from uswds diverge from ours here

Copy link
Contributor

@jamigibbs jamigibbs Oct 18, 2024

Choose a reason for hiding this comment

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

@department-of-veterans-affairs/platform-design-system-designers Are we aware that there is a design divergence between USWDS table and our Figma for the header buttons?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamigibbs - I have keyed Dan into this and he will be working on a solution going forward

/**
* Is the table sortable
*/
@Prop() sortable: boolean = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Have we tested how this behaves with pagination?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamigibbs there was a bug (not actually related to pagination but revealed in the pagination example) that is now fixed

@it-harrison
Copy link
Contributor Author

@rsmithadhoc heads up - I went with buttons in the table header ths.

Copy link
Contributor

@jamigibbs jamigibbs left a comment

Choose a reason for hiding this comment

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

Excellent work, @it-harrison!

If there is any time to add tests for the sort utility methods, there might be an opportunity to do that similar to how va-telephone has unit tests.

And with there being visual changes, let's try and have a design approval before merging too. 🙏🏼

@it-harrison
Copy link
Contributor Author

https://sortable-table--65a6e2ed2314f7b8f98609d8.chromatic.com

@jamigibbs sorting utils tests added. reaching out to design for review

@it-harrison
Copy link
Contributor Author

@danbrady @LWWright7 @babsdenney as per a suggestion from @jamigibbs this PR will wait to merge until one of you has had time to review it for visual changes - thanks!

@danbrady
Copy link
Contributor

Sorry for the delay in review, @it-harrison. I'm a bit swamped. Quick question on something I notice... How come the sorted icons are different between USWDS and VADS?

USWDS:
Screenshot 2024-10-22 at 2 59 43 PM

VADS:
Screenshot 2024-10-22 at 2 59 23 PM

@it-harrison
Copy link
Contributor Author

Sorry for the delay in review, @it-harrison. I'm a bit swamped. Quick question on something I notice... How come the sorted icons are different between USWDS and VADS?

USWDS: Screenshot 2024-10-22 at 2 59 43 PM

VADS: Screenshot 2024-10-22 at 2 59 23 PM

@danbrady no worries and good call - I used va-icon whereas uswds has their own icon set. I assumed that we should use va-icon (I think we have done so in other components that diverge in this way from uwswds) but I could be wrong.

@danbrady
Copy link
Contributor

I see why you did that, Ian. That makes sense to me.

Maybe the USWDS uses that slim arrow instead because it looks closer to the default sort icon. Whereas the Material/VADS arrows are downright chonky. However, the USWDS should probably include those slim arrows in their icon set.

Here's three possible ideas for a way forward:

  1. Keep the icons as we have it now (not aligned with USWDS) using these:
    image

  2. Use the images/unofficial icons that USWDS currently uses and not va-icon (and submit an issue to them):
    image

  3. Add a new, similar style sortable icon from Material to match the style of the arrows in va-icon:
    image

@humancompanion-usds, your thoughts?

@it-harrison The rest of the design looks good. I don't think it's necessary to stop merging this based on the icon alone. We can create a follow up ticket, if needed. Thanks!

@it-harrison it-harrison merged commit 266e660 into main Oct 23, 2024
8 checks passed
@it-harrison it-harrison deleted the sortable-table branch October 23, 2024 14:30
@jamigibbs jamigibbs changed the title Sortable table va-table: add sorting variation Oct 23, 2024
@jamigibbs jamigibbs added minor For a minor Semantic Version change and removed major Major change in semantic versioning labels Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor For a minor Semantic Version change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Sorting to Borderless Table - Development
5 participants