Skip to content

Commit

Permalink
refactor(multiple): remove DOM emulation usage from table components
Browse files Browse the repository at this point in the history
DOM manipulation and emulation prevents the table component from being hydrated. These changes refactor it to avoid them.
  • Loading branch information
devknoll committed Oct 19, 2023
1 parent cf124b3 commit dec74e7
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 140 deletions.
7 changes: 0 additions & 7 deletions src/cdk/table/sticky-styler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class StickyStyler {
private _stickCellCss: string,
public direction: Direction,
private _coalescedStyleScheduler: _CoalescedStyleScheduler,
private _isBrowser = true,
private readonly _needsPositionStickyOnElement = true,
private readonly _positionListener?: StickyPositioningListener,
) {
Expand Down Expand Up @@ -109,7 +108,6 @@ export class StickyStyler {
) {
if (
!rows.length ||
!this._isBrowser ||
!(stickyStartStates.some(state => state) || stickyEndStates.some(state => state))
) {
if (this._positionListener) {
Expand Down Expand Up @@ -183,11 +181,6 @@ export class StickyStyler {
*
*/
stickRows(rowsToStick: HTMLElement[], stickyStates: boolean[], position: 'top' | 'bottom') {
// Since we can't measure the rows on the server, we can't stick the rows properly.
if (!this._isBrowser) {
return;
}

// If positioning the rows to the bottom, reverse their order when evaluating the sticky
// position such that the last row stuck will be "bottom: 0px" and so on. Note that the
// sticky states need to be reversed as well.
Expand Down
10 changes: 10 additions & 0 deletions src/cdk/table/table-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import {
CdkRecycleRows,
FooterRowOutlet,
NoDataRowOutlet,
NativeBody,
NativeFoot,
NativeHead,
TableOutlet,
OutletSource,
} from './table';
import {
CdkCellOutlet,
Expand Down Expand Up @@ -60,6 +65,11 @@ const EXPORTED_DECLARATIONS = [
CdkNoDataRow,
CdkRecycleRows,
NoDataRowOutlet,
NativeBody,
NativeFoot,
NativeHead,
TableOutlet,
OutletSource,
];

@NgModule({
Expand Down
5 changes: 3 additions & 2 deletions src/cdk/table/table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ describe('CdkTable', () => {
});

it('should clear the row view containers on destroy', () => {
const rowOutlet = fixture.componentInstance.table._rowOutlet.viewContainer;
const headerPlaceholder = fixture.componentInstance.table._headerRowOutlet.viewContainer;
const rowOutlet = fixture.componentInstance.table._outletSource.rowOutlet.viewContainer;
const headerPlaceholder =
fixture.componentInstance.table._outletSource.headerRowOutlet.viewContainer;

spyOn(rowOutlet, 'clear').and.callThrough();
spyOn(headerPlaceholder, 'clear').and.callThrough();
Expand Down
Loading

0 comments on commit dec74e7

Please sign in to comment.