-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdk/scrolling): make scroller element configurable for virtual s…
…crolling Decouples the scroller from the virtual-scroll-viewport which allows library consumers to use any parent element as a scroller. This is especially helpful when building SPAs with a single global scrollbar. Closes #13862
- Loading branch information
1 parent
7a6549f
commit 3bfb3fe
Showing
11 changed files
with
236 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Directionality} from '@angular/cdk/bidi'; | ||
import {Directive, ElementRef, NgZone, Optional} from '@angular/core'; | ||
import {ScrollDispatcher} from './scroll-dispatcher'; | ||
import {CdkVirtualScrollable, VIRTUAL_SCROLLABLE} from './virtual-scrollable'; | ||
|
||
@Directive({ | ||
selector: '[cdk-virtual-scrollable-element], [cdkVirtualScrollableElement]', | ||
providers: [{provide: VIRTUAL_SCROLLABLE, useExisting: CdkVirtualScrollableElement}], | ||
host: { | ||
'class': 'cdk-virtual-scrollable', | ||
}, | ||
}) | ||
export class CdkVirtualScrollableElement extends CdkVirtualScrollable { | ||
constructor( | ||
elementRef: ElementRef, | ||
scrollDispatcher: ScrollDispatcher, | ||
ngZone: NgZone, | ||
@Optional() dir: Directionality, | ||
) { | ||
super(elementRef, scrollDispatcher, ngZone, dir); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Directionality} from '@angular/cdk/bidi'; | ||
import {Directive, ElementRef, NgZone, Optional} from '@angular/core'; | ||
import {ScrollDispatcher} from './scroll-dispatcher'; | ||
import {CdkVirtualScrollable, VIRTUAL_SCROLLABLE} from './virtual-scrollable'; | ||
|
||
@Directive({ | ||
selector: 'cdk-virtual-scroll-viewport[scrollable-window]', | ||
providers: [{provide: VIRTUAL_SCROLLABLE, useExisting: CdkVirtualScrollableWindow}], | ||
}) | ||
export class CdkVirtualScrollableWindow extends CdkVirtualScrollable { | ||
constructor(scrollDispatcher: ScrollDispatcher, ngZone: NgZone, @Optional() dir: Directionality) { | ||
super(new ElementRef(document.documentElement), scrollDispatcher, ngZone, dir); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Directionality} from '@angular/cdk/bidi'; | ||
import {Directive, ElementRef, InjectionToken, NgZone, Optional} from '@angular/core'; | ||
import {ScrollDispatcher} from './scroll-dispatcher'; | ||
import {CdkScrollable} from './scrollable'; | ||
|
||
export const VIRTUAL_SCROLLABLE = new InjectionToken<CdkVirtualScrollable>('VIRTUAL_SCROLLABLE'); | ||
|
||
@Directive() | ||
export abstract class CdkVirtualScrollable extends CdkScrollable { | ||
constructor( | ||
elementRef: ElementRef<HTMLElement>, | ||
scrollDispatcher: ScrollDispatcher, | ||
ngZone: NgZone, | ||
@Optional() dir?: Directionality, | ||
) { | ||
super(elementRef, scrollDispatcher, ngZone, dir); | ||
} | ||
|
||
measureViewportSize(orientation: 'horizontal' | 'vertical') { | ||
const viewportEl = this.elementRef.nativeElement; | ||
return orientation === 'horizontal' ? viewportEl.clientWidth : viewportEl.clientHeight; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.