-
Notifications
You must be signed in to change notification settings - Fork 1k
USWDS - Table: Add sticky headers #5420
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
Changes from all commits
9a8a13a
567876c
93269e5
630eadc
4c9a177
ab1e642
455296b
db6c5f7
3b03d79
8dae8db
a060c6a
37d56a8
63f925b
08024a6
81c43dd
40dac7c
a477cd0
ab585ae
da2a9e7
6bd2f54
fd01eb4
54debdc
121762b
65c03b6
feaaecd
ba30313
17b90e5
d02ebdc
bef2f1e
d3162cf
a9e17ac
7ca071b
d6c4ffb
21cec70
0d8a54d
c809938
7ef482c
02034a7
58d0a6a
c4d13e7
b79fdf2
1e447af
cae00e5
b10cae4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
{% if sticky_header %} | ||
{% set sticky_header_class = "usa-table--sticky-header" %} | ||
{% endif %} | ||
|
||
<div class="usa-prose measure-5 padding-2 border-1px border-gray-10 margin-bottom-4"> | ||
<p class="font-body-lg text-bold margin-top-0">Test if all rows of a sticky table header stick to the top of the page</p> | ||
<p>To complete this test:</p> | ||
<ol> | ||
<li>Scroll down until the table header sticks to the top of the page.</li> | ||
<li>Confirm that <b>both</b> table header rows stick to the top of the page.</li> | ||
<li>Confirm that none of the table content shows between the borders of the table header cells.</li> | ||
</ol> | ||
</div> | ||
|
||
<table class="usa-table {{ sticky_header ? sticky_header_class }}"> | ||
<col> | ||
<colgroup span="2"></colgroup> | ||
<colgroup span="2"></colgroup> | ||
<thead> | ||
<tr> | ||
<th rowspan="2">Federal Budget<br> Baseline Projections</th> | ||
<th colspan="2" scope="colgroup" class="text-center">2017</th> | ||
<th colspan="2" scope="colgroup" class="text-center">2018</th> | ||
<th colspan="2" scope="colgroup" class="text-center">2019</th> | ||
<th colspan="2" scope="colgroup" class="text-center">2020</th> | ||
</tr> | ||
<tr> | ||
<th scope="col" class="text-right">%GDP</th> | ||
<th scope="col" class="text-right">USD*</th> | ||
<th scope="col" class="text-right">%GDP</th> | ||
<th scope="col" class="text-right">USD*</th> | ||
<th scope="col" class="text-right">%GDP</th> | ||
<th scope="col" class="text-right">USD*</th> | ||
<th scope="col" class="text-right">%GDP</th> | ||
</tr> | ||
</thead> | ||
<tr> | ||
<th scope="row">Revenue</th> | ||
<td class="font-mono-sm text-tabular text-right">17.2%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,316</td> | ||
<td class="font-mono-sm text-tabular text-right">16.4%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,338</td> | ||
<td class="font-mono-sm text-tabular text-right">16.3%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,490</td> | ||
<td class="font-mono-sm text-tabular text-right">16.7%</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Outlays</th> | ||
<td class="font-mono-sm text-tabular text-right">20.6%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,982</td> | ||
<td class="font-mono-sm text-tabular text-right">20.2%</td> | ||
<td class="font-mono-sm text-tabular text-right">4,142</td> | ||
<td class="font-mono-sm text-tabular text-right">21.0%</td> | ||
<td class="font-mono-sm text-tabular text-right">4,470</td> | ||
<td class="font-mono-sm text-tabular text-right">21.3%</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Budget Deficit</th> | ||
<td class="font-mono-sm text-tabular text-right">-3.5%</td> | ||
<td class="font-mono-sm text-tabular text-right">-665</td> | ||
<td class="font-mono-sm text-tabular text-right">-3.8%</td> | ||
<td class="font-mono-sm text-tabular text-right">-804</td> | ||
<td class="font-mono-sm text-tabular text-right">-4.6%</td> | ||
<td class="font-mono-sm text-tabular text-right">-981</td> | ||
<td class="font-mono-sm text-tabular text-right">-4.6%</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Debt Held by Public</th> | ||
<td class="font-mono-sm text-tabular text-right">76.0%</td> | ||
<td class="font-mono-sm text-tabular text-right">14,665</td> | ||
<td class="font-mono-sm text-tabular text-right">77.4%</td> | ||
<td class="font-mono-sm text-tabular text-right">15,688</td> | ||
<td class="font-mono-sm text-tabular text-right">79.2%</td> | ||
<td class="font-mono-sm text-tabular text-right">16,762</td> | ||
<td class="font-mono-sm text-tabular text-right">80.9%</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Revenue</th> | ||
<td class="font-mono-sm text-tabular text-right">17.2%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,316</td> | ||
<td class="font-mono-sm text-tabular text-right">16.4%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,338</td> | ||
<td class="font-mono-sm text-tabular text-right">16.3%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,490</td> | ||
<td class="font-mono-sm text-tabular text-right">16.7%</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Outlays</th> | ||
<td class="font-mono-sm text-tabular text-right">20.6%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,982</td> | ||
<td class="font-mono-sm text-tabular text-right">20.2%</td> | ||
<td class="font-mono-sm text-tabular text-right">4,142</td> | ||
<td class="font-mono-sm text-tabular text-right">21.0%</td> | ||
<td class="font-mono-sm text-tabular text-right">4,470</td> | ||
<td class="font-mono-sm text-tabular text-right">21.3%</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Budget Deficit</th> | ||
<td class="font-mono-sm text-tabular text-right">-3.5%</td> | ||
<td class="font-mono-sm text-tabular text-right">-665</td> | ||
<td class="font-mono-sm text-tabular text-right">-3.8%</td> | ||
<td class="font-mono-sm text-tabular text-right">-804</td> | ||
<td class="font-mono-sm text-tabular text-right">-4.6%</td> | ||
<td class="font-mono-sm text-tabular text-right">-981</td> | ||
<td class="font-mono-sm text-tabular text-right">-4.6%</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Debt Held by Public</th> | ||
<td class="font-mono-sm text-tabular text-right">76.0%</td> | ||
<td class="font-mono-sm text-tabular text-right">14,665</td> | ||
<td class="font-mono-sm text-tabular text-right">77.4%</td> | ||
<td class="font-mono-sm text-tabular text-right">15,688</td> | ||
<td class="font-mono-sm text-tabular text-right">79.2%</td> | ||
<td class="font-mono-sm text-tabular text-right">16,762</td> | ||
<td class="font-mono-sm text-tabular text-right">80.9%</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Revenue</th> | ||
<td class="font-mono-sm text-tabular text-right">17.2%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,316</td> | ||
<td class="font-mono-sm text-tabular text-right">16.4%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,338</td> | ||
<td class="font-mono-sm text-tabular text-right">16.3%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,490</td> | ||
<td class="font-mono-sm text-tabular text-right">16.7%</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Outlays</th> | ||
<td class="font-mono-sm text-tabular text-right">20.6%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,982</td> | ||
<td class="font-mono-sm text-tabular text-right">20.2%</td> | ||
<td class="font-mono-sm text-tabular text-right">4,142</td> | ||
<td class="font-mono-sm text-tabular text-right">21.0%</td> | ||
<td class="font-mono-sm text-tabular text-right">4,470</td> | ||
<td class="font-mono-sm text-tabular text-right">21.3%</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Budget Deficit</th> | ||
<td class="font-mono-sm text-tabular text-right">-3.5%</td> | ||
<td class="font-mono-sm text-tabular text-right">-665</td> | ||
<td class="font-mono-sm text-tabular text-right">-3.8%</td> | ||
<td class="font-mono-sm text-tabular text-right">-804</td> | ||
<td class="font-mono-sm text-tabular text-right">-4.6%</td> | ||
<td class="font-mono-sm text-tabular text-right">-981</td> | ||
<td class="font-mono-sm text-tabular text-right">-4.6%</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Debt Held by Public</th> | ||
<td class="font-mono-sm text-tabular text-right">76.0%</td> | ||
<td class="font-mono-sm text-tabular text-right">14,665</td> | ||
<td class="font-mono-sm text-tabular text-right">77.4%</td> | ||
<td class="font-mono-sm text-tabular text-right">15,688</td> | ||
<td class="font-mono-sm text-tabular text-right">79.2%</td> | ||
<td class="font-mono-sm text-tabular text-right">16,762</td> | ||
<td class="font-mono-sm text-tabular text-right">80.9%</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Revenue</th> | ||
<td class="font-mono-sm text-tabular text-right">17.2%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,316</td> | ||
<td class="font-mono-sm text-tabular text-right">16.4%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,338</td> | ||
<td class="font-mono-sm text-tabular text-right">16.3%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,490</td> | ||
<td class="font-mono-sm text-tabular text-right">16.7%</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Outlays</th> | ||
<td class="font-mono-sm text-tabular text-right">20.6%</td> | ||
<td class="font-mono-sm text-tabular text-right">3,982</td> | ||
<td class="font-mono-sm text-tabular text-right">20.2%</td> | ||
<td class="font-mono-sm text-tabular text-right">4,142</td> | ||
<td class="font-mono-sm text-tabular text-right">21.0%</td> | ||
<td class="font-mono-sm text-tabular text-right">4,470</td> | ||
<td class="font-mono-sm text-tabular text-right">21.3%</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Budget Deficit</th> | ||
<td class="font-mono-sm text-tabular text-right">-3.5%</td> | ||
<td class="font-mono-sm text-tabular text-right">-665</td> | ||
<td class="font-mono-sm text-tabular text-right">-3.8%</td> | ||
<td class="font-mono-sm text-tabular text-right">-804</td> | ||
<td class="font-mono-sm text-tabular text-right">-4.6%</td> | ||
<td class="font-mono-sm text-tabular text-right">-981</td> | ||
|
||
<td class="font-mono-sm text-tabular text-right">-4.6%</td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Debt Held by Public</th> | ||
<td class="font-mono-sm text-tabular text-right">76.0%</td> | ||
<td class="font-mono-sm text-tabular text-right">14,665</td> | ||
<td class="font-mono-sm text-tabular text-right">77.4%</td> | ||
<td class="font-mono-sm text-tabular text-right">15,688</td> | ||
<td class="font-mono-sm text-tabular text-right">79.2%</td> | ||
<td class="font-mono-sm text-tabular text-right">16,762</td> | ||
<td class="font-mono-sm text-tabular text-right">80.9%</td> | ||
</tr> | ||
</table> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"scrollable": true | ||
} |
![]() Advertisement
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the class, but not seeing sticky headers work in any of these tables. Example ![]() Advertisement
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have to first turn off the scrollable variant in the control since it is incompatible with sticky headers. I added a note to the scrollable control in 58d0a6a to help clarify. Let me know if that helps. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @amyleadem is it worth making these controls conditional1? For example, only show these controls if sticky headers are disabled. Example argTypes: {
scrollable: {
name: "Scrollable (Turning this on will disable sticky headers)",
control: { type: "boolean" },
defaultValue: false,
if: { arg: "sticky_header", truthy: false } // Hide this control if sticky
},
}, FootnotesThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I played with this a bit but lean away from adding it in this instance since neither is actually the dependency of the other. Instead they are just incompatible. I ended up feeling like I would be confused about which options are available for the component, so I left it as is. Let me know if you object. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{ | ||
"scrollable": false, | ||
"modifier": "", | ||
"caption": "Bordered table", | ||
"thead": [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{ | ||
"scrollable": false, | ||
"modifier": "", | ||
"caption": "Bordered table", | ||
"thead": [ | ||
|
amyleadem marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.