Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

cathybaptista
Copy link
Contributor

@cathybaptista cathybaptista commented Jul 19, 2024

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

  1. Table headers inside the table body (<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>.
  2. Currently, only th tags that are in the thead style get the background styling.
  3. Note that this includes <th> tags that appear in the <tfoot>.

Solution

  1. Updated packages/uswds-core/src/styles/mixins/general/table.scss. Added the same styling to the style as is added to the <thead><th> style.
  2. Consolidated styles and removed unnecessary styles in table.scss related to this issue.
  3. Follow-up issue created USWDS - Feature: tfoot behavior and styles for sortable tables #6187 to address TFoot to research how the TFoot should work.
  4. Follow-up issue created USWDS - Feature: Create a test story to demonstrate <tfoot> in tables #6189 to address TFoot in storybook.

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

  1. Open the branch in storybook.
  2. Verify that for each variant <th> tags inside of <td> tags have same styling as any other <th> tag.
  • Confirm that this code follows the 18F Front End Coding Style Guide and Accessibility Guide.
  • Run git pull origin [base branch] to pull in the most recent updates from your base and check for merge conflicts. (Often, the base branch is develop).
  • Run npm run prettier:sass to format any Sass updates.
  • Run npm test and confirm that all tests pass.
  • Run your code through HTML_CodeSniffer and make sure it’s error free.

@cathybaptista cathybaptista requested a review from amyleadem July 19, 2024 21:09
Copy link
Contributor

@amyleadem amyleadem left a 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 thead and tbody. We should update the styles so that they match.
  • 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.
  • Stacked: The th cells 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.

@cathybaptista
Copy link
Contributor Author

cathybaptista commented Jul 25, 2024

@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?

@cathybaptista cathybaptista force-pushed the cb-table-headers-need-header-styling branch 2 times, most recently from 7aa4469 to 33690d2 Compare August 10, 2024 23:20
@cathybaptista
Copy link
Contributor Author

cathybaptista commented Aug 11, 2024

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

#tbody {
    th {
      background-color: #fff;
    }

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:

tr:nth-child(even) {
   td,
   th {
     background-color: #fff;
   }
 }

3. Stacked: The th cells appear to be receiving alternating background colors for their styles. We should standardize those.

They are standard now, again, I overrode the style to:

&:nth-child(odd),
    &:nth-child(even) {
      td,
      th {
        background-color: inherit;

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 <tfoot> tag, so before I spend any time moving styles around I thought I'd mention it.

:)

Cheers to you!
Cathy

@cathybaptista
Copy link
Contributor Author

cathybaptista commented Oct 19, 2024

@mahoneycm, @amyleadem
I want to try to move this forward, but I think we may need a larger discussion on the original issue and if this is the direction we want to take, I can't tell from this conversation how it was discussed and approved, I know it was cleared for dev on Jun 27, but am not sure what happened or if decisions were made about styling, etc. Should we bring it up again? I'm not even 100% sure there is an actual issue here, since I don't know with 100% certainty it's a requirement that they be physically different. Should we involve accessibility to try to figure it out?

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.

@mahoneycm
Copy link
Contributor

@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!

@cathybaptista cathybaptista force-pushed the cb-table-headers-need-header-styling branch from 3f4c858 to c04d8ed Compare October 22, 2024 20:33
@cathybaptista

This comment was marked as outdated.

@cathybaptista
Copy link
Contributor Author

@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!

@mahoneycm

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. :)

@cathybaptista cathybaptista marked this pull request as ready for review October 22, 2024 22:10
Copy link
Contributor

@amyleadem amyleadem left a 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:

  1. Stacked variant has inconsistent header background colors - some are gray and some are white:
    image
  2. Striped variant has variable header background colors - some match the other td cells in the row, others match the thead th
    image

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.

@cathybaptista
Copy link
Contributor Author

cathybaptista commented Oct 25, 2024

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!

@cathybaptista
Copy link
Contributor Author

cathybaptista commented Oct 27, 2024

@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.

@cathybaptista cathybaptista force-pushed the cb-table-headers-need-header-styling branch from a97fe88 to e4934e8 Compare October 30, 2024 15:58
@cathybaptista cathybaptista requested a review from mejiaj November 14, 2024 15:43
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;
Copy link
Contributor

@amyleadem amyleadem Nov 25, 2024

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.

amyleadem
amyleadem previously approved these changes Nov 25, 2024
Copy link
Contributor

@amyleadem amyleadem left a 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 th cells receive bold font-weight
  • Confirm all th, tfoot td, and thead td cells have same background color
  • Confirm all th, tfoot td, and thead td cells 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

Default
image

Borderless
image

Striped
image

Sticky header
image

Sortable
image

Stacked
image

Stacked w/header
image

mahoneycm
mahoneycm previously approved these changes Nov 26, 2024
Copy link
Contributor

@mahoneycm mahoneycm left a 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 🥳

  • th cells are uniform across variants
  • th cells are visually displayed as headers even when not in thead
  • No visual regressions
  • Code matches USWDS standards

@thisisdano thisisdano dismissed stale reviews from mahoneycm and amyleadem via 8b14257 December 16, 2024 22:56
@thisisdano thisisdano merged commit bc35a99 into develop Dec 16, 2024
5 checks passed
@thisisdano thisisdano deleted the cb-table-headers-need-header-styling branch December 16, 2024 23:09
@thisisdano thisisdano mentioned this pull request Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

USWDS - Bug: Table header cells in table body do not get header styling

9 participants