-
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 41 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,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
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"caption": "Sticky header table", | ||
"sticky_header": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,14 @@ | |
@use "../utilities" as *; | ||
@use "../typography/typeset" as *; | ||
|
||
$table-background-color: $theme-table-background-color; | ||
|
||
@if $table-background-color == "default" { | ||
$table-background-color: get-default("bg-color"); | ||
} | ||
Comment on lines
+10
to
+12
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. Tip In the future, we should consider adding Especially as we rely more on default for background color setting only. |
||
|
||
$table-text-color: get-color-token-from-bg( | ||
$bg-color: $theme-body-background-color, | ||
$bg-color: $theme-table-background-color, | ||
$preferred-text-token: $theme-table-text-color, | ||
$context: "Table text", | ||
); | ||
|
@@ -235,7 +241,7 @@ $table-unsorted-icon-color: get-color-token-from-bg( | |
} | ||
th, | ||
td { | ||
background-color: color($theme-body-background-color); | ||
background-color: color($table-background-color); | ||
border: 1px solid color($theme-table-border-color); | ||
font-weight: fw("normal"); | ||
padding: units(1) units(2); | ||
|
@@ -295,7 +301,7 @@ $table-unsorted-icon-color: get-color-token-from-bg( | |
@mixin usa-table--borderless { | ||
thead { | ||
th { | ||
background-color: transparent; | ||
background-color: color($table-background-color); | ||
border-top: 0; | ||
color: color($table-text-color); | ||
|
||
|
@@ -355,6 +361,46 @@ $table-unsorted-icon-color: get-color-token-from-bg( | |
@include table-stacked-header-styles; | ||
} | ||
|
||
@mixin usa-table--sticky-header { | ||
border: 1px solid color($theme-table-border-color); | ||
border-collapse: separate; | ||
|
||
td, | ||
th { | ||
border-left: none; | ||
border-top: none; | ||
|
||
&:last-child { | ||
border-right: none; | ||
} | ||
} | ||
|
||
tbody tr:last-child { | ||
td, | ||
th { | ||
border-bottom: none; | ||
} | ||
} | ||
Comment on lines
+365
to
+383
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. Note To prevent an issue with content showing behind the sticky table headers on scroll, I added This caused the cell borders to essentially double up, which created a need to reconfigure how the borders were applied in this variant. |
||
|
||
thead { | ||
position: sticky; | ||
top: $theme-table-sticky-top-offset; | ||
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. Warning Offset is useful for when there is another element that already sticks to the top of the page, like a sticky header navigation. I suspect that most users will need to write custom rules if their sticky elements change at different breakpoints (For example, the sticky header navigation on uswds-site goes away in the mobile view). Do we want to keep this setting with the understanding that additional style overrides might often be necessary 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 feel like we should keep it. Like most of our work, we provide the tools, but it's up to the users to implement them in a way that works for them. 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. Noting this in the guidance would be useful. As well as recommending users limit the number of sticky/fixed items on the page. For example, a sticky sidenav, header, and table header might be too much. For now a general note might be good enough. |
||
} | ||
|
||
&.usa-table--borderless { | ||
border: none; | ||
|
||
thead th { | ||
background-color: color($table-background-color); | ||
} | ||
|
||
td, | ||
th { | ||
border-right: none; | ||
} | ||
} | ||
} | ||
|
||
@mixin usa-table-container--scrollable { | ||
margin: units(2.5) 0; | ||
overflow-y: hidden; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,6 +203,7 @@ $theme-summary-box-link-color: default !default; | |
$theme-summary-box-text-color: default !default; | ||
|
||
// Table | ||
$theme-table-background-color: default !default; | ||
$theme-table-border-color: "ink" !default; | ||
$theme-table-header-background-color: "base-lighter" !default; | ||
$theme-table-header-text-color: default !default; | ||
|
@@ -213,6 +214,7 @@ $theme-table-sorted-header-background-color: "accent-cool-light" !default; | |
$theme-table-sorted-background-color: "accent-cool-lighter" !default; | ||
$theme-table-sorted-stripe-background-color: "blue-cool-10v" !default; | ||
$theme-table-sorted-icon-color: default !default; | ||
$theme-table-sticky-top-offset: -1px !default; | ||
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. Small concern here is this is similar to the current hero setting where it's not very flexible or re-usable. Not a blocker for this work. 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. Yeah, the setting is fairly limited, but I am not sure if there is a way around it. I would imagine a lot of projects will need to write some custom style rules for the top offset. 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 does this setting accept units too or only pixels? Do we have any guidance for this? |
||
$theme-table-unsorted-icon-color: "base" !default; | ||
|
||
// Tooltips | ||
|
Uh oh!
There was an error while loading. Please reload this page.