Skip to content

Commit 8d051ea

Browse files
committed
move sticky to mixin
1 parent 5c2643f commit 8d051ea

File tree

4 files changed

+27
-33
lines changed

4 files changed

+27
-33
lines changed

src/cdk/table/can-stick.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {coerceBooleanProperty} from '@angular/cdk/coercion';
10+
911
/** @docs-private */
1012
export type Constructor<T> = new(...args: any[]) => T;
1113

@@ -16,6 +18,9 @@ export type Constructor<T> = new(...args: any[]) => T;
1618
* @docs-private
1719
*/
1820
export interface CanStick {
21+
/** Whether sticky positioning should be applied. */
22+
sticky: boolean;
23+
1924
/** Whether the sticky input has changed since it was last checked. */
2025
_hasStickyChanged: boolean;
2126

@@ -34,6 +39,15 @@ export interface CanStick {
3439
export function mixinHasStickyInput<T extends Constructor<{}>>(base: T):
3540
Constructor<CanStick> & T {
3641
return class extends base {
42+
/** Whether sticky positioning should be applied. */
43+
get sticky(): boolean { return this._sticky; }
44+
set sticky(v: boolean) {
45+
const prevValue = this._sticky;
46+
this._sticky = coerceBooleanProperty(v);
47+
this._hasStickyChanged = prevValue !== this._sticky;
48+
}
49+
_sticky: boolean = false;
50+
3751
/** Whether the sticky input has changed since it was last checked. */
3852
_hasStickyChanged: boolean = false;
3953

src/cdk/table/cell.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ export const _CdkColumnDefBase = mixinHasStickyInput(CdkColumnDefBase);
5151
* Column definition for the CDK table.
5252
* Defines a set of cells available for a table column.
5353
*/
54-
@Directive({selector: '[cdkColumnDef]'})
54+
@Directive({
55+
selector: '[cdkColumnDef]',
56+
inputs: ['sticky']
57+
})
5558
export class CdkColumnDef extends _CdkColumnDefBase implements CanStick {
5659
/** Unique name for this column. */
5760
@Input('cdkColumnDef')
@@ -66,17 +69,11 @@ export class CdkColumnDef extends _CdkColumnDefBase implements CanStick {
6669
}
6770
_name: string;
6871

69-
/** Whether this column should be sticky positioned on the start of the row */
70-
@Input('sticky')
71-
get sticky(): boolean { return this._sticky; }
72-
set sticky(v: boolean) {
73-
const prevValue = this._sticky;
74-
this._sticky = coerceBooleanProperty(v);
75-
this._hasStickyChanged = prevValue !== this._sticky;
76-
}
77-
_sticky: boolean = false;
78-
79-
/** Whether this column should be sticky positioned on the end of the row */
72+
/**
73+
* Whether this column should be sticky positioned on the end of the row. Should make sure
74+
* that it mimics the `CanStick` mixin such that `_hasStickyChanged` is set to true if the value
75+
* has been changed.
76+
*/
8077
@Input('stickyEnd')
8178
get stickyEnd(): boolean { return this._stickyEnd; }
8279
set stickyEnd(v: boolean) {

src/cdk/table/row.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
ViewEncapsulation,
2121
} from '@angular/core';
2222
import {CdkCellDef, CdkColumnDef} from './cell';
23-
import {coerceBooleanProperty} from '@angular/cdk/coercion';
2423
import {CanStick, mixinHasStickyInput} from './can-stick';
2524

2625
/**
@@ -87,14 +86,6 @@ export const _CdkHeaderRowDefBase = mixinHasStickyInput(CdkHeaderRowDefBase);
8786
inputs: ['columns: cdkHeaderRowDef', 'sticky: cdkHeaderRowDefSticky'],
8887
})
8988
export class CdkHeaderRowDef extends _CdkHeaderRowDefBase implements CanStick {
90-
get sticky(): boolean { return this._sticky; }
91-
set sticky(v: boolean) {
92-
const prevValue = this._sticky;
93-
this._sticky = coerceBooleanProperty(v);
94-
this._hasStickyChanged = prevValue !== this._sticky;
95-
}
96-
_sticky: boolean;
97-
9889
constructor(template: TemplateRef<any>, _differs: IterableDiffers) {
9990
super(template, _differs);
10091
}
@@ -114,14 +105,6 @@ export const _CdkFooterRowDefBase = mixinHasStickyInput(CdkFooterRowDefBase);
114105
inputs: ['columns: cdkFooterRowDef', 'sticky: cdkFooterRowDefSticky'],
115106
})
116107
export class CdkFooterRowDef extends _CdkFooterRowDefBase implements CanStick {
117-
get sticky(): boolean { return this._sticky; }
118-
set sticky(v: boolean) {
119-
const prevValue = this._sticky;
120-
this._sticky = coerceBooleanProperty(v);
121-
this._hasStickyChanged = prevValue !== this._sticky;
122-
}
123-
_sticky: boolean;
124-
125108
constructor(template: TemplateRef<any>, _differs: IterableDiffers) {
126109
super(template, _differs);
127110
}

src/cdk/table/sticky-styler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ export class StickyStyler {
2828
/**
2929
* @param isNativeHtmlTable Whether the sticky logic should be based on a table
3030
* that uses the native `<table>` element.
31-
* @param stickCellCSS The CSS class that will be applied to every row/cell that has
31+
* @param stickCellCss The CSS class that will be applied to every row/cell that has
3232
* sticky positioning applied.
3333
* @param direction The directionality context of the table (ltr/rtl); affects column positioning
3434
* by reversing left/right positions.
3535
*/
3636
constructor(private isNativeHtmlTable: boolean,
37-
private stickCellCSS: string,
37+
private stickCellCss: string,
3838
public direction: Direction) { }
3939

4040
/**
@@ -163,7 +163,7 @@ export class StickyStyler {
163163
const hasDirection = STICKY_DIRECTIONS.some(dir => !!element.style[dir]);
164164
if (!hasDirection) {
165165
element.style.position = '';
166-
element.classList.remove(this.stickCellCSS);
166+
element.classList.remove(this.stickCellCss);
167167
}
168168
}
169169

@@ -173,7 +173,7 @@ export class StickyStyler {
173173
* direction and value.
174174
*/
175175
_addStickyStyle(element: HTMLElement, dir: StickyDirection, dirValue: number) {
176-
element.classList.add(this.stickCellCSS);
176+
element.classList.add(this.stickCellCss);
177177
element.style[dir] = `${dirValue}px`;
178178
element.style.cssText += 'position: -webkit-sticky; position: sticky; ';
179179
element.style.zIndex = this._getCalculatedZIndex(element);

0 commit comments

Comments
 (0)