From fee27798fc28e2b7717531fc750f5ab8f12898b1 Mon Sep 17 00:00:00 2001 From: tianwenjie Date: Thu, 14 Dec 2023 13:06:53 +0800 Subject: [PATCH 1/2] fix: drawer default option --- src/drawer/component/drawer.component.ts | 8 ++++---- src/drawer/drawer.service.ts | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/drawer/component/drawer.component.ts b/src/drawer/component/drawer.component.ts index 765b82421..cdd97891e 100644 --- a/src/drawer/component/drawer.component.ts +++ b/src/drawer/component/drawer.component.ts @@ -42,7 +42,7 @@ export class DrawerComponent< footer: string | TemplateRef; @Input() - size: DrawerSize = DrawerSize.Medium; + size: DrawerSize; @Input() offsetY = '0px'; @@ -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; diff --git a/src/drawer/drawer.service.ts b/src/drawer/drawer.service.ts index fcad4da05..37db14b19 100644 --- a/src/drawer/drawer.service.ts +++ b/src/drawer/drawer.service.ts @@ -5,9 +5,16 @@ 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 defaultOptions: DrawerOptions = { + size: DrawerSize.Medium, + offsetY: '0px', + showClose: true, + hideOnClickOutside: true, + divider: true, +}; @Injectable() export class DrawerService< @@ -38,7 +45,10 @@ export class DrawerService< } updateOptions(options: DrawerOptions): void { - this.options = options; + this.options = { + ...(defaultOptions as DrawerOptions), + ...options, + }; } private createOverlay() { From 811149bf571b38d76dc44788ffc2f476655072fd Mon Sep 17 00:00:00 2001 From: tianwenjie Date: Thu, 14 Dec 2023 15:04:48 +0800 Subject: [PATCH 2/2] fix: drawer hide can dispose --- .changeset/neat-pots-doubt.md | 6 ++++++ src/drawer/component/drawer.component.ts | 5 ++++- src/drawer/drawer.service.ts | 19 +++++++++++++------ src/drawer/types.ts | 1 + 4 files changed, 24 insertions(+), 7 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 cdd97891e..b356e614b 100644 --- a/src/drawer/component/drawer.component.ts +++ b/src/drawer/component/drawer.component.ts @@ -45,7 +45,7 @@ export class DrawerComponent< size: DrawerSize; @Input() - offsetY = '0px'; + offsetY: string; @Input() visible: boolean; @@ -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 37db14b19..fada83d1e 100644 --- a/src/drawer/drawer.service.ts +++ b/src/drawer/drawer.service.ts @@ -8,12 +8,13 @@ import { DrawerRef } from './drawer-ref'; import { DrawerOptions, DrawerSize } from './types'; const DRAWER_OVERLAY_CLASS = 'aui-drawer-overlay'; -const defaultOptions: DrawerOptions = { +const DEFAULT_OPTIONS: DrawerOptions = { size: DrawerSize.Medium, - offsetY: '0px', + offsetY: '0', showClose: true, - hideOnClickOutside: true, + hideOnClickOutside: false, divider: true, + disposeWhenHide: true, }; @Injectable() @@ -46,7 +47,7 @@ export class DrawerService< updateOptions(options: DrawerOptions): void { this.options = { - ...(defaultOptions as DrawerOptions), + ...(DEFAULT_OPTIONS as DrawerOptions), ...options, }; } @@ -103,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(); } }); @@ -119,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 }