Skip to content

Commit

Permalink
fix(tooltip): allow null and undefined as values for tooltip
Browse files Browse the repository at this point in the history
The documentation says that falsy values are accepted, but in strict mode, only the empty string could actually be passed.

fix #3845
  • Loading branch information
jnizet authored and maxokorokov committed Nov 3, 2020
1 parent 89ec4fe commit b713e38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/tooltip/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ describe('ngb-tooltip', () => {
expect(windowEl).toBeNull();
});

it('should not open a tooltip if content is empty', () => {
const fixture = createTestComponent(`<div ngbTooltip=""></div>`);
const directive = fixture.debugElement.query(By.directive(NgbTooltip));

triggerEvent(directive, 'mouseenter');
fixture.detectChanges();
const windowEl = getWindow(fixture.nativeElement);

expect(windowEl).toBeNull();
});

it('should close the tooltip tooltip if content becomes falsy', () => {
const fixture = createTestComponent(`<div [ngbTooltip]="name"></div>`);
const directive = fixture.debugElement.query(By.directive(NgbTooltip));
Expand Down
4 changes: 2 additions & 2 deletions src/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class NgbTooltip implements OnInit, OnDestroy, OnChanges {
*/
@Output() hidden = new EventEmitter();

private _ngbTooltip: string | TemplateRef<any>;
private _ngbTooltip: string | TemplateRef<any>| null | undefined;
private _ngbTooltipWindowId = `ngb-tooltip-${nextId++}`;
private _popupService: PopupService<NgbTooltipWindow>;
private _windowRef: ComponentRef<NgbTooltipWindow>| null = null;
Expand Down Expand Up @@ -187,7 +187,7 @@ export class NgbTooltip implements OnInit, OnDestroy, OnChanges {
* If the content if falsy, the tooltip won't open.
*/
@Input()
set ngbTooltip(value: string | TemplateRef<any>) {
set ngbTooltip(value: string | TemplateRef<any>| null | undefined) {
this._ngbTooltip = value;
if (!value && this._windowRef) {
this.close();
Expand Down

0 comments on commit b713e38

Please sign in to comment.