Skip to content
Merged
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
19 changes: 10 additions & 9 deletions projects/components/src/popover/popover.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
OnDestroy,
Output
} from '@angular/core';
import { Subscription } from 'rxjs';
import { PopoverBackdrop, PopoverPositionType, PopoverRelativePositionLocation } from './popover';
import { PopoverContentComponent } from './popover-content.component';
import { PopoverRef } from './popover-ref';
Expand Down Expand Up @@ -51,12 +50,14 @@ export class PopoverComponent implements OnDestroy {
@ContentChild(PopoverContentComponent, { static: true })
public content!: PopoverContentComponent;

private subscription?: Subscription;
private popover?: PopoverRef;

public constructor(private readonly popoverService: PopoverService, private readonly popoverElement: ElementRef) {}

public ngOnDestroy(): void {
this.subscription?.unsubscribe();
if (!this.popover?.closed) {
this.popover?.close();
}
}

@HostListener('click')
Expand All @@ -65,7 +66,7 @@ export class PopoverComponent implements OnDestroy {
return;
}

const popover = this.popoverService.drawPopover({
this.popover = this.popoverService.drawPopover({
position: {
type: PopoverPositionType.Relative,
origin: this.popoverElement,
Expand All @@ -76,17 +77,17 @@ export class PopoverComponent implements OnDestroy {
});

// Closing can happen internal to the Popover for things like closeOnBackdropClick. Let the consumer know.
this.subscription = popover.closed$.subscribe(() => this.popoverClose.emit());
this.popover.closed$.subscribe(() => this.popoverClose.emit());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are not unsubscribing from this?

Copy link
Contributor Author

@aaron-steinfeld aaron-steinfeld May 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer necessary, because the closed observable ends when we invoke close which now will always happen at or before destroy.


popover.closeOnBackdropClick();
this.popover.closeOnBackdropClick();

if (this.closeOnClick) {
popover.closeOnPopoverContentClick();
this.popover.closeOnPopoverContentClick();
}
if (this.closeOnNavigate) {
popover.closeOnNavigation();
this.popover.closeOnNavigation();
}

this.popoverOpen.emit(popover);
this.popoverOpen.emit(this.popover);
}
}