Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(tooltip): implement change detection
This fixes issues with custom tooltip class changes  not being applied after
tooltip creation.

Fixes: #3335
  • Loading branch information
peterblazejewicz authored and maxokorokov committed Oct 21, 2019
1 parent 7324083 commit 48bdf62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/tooltip/tooltip.spec.ts
Expand Up @@ -3,12 +3,13 @@ import {createGenericTestComponent, createKeyEvent, triggerEvent} from '../test/

import {By} from '@angular/platform-browser';
import {
Component,
ViewChild,
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
TemplateRef,
ViewContainerRef,
AfterViewInit
ViewChild,
ViewContainerRef
} from '@angular/core';

import {Key} from '../util/key';
Expand Down Expand Up @@ -59,7 +60,6 @@ describe('ngb-tooltip-window', () => {

expect(fixture.nativeElement).toHaveCssClass('my-custom-class');
});

});

describe('ngb-tooltip', () => {
Expand Down
12 changes: 10 additions & 2 deletions src/tooltip/tooltip.ts
Expand Up @@ -18,7 +18,9 @@ import {
NgZone,
ViewEncapsulation,
ChangeDetectorRef,
ApplicationRef
ApplicationRef,
OnChanges,
SimpleChanges
} from '@angular/core';
import {DOCUMENT} from '@angular/common';

Expand Down Expand Up @@ -48,7 +50,7 @@ export class NgbTooltipWindow {
* A lightweight and extensible directive for fancy tooltip creation.
*/
@Directive({selector: '[ngbTooltip]', exportAs: 'ngbTooltip'})
export class NgbTooltip implements OnInit, OnDestroy {
export class NgbTooltip implements OnInit, OnDestroy, OnChanges {
/**
* Indicates whether the tooltip should be closed on `Escape` key and inside/outside clicks:
*
Expand Down Expand Up @@ -253,6 +255,12 @@ export class NgbTooltip implements OnInit, OnDestroy {
this.close.bind(this), +this.openDelay, +this.closeDelay);
}

ngOnChanges({tooltipClass}: SimpleChanges) {
if (tooltipClass && this.isOpen()) {
this._windowRef.instance.tooltipClass = tooltipClass.currentValue;
}
}

ngOnDestroy() {
this.close();
// This check is needed as it might happen that ngOnDestroy is called before ngOnInit
Expand Down

0 comments on commit 48bdf62

Please sign in to comment.