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

refactor(tooltip): migrate to signals #430 #503

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
21 changes: 8 additions & 13 deletions libs/brain/tooltip/src/lib/brn-tooltip-content.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
* Check them out! Give them a try! Leave a star! Their work is incredible!
*/

import { NgTemplateOutlet, isPlatformBrowser } from '@angular/common';
import { isPlatformBrowser, NgTemplateOutlet } from '@angular/common';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
type ElementRef,
ElementRef,
inject,
type OnDestroy,
PLATFORM_ID,
Renderer2,
signal,
type TemplateRef,
ViewChild,
viewChild,
ViewEncapsulation,
inject,
signal,
} from '@angular/core';
import { Subject } from 'rxjs';

Expand Down Expand Up @@ -82,12 +82,7 @@ export class BrnTooltipContentComponent implements OnDestroy {
public _exitAnimationDuration = 0;

/** Reference to the internal tooltip element. */
@ViewChild('tooltip', {
// Use a static query here since we interact directly with
// the DOM which can happen before `ngAfterViewInit`.
static: true,
})
public _tooltip?: ElementRef<HTMLElement>;
public _tooltip = viewChild('tooltip', { read: ElementRef<HTMLElement> });

/** Whether interactions on the page should close the tooltip */
private _closeOnInteraction = false;
Expand Down Expand Up @@ -216,7 +211,7 @@ export class BrnTooltipContentComponent implements OnDestroy {
// We set the classes directly here ourselves so that toggling the tooltip state
// isn't bound by change detection. This allows us to hide it even if the
// view ref has been detached from the CD tree.
const tooltip = this._tooltip?.nativeElement;
const tooltip = this._tooltip()?.nativeElement;
if (!tooltip || !this._isBrowser) return;
this._renderer2.setStyle(tooltip, 'visibility', isVisible ? 'visible' : 'hidden');
if (isVisible) {
Expand All @@ -231,7 +226,7 @@ export class BrnTooltipContentComponent implements OnDestroy {
// We set the classes directly here ourselves so that toggling the tooltip state
// isn't bound by change detection. This allows us to hide it even if the
// view ref has been detached from the CD tree.
const tooltip = this._tooltip?.nativeElement;
const tooltip = this._tooltip()?.nativeElement;
if (!tooltip || !this._isBrowser) return;
this._renderer2.setAttribute(tooltip, 'data-side', side);
this._renderer2.setAttribute(tooltip, 'data-state', isVisible ? 'open' : 'closed');
Expand Down
Loading
Loading