-
Notifications
You must be signed in to change notification settings - Fork 156
fix(vhelper): fix padding only when vhelper scrollbar is visible #15972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
65b6b90
fix(vhelper): fix padding only when vhelper scrollbar is visible
didimmova 18c2387
Merge branch '20.0.x' into didimmova/fix-scrollbar-gap
didimmova d7c8f49
chore(base-helper): fix identation
didimmova 2ef141c
chore(tests): try fixing the tests
didimmova b90711f
Merge branch '20.0.x' into didimmova/fix-scrollbar-gap
simeonoff 72ba2d9
feat(vhelper-scrollbar): update implementation
didimmova 91e1234
Merge branch '20.0.x' into didimmova/fix-scrollbar-gap
didimmova 9961c94
chore(vhelper): update document imports
didimmova 1968188
feat(vhelper): use regular if/else statement
didimmova e989bb8
Merge branch '20.0.x' into didimmova/fix-scrollbar-gap
didimmova 0fc13c2
fix(vhelper): use inject api
didimmova c25009d
Merge branch '20.0.x' into didimmova/fix-scrollbar-gap
simeonoff 7318519
Merge branch '20.0.x' into didimmova/fix-scrollbar-gap
simeonoff 13bc7f1
Merge branch '20.0.x' into didimmova/fix-scrollbar-gap
simeonoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -7,11 +7,13 @@ import { | |
| AfterViewInit, | ||
| Inject, | ||
| NgZone, | ||
| DOCUMENT | ||
| Renderer2, | ||
| PLATFORM_ID | ||
| } from '@angular/core'; | ||
| import { Subject } from 'rxjs'; | ||
| import { takeUntil, throttleTime } from 'rxjs/operators'; | ||
| import { resizeObservable, PlatformUtil } from '../../core/utils'; | ||
| import { DOCUMENT, isPlatformBrowser } from '@angular/common'; | ||
|
|
||
| @Directive({ | ||
| selector: '[igxVirtualHelperBase]', | ||
|
|
@@ -34,6 +36,9 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit { | |
| protected _zone: NgZone, | ||
| @Inject(DOCUMENT) public document: any, | ||
| protected platformUtil: PlatformUtil, | ||
| private renderer: Renderer2, | ||
| @Inject(PLATFORM_ID) private platformId: Object, | ||
| private ngZone: NgZone | ||
| ) { | ||
| this._scrollNativeSize = this.calculateScrollNativeSize(); | ||
| } | ||
|
|
@@ -104,6 +109,31 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit { | |
| return this.document.body.contains(this.nativeElement); | ||
| } | ||
|
|
||
| private toggleClass(element: HTMLElement, className: string, add: boolean): void { | ||
| if (!element) return; | ||
| add ? this.renderer.addClass(element, className) : this.renderer.removeClass(element, className); | ||
|
||
| } | ||
|
|
||
| private updateScrollbarClass() { | ||
| if (!isPlatformBrowser(this.platformId)) { | ||
| return; | ||
| } | ||
|
|
||
| this.ngZone.runOutsideAngular(() => { | ||
| requestAnimationFrame(() => { | ||
| const el = this.nativeElement; | ||
| const hasScrollbar = el.scrollHeight > el.clientHeight; | ||
| const prevSibling = el.previousElementSibling as HTMLElement | null; | ||
| const scrollbarClass = 'igx-display-container--scrollbar'; | ||
|
|
||
| if (prevSibling?.tagName.toLowerCase() === 'igx-display-container') { | ||
| this.toggleClass(prevSibling, scrollbarClass, hasScrollbar); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| protected handleMutations(event) { | ||
| const hasSize = !(event[0].contentRect.height === 0 && event[0].contentRect.width === 0); | ||
| if (!hasSize && !this.isAttachedToDom) { | ||
|
|
@@ -113,6 +143,8 @@ export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit { | |
| // attached back now. | ||
| this.restoreScroll(); | ||
| } | ||
|
|
||
| this.updateScrollbarClass(); | ||
| } | ||
|
|
||
| protected restoreScroll() {} | ||
|
|
||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to use the inject API so you don't have to also modify all classes that extend the base class.