-
Notifications
You must be signed in to change notification settings - Fork 1.1k
USWDS: Table: Add styling to table headers that aren't in thead. #5986
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
Conversation
amyleadem
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this on @cathybaptista.
After looking through the variants in the preview links, I think we will need to make individual header styles for each table variant. Here are some of my thoughts on the available variants:
- Borderless: Right now, the borderless table headers do not match across
theadandtbody. We should update the styles so that they match. - Striped: The striped styles in
tbody thcells are confusing. They should probably just be the same single background color as thethead thcells. - Stacked: The
thcells appear to be receiving alternating background colors for their styles. We should standardize those.
note: I personally hesitate a bit about having the th styles in thead and tbody be identical. Part of me wants tbody th to be visually distinct from both tbody td and thead th cells — maybe something a step lighter — but part of me thinks that is too opinionated. I'll keep thinking about it, but flagging it now in case anyone else is hesitating there.
question: Also a more general question that might be out of scope for this issue: do we want styles for tfoot th? One way this could be in scope is for us to remove the specificity so that we are just styling th, rather than tbody th and thead th. Just a thought for now but wanted to flag the question.
|
@amyleadem You know what, I agree that we should make the styles identical. Looking at the borderless table (for example), the top header says "Document Title" but there is no visual difference between it and the table headers beneath it. I think that's confusing; let's see what we think if it's a bit lighter. As for the tfoot th, there's no good reason for me to think this issue would also not be important in the footer, so my feeling is that we do include it in the scope. Do you want to open comments to this end? Should we discuss maybe in office hours? |
7aa4469 to
33690d2
Compare
|
Hi, @amyleadem! I've made a couple of changes with the hope of opening up the discussion on this issue once again. I say that because I sure don't think this is the end of this discussion, it touches too many things. I'll take your comments one-by-one. :) 1. Borderless: Right now, the borderless table headers do not match across thead and tbody. We should update the styles so that they match. I have made them match, but I made the tbody match to the thead not the other way around. This means none of the th have a gray styling. Now that I re-read your comment, I'm not sure that's what you were thinking :). Also, I overrode the style for usa-table--borderless mixin with to accomplish this. I took this approach because it looks like the default styling for tables is in usa-table, so I left the new styles there and overrode them when appropriate. 2. Striped: The striped styles in tbody th cells are confusing. They should probably just be the same single background color as the thead th cells. I agree! I added this to the usa-table--striped mixin:
They are standard now, again, I overrode the style to: so that the style is consistent. I'm not 100% convinced this is the right approach to this, but it might be a way to at least resolve this issue for default tables. Perhaps we can discuss? Lastly, I want to mention the issue you brought up about the tfoot. It doesn't seem like the twig file is even writing the :) Cheers to you! |
|
@mahoneycm, @amyleadem I also created a test branch to show the table: https://github.com/uswds/uswds/tree/cb-test-table-headers-with-styling Open the table and select table sortable. |
|
@cathybaptista I believe was had agreed that row headers in tables should have the same TH styling as the column headers. We looked at the W3 tables with irregular headers page as a reference for these styles. I think this is something we should move forward with and your demo example looks good! Looking at the changed files in your repo, I'm hoping we can simplify the changes. Would you be able to do another pass of this work and see if there is a way to include row TH cells with fewer changed lines? Happy to sync up if need be! |
3f4c858 to
c04d8ed
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Hi, Charlie! I removed most of the styles I had modified as a result of this issue (#5986 being simplified to only address the th styling. However, I did leave in one additional style, which is part of the borderless table. The gray styling that is added to the base table is being applied to the borderless table and results in a border (or at least, a visual border because the background is gray.) I changed the tbody th tags to white for the borderless table, but included the style with the th and td tags so that I wasn't declaring an entirely new style. Let me know what you think of my solution. :) |
amyleadem
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update @cathybaptista. I found a couple of visual issues that should be addressed:
- Stacked variant has inconsistent header background colors - some are gray and some are white:

- Striped variant has variable header background colors - some match the other
tdcells in the row, others match thethead th

Can you update the styles to make sure these headers consistently use $theme-table-header-background-color?
Additionally, these styles do not appear to touch tfoot th cells. I would expect the header background styles to affect these cells as well. Is it possible to make a single, generic style rule that applies to all table th cells, regardless of their parent? If not, can you make sure that tfoot th is targeted? Additionally, can you add a test story that shows tfoot th cells?
Please let me know if you have any questions.
|
Hi, @amyleadem . Thank you for your thorough review! Federalist Link shows the latest changes. Not quite done yet! f9279a3 addresses the striped table issue e4934e8 addresses the white background (#fff) and stacked tables. I haven't finished with the footer, it's easy enough to add it to the styles but I really don't want to just throw styles in there so I'm trying to figure out how to add them in a way that will not add any additional confusion. I'll get that to you as soon as possible! |
|
@amyleadem I gave this some thought this weekend, we may want to talk as a group. Is the footer any different from the header? Can we set the tfoot in the table scss to extend thead? This may save some future headaches. :) Update on 10/28: This isn't the issue. It's about creating a common th so we don't need to call out thead, tbody, tfoot. |
a97fe88 to
e4934e8
Compare
Co-authored-by: Amy Leadem <93996430+amyleadem@users.noreply.github.com>
…e-headers-need-header-styling
| background-clip: padding-box; | ||
| line-height: line-height($theme-body-font-family, $theme-input-line-height); | ||
| background-color: color($theme-table-header-background-color); | ||
| color: $table-header-text-color; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note
With this change, we are now relying on the user agent style sheet for th to set the font weight to bold and set the text alignment. Firefox, Chrome, and Safari all include a default font-weight:bold rule and left align the text for th. No action is needed here, just flagging it in case we want to be explicit about these th style rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks for your persistence with this one @cathybaptista.
Looking forward to seeing this work continued in #6189.
- Confirm all
thcells receive bold font-weight - Confirm all
th,tfoot td, andthead tdcells have same background color - Confirm all
th,tfoot td, andthead tdcells have the same the line height
Code used in testing
// settings-components.scss
$theme-table-background-color: "blue-cool-10v" !default;
$theme-table-border-color: "red-60" !default;
$theme-table-header-background-color: "mint-20" !default;
$theme-table-header-text-color: "blue-80" !default;
$theme-table-stripe-background-color: "blue-cool-20v" !default;
$theme-table-stripe-text-color: "blue-90" !default;
$theme-table-text-color: "red-80" !default;
$theme-table-sorted-header-background-color: "cyan-20" !default;
$theme-table-sorted-background-color: "cyan-10" !default;
$theme-table-sorted-stripe-background-color: "magenta-10" !default;<tfoot>
<tr>
<th>Table head</th>
<td>Table cell</td>
<td>Table cell</td>
</tr>
</tfoot>Screenshots
mahoneycm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the great work here @cathybaptista 🥳
-
thcells are uniform across variants -
thcells are visually displayed as headers even when not inthead - No visual regressions
- Code matches USWDS standards
Co-authored-by: Amy Leadem <93996430+amyleadem@users.noreply.github.com>







Summary
Updated the table component styles so that table headers get consistent styling whether they are inside the thead or not.
Breaking change
This is not a breaking change. Users should confirm that their tables display as expected.
Related issue
Closes #5777
Related pull requests
Relates to #5779 submitted by @ajanickiv. Note there were other issues mentioned in #5779, but this PR addresses TH styling only.
Preview link
Change log PR →
Problem statement
<tbody>) should get the table header background color color($theme-table-header-background-color), even if the tag is inside of a<td>or<tr>.<th>tags that appear in the<tfoot>.Solution
<thead><th>style.Major changes
This change was made to table.scss, and so impacts other table variants. TFoot addition does not impact stacked, sortable or scrollable variants.
Testing and review
<th>tags inside of<td>tags have same styling as any other<th>tag.git pull origin [base branch]to pull in the most recent updates from your base and check for merge conflicts. (Often, the base branch isdevelop).npm run prettier:sassto format any Sass updates.npm testand confirm that all tests pass.