Skip to content

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

Merged
merged 44 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9a8a13a
add the ability to sticky the header of the table component
etanb Dec 20, 2022
567876c
prettier
etanb Dec 20, 2022
93269e5
Merge branch 'develop' into eb-sticky-table-header
etanb Apr 17, 2023
630eadc
fixes to implementation
etanb Apr 18, 2023
4c9a177
Add sticky header control
May 16, 2023
ab1e642
Override position:relative on sortable sticky th cells
May 16, 2023
455296b
Remove stickyheader control
May 16, 2023
db6c5f7
Add sortable JSON file
May 16, 2023
3b03d79
Add demo for multi-row headers
May 16, 2023
8dae8db
Add multipleHeaderRows control for testing
May 17, 2023
a060c6a
Remove background color and extra borders from sticky table thead
May 17, 2023
37d56a8
Disable multipleHeaderRows for sortable tables
May 17, 2023
63f925b
Remove text-right from table header
May 17, 2023
08024a6
Merge branch 'develop' of https://github.com/uswds/uswds into al-stic…
May 19, 2023
81c43dd
Run prettier
May 19, 2023
40dac7c
Add settings for table background color and sticky table top offset
May 23, 2023
a477cd0
Move stickyheader from json to a storybook control
Aug 2, 2023
ab585ae
Remove stickyheader check on scrollable variant
Aug 2, 2023
da2a9e7
Format code
Aug 2, 2023
6bd2f54
Move scrollable setting from json to storybook
Aug 2, 2023
fd01eb4
Let $theme-table-background-color accept default
Aug 2, 2023
54debdc
Run prettier
Aug 2, 2023
121762b
Fix default for $theme-table-background-color
Aug 2, 2023
65c03b6
Clean up multiple header rows code
Aug 2, 2023
feaaecd
Add scrollable conditional to sortable twig
Aug 3, 2023
ba30313
Create loops for header and body rows
Aug 4, 2023
17b90e5
Remove background color on table button default
Aug 4, 2023
d02ebdc
Merge branch 'develop' of https://github.com/uswds/uswds into al-stic…
Aug 9, 2023
bef2f1e
Restore scrollable default on sortable tables
Aug 9, 2023
d3162cf
Clean up sticky header style rules
Aug 9, 2023
a9e17ac
Reorganize sticky header controls
Aug 9, 2023
7ca071b
Move scrollable: true to json file
Aug 11, 2023
d6c4ffb
Run prettier
Aug 11, 2023
21cec70
Add !default to $theme-table-sticky-top-offset
Aug 21, 2023
0d8a54d
Move 'stickyheader:true' to JSON
Sep 6, 2023
c809938
Merge branch 'develop' of github.com:uswds/uswds into al-sticky-table…
Jan 9, 2024
7ef482c
Add note about sticky header to scrollable control
Jan 10, 2024
02034a7
Use underscores for twig variables
Jan 10, 2024
58d0a6a
Add note to sticky header + mult header controls
Jan 11, 2024
c4d13e7
Add underscore to stickheader json + twig
Jan 11, 2024
b79fdf2
Remove "Note:" from scrollable control
Jan 11, 2024
1e447af
Create test: multiple header rows + sticky header
Jan 23, 2024
cae00e5
Assign sticky_header_class on sortable twig
Jan 23, 2024
b10cae4
Run prettier
Jan 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add underscore to stickheader json + twig
  • Loading branch information
amyleadem committed Jan 11, 2024
commit c4d13e7ff96314255373dddb714f2ff7992dc032
Copy link
Contributor

Choose a reason for hiding this comment

The 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
image
From preview Table - Sortable ⋅ Storybook

Copy link
Contributor Author

@amyleadem amyleadem Jan 10, 2024

Choose a reason for hiding this comment

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

Copy link
Contributor

@mejiaj mejiaj Jan 19, 2024

Choose a reason for hiding this comment

The 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
    },
  },

Footnotes

  1. https://storybook.js.org/docs/essentials/controls#conditional-controls

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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,7 +1,7 @@
{% if scrollable %}
<div class="usa-table-container--scrollable" tabindex="0">
{% endif %}
<table class="usa-table {{stickyHeader ? 'usa-table--sticky-header' : ''}}">
<table class="usa-table {{sticky_header ? 'usa-table--sticky-header' : ''}}">
<caption>Recently admitted US states (sortable table example)</caption>
<thead>
<tr>
Expand Down Expand Up @@ -96,7 +96,7 @@
{% if scrollable %}
<div class="usa-table-container--scrollable" tabindex="0">
{% endif %}
<table class="usa-table usa-table--striped {{stickyHeader ? 'usa-table--sticky-header' : ''}}">
<table class="usa-table usa-table--striped {{sticky_header ? 'usa-table--sticky-header' : ''}}">
<caption>Sortable striped table with various content types</caption>
<thead>
<tr>
Expand Down Expand Up @@ -171,7 +171,7 @@
{% if scrollable %}
<div class="usa-table-container--scrollable" tabindex="0">
{% endif %}
<table class="usa-table usa-table--borderless {{stickyHeader ? 'usa-table--sticky-header' : ''}}">
<table class="usa-table usa-table--borderless {{sticky_header ? 'usa-table--sticky-header' : ''}}">
<caption>Sortable borderless table with various content types</caption>
<thead>
<tr>
Expand Down
3 changes: 1 addition & 2 deletions packages/usa-table/src/usa-table~stickyheader.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"modifier": "usa-table--sticky-header",
"caption": "Sticky header table",
"stickyHeader": true
"sticky_header": true
}