Skip to content

fix: table header background ignores container-level dark mode - #4765

Draft
ernst-dev wants to merge 1 commit into
mainfrom
feat/table-dark-mode-container
Draft

fix: table header background ignores container-level dark mode#4765
ernst-dev wants to merge 1 commit into
mainfrom
feat/table-dark-mode-container

Conversation

@ernst-dev

Copy link
Copy Markdown
Member

Summary

Fixes #4111

When .awsui-dark-mode is applied to a container ancestor rather than <body>, the sticky table header and <thead> background-color were not updating to the dark value — they showed the light fallback (#fafafa) instead.

Root cause

The design token CSS custom properties are defined inside @layer awsui-base-theme { body { ... } }. The dark-mode override block is also nested inside this body rule, so the token override is set on the .awsui-dark-mode element. While CSS custom properties cascade, the @layer interaction with unlayered component styles means an explicit dark-mode-only rule is needed in the component SCSS to guarantee correct token resolution when dark mode is scoped to a container.

Fix

Use the dark-mode-only() mixin (from internal/styles/utils/theming) in:

  • src/table/styles.scss — for .header-secondary (the sticky header wrapper div)
  • src/table/header-cell/styles.scss — for .header-cell, .header-cell.sticky-cell, and full-page variant backgrounds

This generates .awsui-dark-mode .header-secondary and .awsui-dark-mode .header-cell rules that correctly win the cascade for container-level dark mode.

Dev page

Added pages/table/dark-mode-container.page.tsx as a regression test page showing:

  1. Baseline light-mode table
  2. Table inside a .awsui-dark-mode container div (the failing scenario)
  3. Table with sticky columns inside a .awsui-dark-mode container div

Testing

  • Build: ✅ passes (npm run build)
  • Unit tests: ✅ 589 suites, 13168 passed, 162 skipped, 0 failed (gulp test:unit)

When .awsui-dark-mode is applied to a container ancestor rather than
<body>, the sticky table header and thead background-color token
(color-background-table-header) was not updating to the dark value.

Root cause: the design token CSS custom properties are defined inside
@layer awsui-base-theme { body { ... } }. The dark-mode override block
is also nested inside this body rule, so the token value is set on the
.awsui-dark-mode element. While CSS custom properties cascade, the
@layer specificity means that an explicit dark-mode-only rule in the
component SCSS is needed to guarantee the correct token resolution when
dark mode is scoped to a container.

Fix: use the dark-mode-only() mixin (from internal/styles/utils/theming)
in src/table/styles.scss and src/table/header-cell/styles.scss to
re-declare the background property inside the dark-mode selector. This
generates a .awsui-dark-mode .header-secondary and
.awsui-dark-mode .header-cell rule that correctly wins the cascade for
container-level dark mode.

Affected elements:
- .header-secondary (sticky header wrapper div)
- .header-cell (thead <th> cells)
- .header-cell.sticky-cell (sticky column header cells)
- full-page variant backgrounds

Dev page: pages/table/dark-mode-container.page.tsx
Regression test for container-level dark mode with stickyHeader and
stickyColumns.

Fixes #4111
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.

[Bug]: Table header not respecting container-level dark mode

1 participant