Skip to content

Commit

Permalink
fix(popover): don't show header if title is empty
Browse files Browse the repository at this point in the history
by removing the element from the DOM

Closes #2653

Closes #2661
  • Loading branch information
bedag-moo authored and pkozlowski-opensource committed Aug 30, 2018
1 parent c9f847b commit f1ec90b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/popover/popover.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ describe('ngb-popover', () => {
expect(spyService.called).toBeTruthy();
});

it('should not show a header if title is empty', () => {
const fixture = createTestComponent(`<div ngbPopover="Great tip!"></div>`);
const directive = fixture.debugElement.query(By.directive(NgbPopover));

directive.triggerEventHandler('click', {});
fixture.detectChanges();
const windowEl = getWindow(fixture.nativeElement);
expect(windowEl.querySelector('.popover-header')).toBeNull();
});

it('should not open a popover if content and title are empty', () => {
const fixture = createTestComponent(`<div [ngbPopover]="" [popoverTitle]=""></div>`);
const directive = fixture.debugElement.query(By.directive(NgbPopover));
Expand Down
4 changes: 2 additions & 2 deletions src/popover/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ let nextId = 0;
},
template: `
<div class="arrow"></div>
<h3 class="popover-header">
<h3 class="popover-header" *ngIf="title != null">
<ng-template #simpleTitle>{{title}}</ng-template>
<ng-template [ngTemplateOutlet]="isTitleTemplate() ? title : simpleTitle" [ngTemplateOutletContext]="context"></ng-template>
</h3>
Expand Down Expand Up @@ -80,7 +80,7 @@ let nextId = 0;
})
export class NgbPopoverWindow {
@Input() placement: Placement = 'top';
@Input() title: string | TemplateRef<any>;
@Input() title: undefined | string | TemplateRef<any>;
@Input() id: string;
@Input() popoverClass: string;
@Input() context: any;
Expand Down

0 comments on commit f1ec90b

Please sign in to comment.