Skip to content

Commit dcbdeff

Browse files
authored
fix(gantt): 纵向滚动条往下拖动会弹回到拉动的位置 (#569)
1 parent c858aa0 commit dcbdeff

File tree

4 files changed

+46
-14
lines changed

4 files changed

+46
-14
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<div
22
class="gantt-scrollbar"
3-
[ngClass]="{ 'gantt-scrollbar-bg': hasFooter }"
4-
[style.height.px]="ganttRoot?.horizontalScrollbarHeight + 1"
5-
[style.right.px]="ganttRoot?.verticalScrollbarWidth"
3+
[ngClass]="{ 'gantt-scrollbar-bg': hasFooter() }"
4+
[style.height.px]="ganttRoot()?.horizontalScrollbarHeight + 1"
5+
[style.right.px]="ganttRoot()?.verticalScrollbarWidth"
66
>
77
<div
88
class="gantt-table-scrollbar"
99
syncScrollX="ganttTableXScroll"
10-
[class.with-scrollbar]="ganttRoot?.horizontalScrollbarHeight"
11-
[style.width.px]="tableWidth"
10+
[class.with-scrollbar]="ganttRoot()?.horizontalScrollbarHeight"
11+
[style.width.px]="tableWidth()"
1212
>
13-
<div class="h-100" [style.width.px]="ganttRoot.ganttUpper['ganttTableBody']?.elementRef?.nativeElement?.offsetWidth - 1 || 0"></div>
13+
<div class="h-100" [style.width.px]="tableScrollWidth() - 1"></div>
1414
</div>
1515
<div class="gantt-main-scrollbar" syncScrollX="ganttMainXScroll">
16-
<div class="h-100" [style.width.px]="ganttRoot['view']?.width"></div>
16+
<div class="h-100" [style.width.px]="ganttRoot()['view']?.width"></div>
1717
</div>
1818
</div>
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Component, Inject, Input } from '@angular/core';
2-
import { GANTT_UPPER_TOKEN, GanttUpper } from '../../gantt-upper';
31
import { NgClass } from '@angular/common';
2+
import { Component, Inject, input } from '@angular/core';
3+
import { GANTT_UPPER_TOKEN, GanttUpper } from '../../gantt-upper';
44
import { NgxGanttRootComponent } from '../../root.component';
55
import { GanttSyncScrollXDirective } from '../../directives/sync-scroll.directive';
66

@@ -10,11 +10,13 @@ import { GanttSyncScrollXDirective } from '../../directives/sync-scroll.directiv
1010
imports: [NgClass, GanttSyncScrollXDirective]
1111
})
1212
export class GanttScrollbarComponent {
13-
@Input() hasFooter: boolean = false;
13+
hasFooter = input<boolean>(false);
14+
15+
tableWidth = input<number>();
1416

15-
@Input() tableWidth: number;
17+
ganttRoot = input<NgxGanttRootComponent>();
1618

17-
@Input() ganttRoot: NgxGanttRootComponent;
19+
tableScrollWidth = input<number>(0);
1820

1921
constructor(@Inject(GANTT_UPPER_TOKEN) public ganttUpper: GanttUpper) {}
2022
}

packages/gantt/src/gantt.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
[ganttRoot]="ganttRoot"
8383
[hasFooter]="!!table?.tableFooterTemplate"
8484
[tableWidth]="tableHeader.tableWidth"
85+
[tableScrollWidth]="tableScrollWidth()"
8586
></gantt-scrollbar>
8687

8788
@if (table?.tableFooterTemplate || footerTemplate) {

packages/gantt/src/gantt.component.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import {
2020
SimpleChanges,
2121
TemplateRef,
2222
ViewChild,
23-
forwardRef
23+
forwardRef,
24+
signal
2425
} from '@angular/core';
2526
import { Observable, from } from 'rxjs';
2627
import { finalize, skip, take, takeUntil } from 'rxjs/operators';
@@ -44,6 +45,7 @@ import { GanttMainComponent } from './components/main/gantt-main.component';
4445
import { GanttScrollbarComponent } from './components/scrollbar/scrollbar.component';
4546
import { GanttTableBodyComponent } from './components/table/body/gantt-table-body.component';
4647
import { GanttTableHeaderComponent } from './components/table/header/gantt-table-header.component';
48+
import { GanttSyncScrollXDirective, GanttSyncScrollYDirective } from './directives/sync-scroll.directive';
4749
import { GANTT_ABSTRACT_TOKEN } from './gantt-abstract';
4850
import { GANTT_UPPER_TOKEN, GanttUpper } from './gantt-upper';
4951
import { GANTT_GLOBAL_CONFIG, GanttGlobalConfig } from './gantt.config';
@@ -52,7 +54,6 @@ import { NgxGanttTableColumnComponent } from './table/gantt-column.component';
5254
import { NgxGanttTableComponent } from './table/gantt-table.component';
5355
import { GanttDate } from './utils/date';
5456
import { Dictionary, keyBy, recursiveItems, uniqBy } from './utils/helpers';
55-
import { GanttSyncScrollXDirective, GanttSyncScrollYDirective } from './directives/sync-scroll.directive';
5657

5758
@Component({
5859
selector: 'ngx-gantt',
@@ -141,6 +142,10 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, OnChanges,
141142

142143
@ViewChild('ganttTableBody', { static: true }) ganttTableBody: ElementRef<HTMLDivElement>;
143144

145+
public tableScrollWidth = signal<number>(0);
146+
147+
private resizeObserver: ResizeObserver;
148+
144149
get loading() {
145150
return this._loading;
146151
}
@@ -229,6 +234,7 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, OnChanges,
229234
this.computeTempDataRefs();
230235
});
231236
}
237+
this.initScrollContainerObserver();
232238
}
233239

234240
ngAfterViewChecked() {
@@ -413,4 +419,27 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, OnChanges,
413419
this.table.dragEnded.emit(event);
414420
this.draggingItem = null;
415421
}
422+
423+
private initScrollContainerObserver() {
424+
if (this.ganttTableBody && this.ganttTableBody['elementRef']?.nativeElement) {
425+
this.tableScrollWidth.set(this.ganttTableBody['elementRef'].nativeElement.clientWidth);
426+
if (typeof ResizeObserver !== 'undefined') {
427+
this.resizeObserver = new ResizeObserver((entries) => {
428+
const newWidth = entries[0].target.clientWidth;
429+
if (this.tableScrollWidth() !== newWidth) {
430+
this.tableScrollWidth.set(newWidth);
431+
this.cdr.markForCheck();
432+
}
433+
});
434+
this.resizeObserver.observe(this.ganttTableBody['elementRef'].nativeElement);
435+
}
436+
}
437+
}
438+
439+
override ngOnDestroy() {
440+
super.ngOnDestroy();
441+
if (this.resizeObserver) {
442+
this.resizeObserver.disconnect();
443+
}
444+
}
416445
}

0 commit comments

Comments
 (0)