Skip to content

fix(cdk/table): collapse table borders when a fixed layout is used - #34150

Open
vurumalla92 wants to merge 1 commit into
angular:mainfrom
vurumalla92:fix/components-32715-virtual-scroll-border-collapse
Open

vurumalla92 wants to merge 1 commit into
angular:mainfrom
vurumalla92:fix/components-32715-virtual-scroll-border-collapse

Conversation

@vurumalla92

Copy link
Copy Markdown

Fixes #32715.

PR #33439 baked in option 1 from @Fichti1982's workaround in #32715 (overflow-anchor: none on the virtual scroll viewport), but option 2 was only half applied: a fixed layout is forced on when virtual scrolling is enabled (fixedLayout in src/cdk/table/table.ts), yet nothing in the CDK or Material table styles set border-collapse. The table therefore keeps the separate border model while rows are swapped in and out during virtual scrolling, so the table height fluctuates and throws off the scroll calculations — the jumping/shifting still reported on Angular/CDK 22.0.5 (Firefox).

This change adds border-collapse: collapse to the fixed-layout rules, which is exactly the rule a fixed layout is forced on for when virtual scrolling is enabled:

  • src/cdk/table/table.scss — .cdk-table-fixed-layout (covers cdk-table)
  • src/material/table/table.scss — .mat-table-fixed-layout (covers mat-table, which carries its own copy of the rule because the CDK stylesheet is not loaded for Material tables)

Both are one-line additions with a comment explaining why. Material rows only use bottom borders, so collapsing the border model does not change the rendered row separators; it only stops the box-model fluctuations that disturb the virtual scroll math. The docs table-virtual-scroll example (sticky header, itemSize="52") is the affected scenario.

Tests

  • src/cdk/table/table.spec.ts: new test should collapse borders on tables with virtual scrolling asserts getComputedStyle(table).borderCollapse is 'collapse' for a table inside a cdk-virtual-scroll-viewport.
  • src/material/table/table.spec.ts: new test should collapse borders on tables with a fixed layout (with a new minimal MatTableFixedLayoutApp fixture) asserts the same for a mat-table with [fixedLayout]="true".

Verification

  • Compiled both stylesheets with dart-sass: both emit border-collapse: collapse in the fixed-layout rules. Negative control: compiling the pre-fix stylesheets emits only table-layout: fixed (no border-collapse, so the computed value stays the default separate and the new tests fail without this fix).
  • Both edited spec files pass a TypeScript transpile (syntax) check.

Caveats — not verified here

  • The repo's Karma/Bazel unit-test harness could not run in this environment (no pnpm/bazel, no Chrome/Firefox in the VM), so the new unit tests have not been executed yet — CI is the first real run of them.
  • The scrolling behaviour itself was not reproduced or verified in a real browser (no Firefox/Chrome available here), including the Firefox case from the latest report on bug(cdkTable & mat-table): virtual scrolling shifting issues introduced in 21.1 #32715. This PR implements the remaining half of the maintainer-endorsed workaround from that thread; please let me know if you'd rather the Firefox case be investigated separately first.

PR angular#33439 baked in option 1 from angular#32715 (overflow-anchor: none), but
option 2's border-collapse half was never applied: nothing in the CDK or
Material table styles sets border-collapse, so the table keeps the
separate border model while rows are swapped in and out during virtual
scrolling. The resulting height fluctuations throw off the scroll
calculations and the content jumps around, as still reported on
Angular/CDK 22.0.5 (Firefox).

A fixed layout is already forced on whenever virtual scrolling is
enabled (see fixedLayout in table.ts), so collapsing the borders on the
fixed-layout rules covers both cdk-table (.cdk-table-fixed-layout) and
mat-table (.mat-table-fixed-layout, which has its own copy of the rule
because the CDK stylesheet is not loaded for Material tables).

Fixes angular#32715.
@google-cla

google-cla Bot commented Nov 18, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@vurumalla92

Copy link
Copy Markdown
Author

Friendly ping — this PR is waiting on the Google-internal presubmit (google-internal-tests) and pullapprove, plus the missing target: * label. Could someone on the team kick off the presubmit when you have a moment?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(cdkTable & mat-table): virtual scrolling shifting issues introduced in 21.1

1 participant