-
Notifications
You must be signed in to change notification settings - Fork 1k
USWDS - Table component: add ability to make headers sticky as user scrolls #5074
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
@etanb Thank you for this submission! I like the possibilities this variant offers. I've added some notes on a few items I discovered. Would you be able to take a look and resolve these items?
Please let me know if you have any questions or comments! |
@etanb I have added the |
Thanks for the contribution @etanb! No issues found on mobile and browser support looks pretty good. https://caniuse.com/css-sticky Are you able to address Amy's comments? If you're unable to that's okay. We can create another issue for the comments and create a separate feature branch for all this work. What do you think @amyleadem? |
Hi all, I'm just rebuilding my local now and will have an update soon! Will try and incorporate all of @amyleadem requests. |
My latest commit #630eadc6913a3efa5a08e90049074add4a8f11a6 adds usage for all the other USWDS stylings except for Two remaining issues / items for y'all/us to decide on:
You can see that the row that are doubled up get squashed together since all Let me know what y'all think! cc @amyleadem @mejiaj |

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.
@etanb thanks for updating!
- I think it's worth trying to find workarounds. Especially ones with minimal impact on the markup.
- Option
D
for colspan greater than 1 seems good to me, but I'd like the team to weigh in.
Unfortunately, after digging deeper, having a horizontal scroll + a sticky header for a table has been a known issue for a while (2017!) and there's still an open issue on W3C CSS repo: w3c/csswg-drafts#865 The only workaround I see is removing
![]() Advertisement
and removing
Example of it working: scrollAndSticky.mp4However, that's a lot of modifications to get this feature working. Let me know what y'all think and what is worthwhile! |
Yes it is a really old issue and I hope one day it could be fixed. We need a feature that allows overflow on height or width. But both overflows works and no one too. If we remove hidden overflow the table expands the viewport. It would be grate that setting an overflow hidden does not remove the sticky attribute so text outside the table stays on the view. It is especially good for mobile when the user can scroll inside the table without scrolling the whole page. |
Ok, not sure what next steps are here are @DorianCoding @amyleadem @mejiaj . My gut instinct here is to just make |
It already works when setting both width and height or none using overflow visible. |
If we have a fixed table height, you can have BOTH side scrolling + sticky header. |
@etanb I know some time has passed, so please let us know if your availability has changed and you need any help finishing this out. I have tested the following items:
Other considerations
cc: @mejiaj @mahoneycm |
Thanks for the extensive checklist @amyleadem. We're currently implementing on our variation of this feature on our site, and as said previously, using a fixed height (we do |
@etanb Thanks for the suggestion. I will take a look and discuss with the team. |
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.
Hi @etanb,
Wanted to check in to see if you will be able to get to the items in the checklist in this comment.
I know a part of the conversation was left hanging on my part. Thanks for your patience with that. For now, lets move forward without including sticky tables on scrollable headers. We can always address that concern as a follow-on enhancement.
Just let us know if your availability has changed and you need us to finish this out.
That's exciting news! Thanks for making this happen @amyleadem , let me know if I can be useful. |
Absolutely! Thanks for your patience on this. |
Summary
For very long tables, it's difficult to remember what the header content was. This change allows a developer to have the the table header content follow a user on scroll.
Breaking change
This is not a breaking change.
Related issue
N/A
Preview link
FixedHeaderTable.mp4
Solution
usa-table--sticky-header
that invokes the following CSS rule:(NOTE: you can not
position: sticky;
a<thead>
element so the preferred solution is to just target the<th>
data.)Testing and review
Sticky Header
where you can review the results