Skip to content

Tooltip signals input 2 #540

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

Closed
wants to merge 6 commits into from
Closed
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
1 change: 1 addition & 0 deletions libs/brain/tooltip/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './lib/brn-tooltip-content.component';
export * from './lib/brn-tooltip-content.directive';
export * from './lib/brn-tooltip-trigger.directive';
export * from './lib/brn-tooltip.directive';
export * from './lib/brn-tooltip.token';

export const BrnTooltipImports = [
BrnTooltipDirective,
Expand Down
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