department-of-veterans-affairs / vets-design-system-documentation

Repository for design.va.gov website
https://design.va.gov
36 stars 55 forks source link

va-table: Clarify the right alignment of numerical data #1871

Open jamigibbs opened 11 months ago

jamigibbs commented 11 months ago

Description

During the PR review of the React Table component migration, it was noted that a column that was previously left aligned is now right aligned by the va-table web component.

React Web Component
Screenshot 2023-06-06 at 12 08 58 PM Screenshot 2023-06-06 at 12 03 48 PM

Our utility function that determines if a column should be right aligned is:

export function isNumeric(value: string): boolean {
  return !Number.isNaN(parseFloat(value));
}

As Jerek pointed out, it's being identified as numeric because parseFloat('534-K90HEWN') evaluates to 534.

The design system documentation for table just says that "Numerical data is right-aligned" but we weren't exactly sure what is meant by "numerical" and if there's situations (like with the table above) where it wouldn't be right aligned.

Another possible issue is that the component is only checking the first instance of column data and it assumes the other column values are the same type. For example, if a columns data set is 123, 45b3, hello world, these would all be right aligned because the first one evaluates to a number.

Some questions to answer

Tasks

Acceptance Criteria

humancompanion-usds commented 2 weeks ago

I don't think we should be determining this automatically. We should just provide the ability to set the alignment to left or right (we don't want centered).

jamigibbs commented 1 week ago

Related issue created to add numerical alignment to the USWDS variation: https://github.com/department-of-veterans-affairs/vets-design-system-documentation/issues/2846