Skip to content

Commit 607c016

Browse files
authored
fix: drawer scroll strategy adjust (#521)
1 parent a2a2daa commit 607c016

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

.changeset/blue-comics-sparkle.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@alauda/ui": patch
3+
---
4+
5+
fix: drawer scroll strategy adjust

src/dialog/dialog.component.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
ViewEncapsulation,
1919
Renderer2,
2020
} from '@angular/core';
21+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
22+
import { debounceTime, filter, fromEvent } from 'rxjs';
2123

2224
import { Bem, buildBem, getElementOffset } from '../utils';
2325

@@ -99,7 +101,21 @@ export class DialogComponent {
99101
constructor(
100102
private readonly elementRef: ElementRef<HTMLElement>,
101103
private readonly render: Renderer2,
102-
) {}
104+
) {
105+
// Issues: https://github.com/angular/components/issues/10841
106+
// scrollStrategy 为 Block 时,若创建 Overlay 时,高度不足以出现滚动,则 scrollStrategy 不会生效
107+
fromEvent(window, 'resize')
108+
.pipe(
109+
debounceTime(100),
110+
filter(
111+
() => document.documentElement.scrollHeight > window.innerHeight,
112+
),
113+
takeUntilDestroyed(),
114+
)
115+
.subscribe(() => {
116+
this.overlayRef?.getConfig().scrollStrategy.enable();
117+
});
118+
}
103119

104120
attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T> {
105121
if (this.portalOutlet.hasAttached()) {

src/drawer/component/drawer.component.ts

+28-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ import {
3333
ViewContainerRef,
3434
ViewEncapsulation,
3535
} from '@angular/core';
36-
import { Observable, Subject, takeUntil } from 'rxjs';
36+
import {
37+
Observable,
38+
Subject,
39+
debounceTime,
40+
filter,
41+
fromEvent,
42+
takeUntil,
43+
} from 'rxjs';
3744

3845
import { IconComponent } from '../../icon/icon.component';
3946
import { isTemplateRef } from '../../utils';
@@ -192,6 +199,23 @@ export class DrawerComponent<
192199
this.attachOverlay();
193200
this.updateBodyOverflow();
194201
this.templateContext = { $implicit: this.contentParams };
202+
203+
if (this.mask) {
204+
// Issues: https://github.com/angular/components/issues/10841
205+
// scrollStrategy 为 Block 时,若创建 Overlay 时,高度不足以出现滚动,则 scrollStrategy 不会生效
206+
fromEvent(window, 'resize')
207+
.pipe(
208+
debounceTime(100),
209+
filter(
210+
() => document.documentElement.scrollHeight > window.innerHeight,
211+
),
212+
takeUntil(this.onDestroy$),
213+
)
214+
.subscribe(() => {
215+
this.overlayRef.getConfig().scrollStrategy.enable();
216+
});
217+
}
218+
195219
this.cdr.detectChanges();
196220
}
197221

@@ -249,7 +273,9 @@ export class DrawerComponent<
249273
return new OverlayConfig({
250274
panelClass: DRAWER_OVERLAY_CLASS,
251275
positionStrategy: this.overlay.position().global(),
252-
scrollStrategy: this.overlay.scrollStrategies.block(),
276+
scrollStrategy: this.mask
277+
? this.overlay.scrollStrategies.block()
278+
: this.overlay.scrollStrategies.noop(),
253279
});
254280
}
255281

0 commit comments

Comments
 (0)