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

Table: Create table components #695

Merged
merged 35 commits into from
Mar 14, 2024
Merged

Table: Create table components #695

merged 35 commits into from
Mar 14, 2024

Conversation

jialin-he
Copy link
Contributor

@jialin-he jialin-he commented Mar 2, 2024

This change: (check at least one)

  • Adds a new feature
  • Fixes a bug
  • Improves maintainability
  • Improves documentation
  • Is a release activity

Is this a breaking change? (check one)

  • Yes
  • No

Is the: (complete all)

  • Title of this pull request clear, concise, and indicative of the issue number it addresses, if any?
  • Test suite(s) passing?
  • Code coverage maximal?
  • Changeset added?
  • Component status page up to date?

What does this change address?

Resolves #355 ; Create a basic table component

How does this change work?
A table component that takes in user input data and display with pagination.

@jialin-he jialin-he requested a review from a team as a code owner March 2, 2024 02:40
@jialin-he jialin-he requested review from daneah, sirrah-tam and mtorres3 and removed request for a team March 2, 2024 02:40
Copy link

changeset-bot bot commented Mar 2, 2024

🦋 Changeset detected

Latest commit: 2161b85

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@ithaka/pharos Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Mar 2, 2024

size-limit report 📦

Path Size
packages/pharos/lib/index.js 63.79 KB (+1.37% 🔺)

Copy link
Member

@daneah daneah left a comment

Choose a reason for hiding this comment

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

Looks as though there's a little layout blip between when the Previous button is shown in the pagination vs. not.

Screen.Recording.2024-03-05.at.10.19.49.mov

packages/pharos/src/components/table/pharos-table.ts Outdated Show resolved Hide resolved
Comment on lines 42 to 43
/* eslint-disable @typescript-eslint/no-explicit-any */
public columns: any[] = [];
Copy link
Member

Choose a reason for hiding this comment

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

I'm just spitballing here, but it could be interesting to think about a system where the column spec specifies the expected data type of each column, and that the types would guide telling a consumer if they've supplied data of the wrong types. At a minimum, perhaps we could make an alias type to avoid all the eslint-disables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've been thinking about your suggestion Dane. I wonder if it is possible in some cases the content in a column can be in multiple types. Do we require the consumer to provide all possible types? Will that be too heavy load for the consumer?

Copy link
Member

Choose a reason for hiding this comment

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

I would generally hope that if we're displaying tabular data, that within a column the data type is consistent (or can be coerced to be consistent by way of string, minimally). There's a tradeoff here between safety and tedium as you rightly call out...I don't really have strong feelings on this, and it can definitely be iterated on, so I don't want it to hold us up here too much!

packages/pharos/src/components/table/pharos-table.ts Outdated Show resolved Hide resolved
jialin-he and others added 2 commits March 5, 2024 13:10
Co-authored-by: Dane Hillard <github@danehillard.com>
Co-authored-by: Dane Hillard <github@danehillard.com>
jialin-he and others added 3 commits March 7, 2024 09:55
public pageSizeOptions: number[] = [50, 100];

@property({ type: String, reflect: true, attribute: 'caption' })
public caption: string = '';
Copy link

Choose a reason for hiding this comment

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

I understand we need the caption for accessibility reasons, I'm curious if there should be any ability to visually hide it in certain cases or is the expectation should be having the practice of always showing a table caption?

Copy link
Contributor

Choose a reason for hiding this comment

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

☝️ @sirrah-tam might have some insight into this, I think it could be "visually hidden" as long as it is still accessible to screen readers

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great to be able to include an attribute that auto-visually-hides the caption as that does appear to be pretty common in other examples I'm finding. Similar to how the <title> element gives a SVG it's accessible name (accNam), the gives the Table it's accName, helpful when users of AT are reviewing the contents of a page. Visually hiding the captions would mean that a sighted user would have to use other information on the page to understand the context and purpose of the table, ex page title or heading preceding the table.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I understand correctly, we want to add another attribute, something like auto-visually-hide = true, to control if we want to visually hide the caption? Does that mean we should make the caption attribute a required attribute so that we always have a accessible name for the table?

Copy link

@kentjas1 kentjas1 Mar 12, 2024

Choose a reason for hiding this comment

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

I do feel like the caption should be required to enforce always having accessible tables generated but would leave that up to @sirrah-tam and the other wickies to officially answer yes/no.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!

Copy link
Contributor

Choose a reason for hiding this comment

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

The caption element is not required per WCAG and there are some cases where the caption may not be needed, especially for simple tables where there is already a heading that precedes the table. However, I do like that we'd kind of take a stand that all tables need a caption by requiring it for our design system. I would however say we shouldn't have it hidden by default and instead make the user explicitly hide it.

}

.hide-table-caption {
visibility: hidden;
Copy link
Contributor

Choose a reason for hiding this comment

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

This CSS style will actually hide the content from a screen reader, similar to display: none. It's better to use the following set of styles when trying to visually hide content:

.visually-hidden:not(:focus):not(:active) {
  clip: rect(0 0 0 0); 
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap; 
  width: 1px;
}

Reference: https://www.scottohara.me/blog/2017/04/14/inclusively-hidden.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!

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 this mixin is what you want within pharos

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

public pageSizeOptions: number[] = [50, 100];

@property({ type: String, reflect: true, attribute: 'caption' })
public caption: string = '';
Copy link
Contributor

Choose a reason for hiding this comment

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

The caption element is not required per WCAG and there are some cases where the caption may not be needed, especially for simple tables where there is already a heading that precedes the table. However, I do like that we'd kind of take a stand that all tables need a caption by requiring it for our design system. I would however say we shouldn't have it hidden by default and instead make the user explicitly hide it.

Comment on lines +22 to +41
.table-controls {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: var(--pharos-spacing-one-half-x);

.item-per-page-wrapper {
display: flex;
align-items: center;
column-gap: var(--pharos-spacing-one-half-x);

.item-per-page-selector {
width: 75px;
}
}

.pagination {
height: var(--pharos-spacing-one-and-a-half-x);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Typically we try to use a more BEM-like approach rather than deeply nested selectors. Because this isn't automated and is somewhat subjective currently, let's let it stand as a "TODO" for later 😄

packages/pharos/src/components/table/pharos-table.ts Outdated Show resolved Hide resolved
Co-authored-by: Dane Hillard <github@danehillard.com>
public rowData: RowData[] = [];

@property({ type: Boolean, reflect: true, attribute: 'hide-pagination' })
public hidePagination: boolean = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Might just be just personal opinion, but thoughts on making this showPagination instead and defaulting it to false? Setting hidePagination="false" to show the pagination seems like a more complicated mental model than just showPagination="true" or showPagination="false" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I feel showPagination makes more sense, updated!

it('is accessible', async () => {
await expect(component).to.be.accessible();
});

Copy link
Contributor

Choose a reason for hiding this comment

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

Might be nice to add a unit test like this one which verifies it throws an error when there is no caption?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

protected override firstUpdated(): void {
this._pageSize = this.hidePagination ? this.rowData.length : this.pageSizeOptions[0];
this.totalResults =
this.hidePagination || !this.totalResults ? this.rowData.length : this.totalResults;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we care about hidePagination here?

Copy link
Contributor Author

@jialin-he jialin-he Mar 13, 2024

Choose a reason for hiding this comment

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

Oh I guess we don't need it here!

Copy link
Contributor

@brentswisher brentswisher left a comment

Choose a reason for hiding this comment

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

@jialin-he Just a couple of nits/questions, but this is looking awesome 🎉

Co-authored-by: Brent Swisher <brent@brentswisher.com>
Copy link
Contributor

@sirrah-tam sirrah-tam left a comment

Choose a reason for hiding this comment

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

Small request to change the reference to hideCaption vs hideCaptionVisually as more concise way of setting that attribute.

packages/pharos/src/components/table/pharos-table.ts Outdated Show resolved Hide resolved
packages/pharos/src/components/table/pharos-table.ts Outdated Show resolved Hide resolved
packages/pharos/src/components/table/pharos-table.ts Outdated Show resolved Hide resolved
jialin-he and others added 3 commits March 13, 2024 14:28
Co-authored-by: Mat Harris <mat.harris@ithaka.org>
Co-authored-by: Mat Harris <mat.harris@ithaka.org>
Co-authored-by: Mat Harris <mat.harris@ithaka.org>
@jialin-he jialin-he merged commit b864531 into develop Mar 14, 2024
6 of 11 checks passed
@jialin-he jialin-he deleted the feat/pharos-table branch March 14, 2024 12:35
@github-actions github-actions bot mentioned this pull request Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tables: A way to organize information, especially large sets of information
6 participants