Skip to content

Commit

Permalink
more fixes on animation and handleClickOutside
Browse files Browse the repository at this point in the history
  • Loading branch information
Pop John committed Oct 24, 2024
1 parent 3d911c3 commit 85897c1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
SPDX-License-Identifier: Apache-2.0 -->

<div
class="tooltip-container"
class="tooltip-container popover-element"
[ngClass]="data.position"
[ngStyle]="data.width | iconPanelSizeStyles: data.height"
[@fadeInOut]="isClosing">
[@fadeInOut]="popoverRef.isClosing">
<div class="tooltip-arrow"></div>

<div class="popover-content">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ export class MsPopoverComponent {
@Input() contentTemplate?: TemplateRef<any>;
@Output() actionEvent: EventEmitter<PopoverStatus> = new EventEmitter<PopoverStatus>();

isClosing = false;

constructor(
private popoverRef: PopoverRef,
public popoverRef: PopoverRef,
@Inject(POPOVER_DATA) public data: PopoverConfig
) {
this.closeDrawerOnBackdropClick();
Expand All @@ -62,19 +60,16 @@ export class MsPopoverComponent {
onClose(): void {
this.actionEvent.emit(PopoverStatus.CLOSE);
this.popoverRef.close({ status: PopoverStatus.CLOSE });
this.isClosing = true;
}

onSave(): void {
this.actionEvent.emit(PopoverStatus.SAVE);
this.popoverRef.close({ status: PopoverStatus.SAVE });
this.isClosing = false;
}

onDismiss(): void {
this.actionEvent.emit(PopoverStatus.DISMISS);
this.popoverRef.close({ status: PopoverStatus.DISMISS });
this.isClosing = false;
}

private closeDrawerOnBackdropClick(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import { PopoverClose } from './models/interfaces/popover-config.interface';
// - Handle Backdrop Clicks: Allows listening to backdrop clicks, providing a way to close the popover or take action when the user clicks outside of the popover.

export class PopoverRef {
/**
* Based on this value we trigger the fade-in and fade-out animations.
*/
public isClosing: boolean = false;

private afterClosedSubject = new Subject<any>();

/**
Expand All @@ -54,6 +59,8 @@ export class PopoverRef {
}

public close(result?: PopoverClose<any>) {
this.isClosing = true;

this.afterClosedSubject.next(result);
this.afterClosedSubject.complete();
this.dataSubject.complete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class MsTerminalToolbarComponent implements OnInit, OnDestroy {
.pipe(take(1))
.subscribe(() => {
this.searchPanelRef = undefined;
this.disposeSearch.emit();
});
}

Expand All @@ -135,6 +136,10 @@ export class MsTerminalToolbarComponent implements OnInit, OnDestroy {
}

openTerminalMessagesHistoryDialog() {
if (!isNil(this.searchPanelRef)) {
this.searchPanelRef?.close();
}

this.terminalDialogService.openMessagesHistoryDialog();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { MsTerminalXtermComponent } from '../ms-terminal-xterm/ms-terminal-xterm
})
export class MsTerminalXtermWithToolbarComponent implements OnDestroy {
@ViewChild('terminalWrapper') terminalWrapper!: ElementRef;
@ViewChild('popoverElement') popoverElement!: ElementRef;

private clickListener!: () => void;

Expand All @@ -46,7 +47,9 @@ export class MsTerminalXtermWithToolbarComponent implements OnDestroy {
}

handleClickOutside(event: Event): void {
if (this.terminalWrapper && !this.terminalWrapper.nativeElement.contains(event.target)) {
const clickedInsidePopover = (event.target as HTMLElement).closest('.popover-element');

if (this.terminalWrapper && !this.terminalWrapper.nativeElement.contains(event.target) && !clickedInsidePopover) {
if (this.popoverManager.hasActivePopover('terminal-popover')) {
this.popoverManager.closePopoverById('terminal-popover');
}
Expand Down

0 comments on commit 85897c1

Please sign in to comment.