From 780dfb2830a0cbac327496e13934240760ea36fc Mon Sep 17 00:00:00 2001 From: igauch Date: Thu, 14 Dec 2023 15:36:46 +0800 Subject: [PATCH] fix: known drawer issues (#531) Co-authored-by: tianwenjie --- .changeset/neat-pots-doubt.md | 6 ++++++ src/drawer/component/drawer.component.ts | 13 +++++++----- src/drawer/drawer.service.ts | 25 ++++++++++++++++++++---- src/drawer/types.ts | 1 + 4 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 .changeset/neat-pots-doubt.md diff --git a/.changeset/neat-pots-doubt.md b/.changeset/neat-pots-doubt.md new file mode 100644 index 000000000..e466955b8 --- /dev/null +++ b/.changeset/neat-pots-doubt.md @@ -0,0 +1,6 @@ +--- +'@alauda/ui': patch +--- + +- fix: no default config for using service mode +- fix: not auto destroy when hiding for using service mode diff --git a/src/drawer/component/drawer.component.ts b/src/drawer/component/drawer.component.ts index 765b82421..b356e614b 100644 --- a/src/drawer/component/drawer.component.ts +++ b/src/drawer/component/drawer.component.ts @@ -42,10 +42,10 @@ export class DrawerComponent< footer: string | TemplateRef; @Input() - size: DrawerSize = DrawerSize.Medium; + size: DrawerSize; @Input() - offsetY = '0px'; + offsetY: string; @Input() visible: boolean; @@ -54,10 +54,10 @@ export class DrawerComponent< content: TemplateRef | ComponentType; @Input() - hideOnClickOutside = false; + hideOnClickOutside: boolean; @Input() - showClose = true; + showClose: boolean; @Input() drawerClass: string; @@ -69,7 +69,7 @@ export class DrawerComponent< maskClosable: boolean; @Input() - divider = true; + divider: boolean; @Input() width: number; @@ -77,6 +77,9 @@ export class DrawerComponent< @Input() contentParams: C; + @Input() + disposeWhenHide = false; + @Output() readonly close = new EventEmitter(); diff --git a/src/drawer/drawer.service.ts b/src/drawer/drawer.service.ts index fcad4da05..fada83d1e 100644 --- a/src/drawer/drawer.service.ts +++ b/src/drawer/drawer.service.ts @@ -5,9 +5,17 @@ import { debounceTime, filter, fromEvent, Subject, takeUntil } from 'rxjs'; import { DrawerInternalComponent } from './component/internal/internal.component'; import { DrawerRef } from './drawer-ref'; -import { DrawerOptions } from './types'; +import { DrawerOptions, DrawerSize } from './types'; const DRAWER_OVERLAY_CLASS = 'aui-drawer-overlay'; +const DEFAULT_OPTIONS: DrawerOptions = { + size: DrawerSize.Medium, + offsetY: '0', + showClose: true, + hideOnClickOutside: false, + divider: true, + disposeWhenHide: true, +}; @Injectable() export class DrawerService< @@ -38,7 +46,10 @@ export class DrawerService< } updateOptions(options: DrawerOptions): void { - this.options = options; + this.options = { + ...(DEFAULT_OPTIONS as DrawerOptions), + ...options, + }; } private createOverlay() { @@ -93,6 +104,7 @@ export class DrawerService< drawerInternalComponentRef.instance.animationStep$.subscribe(step => { if (step === 'hideDone') { this.invisible$.next(); + this.options.disposeWhenHide && this.dispose(); this.overlayRef?.getConfig().scrollStrategy.disable(); } }); @@ -109,12 +121,17 @@ export class DrawerService< }); } - ngOnDestroy(): void { - this.invisible$.next(); + private dispose() { if (this.overlayRef) { this.overlayRef.getConfig().scrollStrategy.disable(); this.overlayRef.dispose(); this.overlayRef = null; } + this.drawerInternalComponentRef = null; + } + + ngOnDestroy(): void { + this.invisible$.next(); + this.dispose(); } } diff --git a/src/drawer/types.ts b/src/drawer/types.ts index be58712aa..f360e0c54 100644 --- a/src/drawer/types.ts +++ b/src/drawer/types.ts @@ -26,4 +26,5 @@ export interface DrawerOptions { mask?: boolean; maskClosable?: boolean; // 点击背景是否关闭抽屉 hideOnClickOutside?: boolean; // 在抽屉外点击是否关闭抽屉,与 maskClosable 的区别是是否有 mask + disposeWhenHide?: boolean; // 抽屉不可见时是否销毁,使用组件方式时默认为false }