Skip to content

Commit e05a99f

Browse files
medinarkhovmaxokorokov
authored andcommitted
feat(tooltip): intoduce disabled flag
Closes #2253
1 parent 7201af3 commit e05a99f

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

src/tooltip/tooltip-config.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ describe('ngb-tooltip-config', () => {
77
expect(config.placement).toBe('top');
88
expect(config.triggers).toBe('hover');
99
expect(config.container).toBeUndefined();
10+
expect(config.disableTooltip).toBe(false);
1011
});
1112
});

src/tooltip/tooltip-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export class NgbTooltipConfig {
1111
placement: PlacementArray = 'top';
1212
triggers = 'hover';
1313
container: string;
14+
disableTooltip = false;
1415
}

src/tooltip/tooltip.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,17 @@ describe('ngb-tooltip', () => {
136136
expect(getWindow(fixture.nativeElement)).toBeNull();
137137
});
138138

139+
it('should not open a tooltip if [disableTooltip] flag', () => {
140+
const fixture = createTestComponent(`<div [ngbTooltip]="Disabled!" [disableTooltip]="true"></div>`);
141+
const directive = fixture.debugElement.query(By.directive(NgbTooltip));
142+
143+
directive.triggerEventHandler('mouseenter', {});
144+
fixture.detectChanges();
145+
const windowEl = getWindow(fixture.nativeElement);
146+
147+
expect(windowEl).toBeNull();
148+
});
149+
139150
it('should allow re-opening previously closed tooltips', () => {
140151
const fixture = createTestComponent(`<div ngbTooltip="Great tip!"></div>`);
141152
const directive = fixture.debugElement.query(By.directive(NgbTooltip));

src/tooltip/tooltip.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ export class NgbTooltip implements OnInit, OnDestroy {
101101
* Currently only supports "body".
102102
*/
103103
@Input() container: string;
104+
/**
105+
* A flag indicating if a given tooltip is disabled and should not be displayed.
106+
*/
107+
@Input() disableTooltip: boolean;
104108
/**
105109
* Emits an event when the tooltip is shown
106110
*/
@@ -124,6 +128,7 @@ export class NgbTooltip implements OnInit, OnDestroy {
124128
this.placement = config.placement;
125129
this.triggers = config.triggers;
126130
this.container = config.container;
131+
this.disableTooltip = config.disableTooltip;
127132
this._popupService = new PopupService<NgbTooltipWindow>(
128133
NgbTooltipWindow, injector, viewContainerRef, _renderer, componentFactoryResolver);
129134

@@ -155,7 +160,7 @@ export class NgbTooltip implements OnInit, OnDestroy {
155160
* The context is an optional value to be injected into the tooltip template when it is created.
156161
*/
157162
open(context?: any) {
158-
if (!this._windowRef && this._ngbTooltip) {
163+
if (!this._windowRef && this._ngbTooltip && !this.disableTooltip) {
159164
this._windowRef = this._popupService.open(this._ngbTooltip, context);
160165
this._windowRef.instance.id = this._ngbTooltipWindowId;
161166

0 commit comments

Comments
 (0)