Skip to content

feat(table-container): sticky table header for tall tables#1585

Draft
caugner wants to merge 1 commit into
mainfrom
sticky-table-headers
Draft

feat(table-container): sticky table header for tall tables#1585
caugner wants to merge 1 commit into
mainfrom
sticky-table-headers

Conversation

@caugner

@caugner caugner commented May 19, 2026

Copy link
Copy Markdown
Contributor

Description

Add a sticky <thead> for tables wrapped in .table-container that have at least 10 body rows. A new hooks/sticky-table-header.js:

  • clones each qualifying <thead> into a position: fixed overlay placed just below the sticky page header,
  • mirrors the table-container's horizontal scroll position via transform: translateX(...), and
  • copies each header cell's computed width so columns stay aligned.

The overlay shifts up by the cell's computed border-top-width so it overlaps the breadcrumbs bar's 1px bottom border instead of stacking with it.

Motivation

Make column headers remain visible while scrolling through long content tables, without changing how .table-container handles wide tables. Native position: sticky can't be used because .table-container sets overflow-x: auto, which makes it a scroll container on both axes and confines sticky positioning within it instead of relative to the viewport.

Additional details

  • Opt-in by row count (≥10 body rows) to avoid wasted DOM on short tables.
  • Vertical offset is read from .page-layout__header's bottom edge at runtime, so it follows the page header height.
  • Horizontal scroll within .table-container is mirrored on the clone via translateX(-scrollLeft).
  • The overlay has pointer-events: none — interactive elements inside <th> (e.g. sort buttons) are not clickable while the clone is shown.
  • ResizeObserver keeps cell widths in sync when the table or container resizes.

Example: https://fred-pr1585.review.mdn.allizom.net/en-US/docs/Web/HTML/Reference/Attributes#attribute_list

Related issues or pull requests

Fixes #933.

Clone the `<thead>` into a fixed-position overlay that appears below the
sticky page header when a `.table-container` table with at least 10 body
rows scrolls past the breadcrumbs bar. The overlay mirrors the table's
horizontal scroll position and shifts up by the cell's `border-top-width`
to overlap the breadcrumbs bar's bottom border.

Native `position: sticky` cannot be used here because `.table-container`
sets `overflow-x: auto`, which makes it a scroll container on both axes
and confines sticky positioning within it instead of relative to the
viewport.
@github-actions

Copy link
Copy Markdown
Contributor

86e7aff was deployed to: https://fred-pr1585.review.mdn.allizom.net/

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.

Make table header sticky on lengthy tables

2 participants