Skip to content
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

fix(popover): propagate 'popoverClass' change correctly #3420

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/popover/popover.spec.ts
Expand Up @@ -179,6 +179,21 @@ describe('ngb-popover', () => {
expect(directive.nativeElement.getAttribute('aria-describedby')).toBeNull();
});

it('should propagate popoverClass changes to the window', () => {
const fixture =
createTestComponent(`<div ngbPopover="Great tip!" popoverTitle="Title" [popoverClass]="popoverClass"></div>`);
const directive = fixture.debugElement.query(By.directive(NgbPopover));

triggerEvent(directive, 'click');
fixture.detectChanges();
const windowEl = getWindow(fixture.nativeElement);
expect(windowEl).not.toHaveCssClass('my-popover-class');

fixture.componentInstance.popoverClass = 'my-popover-class';
fixture.detectChanges();
expect(windowEl).toHaveCssClass('my-popover-class');
});

it('should accept a template for the title and properly destroy it when closing', () => {
const fixture = createTestComponent(`
<ng-template #t>Hello, {{name}}! <destroyable-cmpt></destroyable-cmpt></ng-template>
Expand Down Expand Up @@ -727,6 +742,7 @@ export class TestComponent {
show = true;
title: string;
placement: string;
popoverClass: string;

@ViewChild(NgbPopover, {static: true}) popover: NgbPopover;

Expand Down
7 changes: 5 additions & 2 deletions src/popover/popover.ts
Expand Up @@ -274,9 +274,12 @@ export class NgbPopover implements OnInit, OnDestroy, OnChanges {
this.close.bind(this), +this.openDelay, +this.closeDelay);
}

ngOnChanges(changes: SimpleChanges) {
ngOnChanges({ngbPopover, popoverTitle, disablePopover, popoverClass}: SimpleChanges) {
if (popoverClass && this.isOpen()) {
this._windowRef.instance.popoverClass = popoverClass.currentValue;
}
// close popover if title and content become empty, or disablePopover set to true
if ((changes['ngbPopover'] || changes['popoverTitle'] || changes['disablePopover']) && this._isDisabled()) {
if ((ngbPopover || popoverTitle || disablePopover) && this._isDisabled()) {
this.close();
}
}
Expand Down