Skip to content

Commit 95007e5

Browse files
authored
fix(table): incorrectly sticking multiple footer rows (#19321)
The loop that sticks headers and footers is run in reverse for footers. The problem is that we were only reversing the order of the elements, but not the sticky states which resulted in them being flipped. E.g. setting the last row to be sticky would actually stick the first one. Fixes #19311.
1 parent 72b0219 commit 95007e5

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/cdk/table/sticky-styler.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,14 @@ export class StickyStyler {
119119
}
120120

121121
// If positioning the rows to the bottom, reverse their order when evaluating the sticky
122-
// position such that the last row stuck will be "bottom: 0px" and so on.
123-
const rows = position === 'bottom' ? rowsToStick.reverse() : rowsToStick;
122+
// position such that the last row stuck will be "bottom: 0px" and so on. Note that the
123+
// sticky states need to be reversed as well.
124+
const rows = position === 'bottom' ? rowsToStick.slice().reverse() : rowsToStick;
125+
const states = position === 'bottom' ? stickyStates.slice().reverse() : stickyStates;
124126

125127
let stickyHeight = 0;
126128
for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
127-
if (!stickyStates[rowIndex]) {
129+
if (!states[rowIndex]) {
128130
continue;
129131
}
130132

src/cdk/table/table.spec.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,14 @@ describe('CdkTable', () => {
898898
expectNoStickyStyles(footerRows);
899899
});
900900

901+
it('should stick the correct footer row', () => {
902+
component.stickyFooters = ['footer-3'];
903+
fixture.detectChanges();
904+
905+
expectStickyStyles(footerRows[2], '10', {bottom: '0px'});
906+
expectNoStickyStyles([footerRows[0], footerRows[1]]);
907+
});
908+
901909
it('should stick and unstick left columns', () => {
902910
component.stickyStartColumns = ['column-1', 'column-3'];
903911
fixture.detectChanges();
@@ -1010,11 +1018,11 @@ describe('CdkTable', () => {
10101018
});
10111019

10121020
let footerCells = getFooterCells(footerRows[0]);
1013-
expectStickyStyles(footerRows[0], '10', {bottom: '0px'});
1021+
expectStickyStyles(footerRows[2], '10', {bottom: '0px'});
10141022
expectStickyStyles(footerCells[0], '1', {left: '0px'});
10151023
expectStickyStyles(footerCells[5], '1', {right: '0px'});
10161024
expectNoStickyStyles([footerCells[1], footerCells[2], footerCells[3], footerCells[4]]);
1017-
expectNoStickyStyles([footerRows[1], footerRows[2]]);
1025+
expectNoStickyStyles([footerRows[0], footerRows[1]]);
10181026

10191027
component.stickyHeaders = [];
10201028
component.stickyFooters = [];
@@ -1179,7 +1187,7 @@ describe('CdkTable', () => {
11791187
expectNoStickyStyles([cells[1], cells[2], cells[3], cells[4]]);
11801188
});
11811189

1182-
const footerCells = getFooterCells(footerRows[0]);
1190+
const footerCells = getFooterCells(footerRows[2]);
11831191
expectStickyStyles(footerCells[0], '11', {bottom: '0px', left: '0px'});
11841192
expectStickyStyles(footerCells[1], '10', {bottom: '0px'});
11851193
expectStickyStyles(footerCells[2], '10', {bottom: '0px'});

0 commit comments

Comments
 (0)