Skip to content

fix: issue number 4 where the grid doesnt adhere to the dynamic scrollbars #83

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion projects/angular-grid-layout/src/lib/grid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,36 @@ export class KtdGridComponent implements OnChanges, AfterContentInit, AfterConte
* Parent element that contains the scroll. If an string is provided it would search that element by id on the dom.
* If no data provided or null autoscroll is not performed.
*/
@Input() scrollableParent: HTMLElement | Document | string | null = null;
@Input() set scrollableParent(val: HTMLElement | Document | string | null) {
this.scrollParentIntersectionObserver?.unobserve(this.elementRef.nativeElement);
this.scrollParentIntersectionObserver?.disconnect();

if (val) {
this._scrollableParent = val;
const scrollParent = typeof this.scrollableParent === 'string' ? document.getElementById(this.scrollableParent) : this.scrollableParent;

// we trigger only if the whole grid becomes visible of not
let options = {
root: scrollParent ,
rootMargin: "0px",
threshold: 1,
};

// if the grid changes from completely visible to not completely visible in the scroll container we do a resize.
// this makes sure the grid stays positioned correctly
this.scrollParentIntersectionObserver = new IntersectionObserver(() => {
this.resize();
}, options);

this.scrollParentIntersectionObserver.observe(this.elementRef.nativeElement);
}
};

get scrollableParent(): HTMLElement | Document | string | null {
return this._scrollableParent;
}

private _scrollableParent: HTMLElement | Document | string | null = null;

/** Whether or not to update the internal layout when some dependent property change. */
@Input()
Expand Down Expand Up @@ -271,6 +300,8 @@ export class KtdGridComponent implements OnChanges, AfterContentInit, AfterConte
private _gridItemsRenderData: KtdDictionary<KtdGridItemRenderData<number>>;
private subscriptions: Subscription[];

private scrollParentIntersectionObserver:IntersectionObserver;

constructor(private gridService: KtdGridService,
private elementRef: ElementRef,
private viewContainerRef: ViewContainerRef,
Expand Down Expand Up @@ -326,6 +357,8 @@ export class KtdGridComponent implements OnChanges, AfterContentInit, AfterConte

ngOnDestroy() {
this.subscriptions.forEach(sub => sub.unsubscribe());
this.scrollParentIntersectionObserver?.unobserve(this.elementRef.nativeElement);
this.scrollParentIntersectionObserver?.disconnect();
}

compactLayout() {
Expand Down