Skip to content

Commit

Permalink
fix: drawer option update sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Lufan You authored and fengtianze committed Apr 25, 2024
1 parent fbc5cc0 commit 11caa9d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/drawer/component/drawer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export class DrawerComponent<
this.drawerRef.close();
}
}
this.drawerService.updateOptions(this);
}

ngAfterViewInit() {
Expand Down
11 changes: 10 additions & 1 deletion src/drawer/component/internal/internal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '@angular/common';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
InjectionToken,
Expand Down Expand Up @@ -128,7 +129,10 @@ export class DrawerInternalComponent<T = unknown, C extends object = object> {

isTemplateRef = isTemplateRef;

constructor(private readonly injector: Injector) {}
constructor(
private readonly injector: Injector,
private readonly cdr: ChangeDetectorRef,
) {}

ngAfterViewInit() {
this.attachBodyContent();
Expand Down Expand Up @@ -206,6 +210,11 @@ export class DrawerInternalComponent<T = unknown, C extends object = object> {
}
}

updateOptions(options: DrawerOptions<T, C>) {
this.options = options;
this.cdr.markForCheck();
}

show() {
this.showHide$$.next('show');
}
Expand Down
3 changes: 2 additions & 1 deletion src/drawer/drawer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class DrawerService<

updateOptions(options: DrawerOptions<T, C>): void {
this.options = merge<DrawerOptions<T, C>>(DEFAULT_OPTIONS, options);
this.drawerInternalComponentRef?.instance.updateOptions(this.options);
}

private createOverlay() {
Expand Down Expand Up @@ -97,7 +98,7 @@ export class DrawerService<
const drawerInternalComponentRef = this.overlayRef.attach(
new ComponentPortal(DrawerInternalComponent<T, C>),
);
drawerInternalComponentRef.instance.options = this.options;
drawerInternalComponentRef.instance.updateOptions(this.options);
drawerInternalComponentRef.instance.animationStep$.subscribe(step => {
if (step === 'hideDone') {
this.invisible$.next();
Expand Down
1 change: 0 additions & 1 deletion stories/drawer/basic-drawer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core';
[divider]="divider"
[offsetY]="offsetY + 'px'"
[visible]="visible"
[hideOnClickOutside]="true"
(close)="closeHandle()"
>
<div *auiDrawerHeader>header</div>
Expand Down

0 comments on commit 11caa9d

Please sign in to comment.