Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: known drawer issues #531

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/neat-pots-doubt.md
Original file line number Diff line number Diff line change
@@ -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
13 changes: 8 additions & 5 deletions src/drawer/component/drawer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export class DrawerComponent<
footer: string | TemplateRef<C>;

@Input()
size: DrawerSize = DrawerSize.Medium;
size: DrawerSize;

@Input()
offsetY = '0px';
offsetY: string;

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

@Input()
hideOnClickOutside = false;
hideOnClickOutside: boolean;

@Input()
showClose = true;
showClose: boolean;

@Input()
drawerClass: string;
Expand All @@ -69,14 +69,17 @@ export class DrawerComponent<
maskClosable: boolean;

@Input()
divider = true;
divider: boolean;

@Input()
width: number;

@Input()
contentParams: C;

@Input()
disposeWhenHide = false;

@Output()
readonly close = new EventEmitter<R>();

Expand Down
25 changes: 21 additions & 4 deletions src/drawer/drawer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -38,7 +46,10 @@ export class DrawerService<
}

updateOptions(options: DrawerOptions<T, C>): void {
this.options = options;
this.options = {
...(DEFAULT_OPTIONS as DrawerOptions<T, C>),
JounQin marked this conversation as resolved.
Show resolved Hide resolved
...options,
};
}

private createOverlay() {
Expand Down Expand Up @@ -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();
}
});
Expand All @@ -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();
}
}
1 change: 1 addition & 0 deletions src/drawer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export interface DrawerOptions<T = unknown, C extends object = object> {
mask?: boolean;
maskClosable?: boolean; // 点击背景是否关闭抽屉
hideOnClickOutside?: boolean; // 在抽屉外点击是否关闭抽屉,与 maskClosable 的区别是是否有 mask
disposeWhenHide?: boolean; // 抽屉不可见时是否销毁,使用组件方式时默认为false
}
Loading