Skip to content

Commit 780dfb2

Browse files
authored
fix: known drawer issues (#531)
Co-authored-by: tianwenjie <igauch@qq.com>
1 parent 4bb7e03 commit 780dfb2

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

.changeset/neat-pots-doubt.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@alauda/ui': patch
3+
---
4+
5+
- fix: no default config for using service mode
6+
- fix: not auto destroy when hiding for using service mode

src/drawer/component/drawer.component.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ export class DrawerComponent<
4242
footer: string | TemplateRef<C>;
4343

4444
@Input()
45-
size: DrawerSize = DrawerSize.Medium;
45+
size: DrawerSize;
4646

4747
@Input()
48-
offsetY = '0px';
48+
offsetY: string;
4949

5050
@Input()
5151
visible: boolean;
@@ -54,10 +54,10 @@ export class DrawerComponent<
5454
content: TemplateRef<C> | ComponentType<T>;
5555

5656
@Input()
57-
hideOnClickOutside = false;
57+
hideOnClickOutside: boolean;
5858

5959
@Input()
60-
showClose = true;
60+
showClose: boolean;
6161

6262
@Input()
6363
drawerClass: string;
@@ -69,14 +69,17 @@ export class DrawerComponent<
6969
maskClosable: boolean;
7070

7171
@Input()
72-
divider = true;
72+
divider: boolean;
7373

7474
@Input()
7575
width: number;
7676

7777
@Input()
7878
contentParams: C;
7979

80+
@Input()
81+
disposeWhenHide = false;
82+
8083
@Output()
8184
readonly close = new EventEmitter<R>();
8285

src/drawer/drawer.service.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ import { debounceTime, filter, fromEvent, Subject, takeUntil } from 'rxjs';
55

66
import { DrawerInternalComponent } from './component/internal/internal.component';
77
import { DrawerRef } from './drawer-ref';
8-
import { DrawerOptions } from './types';
8+
import { DrawerOptions, DrawerSize } from './types';
99

1010
const DRAWER_OVERLAY_CLASS = 'aui-drawer-overlay';
11+
const DEFAULT_OPTIONS: DrawerOptions = {
12+
size: DrawerSize.Medium,
13+
offsetY: '0',
14+
showClose: true,
15+
hideOnClickOutside: false,
16+
divider: true,
17+
disposeWhenHide: true,
18+
};
1119

1220
@Injectable()
1321
export class DrawerService<
@@ -38,7 +46,10 @@ export class DrawerService<
3846
}
3947

4048
updateOptions(options: DrawerOptions<T, C>): void {
41-
this.options = options;
49+
this.options = {
50+
...(DEFAULT_OPTIONS as DrawerOptions<T, C>),
51+
...options,
52+
};
4253
}
4354

4455
private createOverlay() {
@@ -93,6 +104,7 @@ export class DrawerService<
93104
drawerInternalComponentRef.instance.animationStep$.subscribe(step => {
94105
if (step === 'hideDone') {
95106
this.invisible$.next();
107+
this.options.disposeWhenHide && this.dispose();
96108
this.overlayRef?.getConfig().scrollStrategy.disable();
97109
}
98110
});
@@ -109,12 +121,17 @@ export class DrawerService<
109121
});
110122
}
111123

112-
ngOnDestroy(): void {
113-
this.invisible$.next();
124+
private dispose() {
114125
if (this.overlayRef) {
115126
this.overlayRef.getConfig().scrollStrategy.disable();
116127
this.overlayRef.dispose();
117128
this.overlayRef = null;
118129
}
130+
this.drawerInternalComponentRef = null;
131+
}
132+
133+
ngOnDestroy(): void {
134+
this.invisible$.next();
135+
this.dispose();
119136
}
120137
}

src/drawer/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ export interface DrawerOptions<T = unknown, C extends object = object> {
2626
mask?: boolean;
2727
maskClosable?: boolean; // 点击背景是否关闭抽屉
2828
hideOnClickOutside?: boolean; // 在抽屉外点击是否关闭抽屉,与 maskClosable 的区别是是否有 mask
29+
disposeWhenHide?: boolean; // 抽屉不可见时是否销毁,使用组件方式时默认为false
2930
}

0 commit comments

Comments
 (0)