-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(popover): allow specifying target for popover
- Loading branch information
1 parent
9c8bf98
commit 711bfd3
Showing
5 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
demo/src/app/components/popover/demos/custom-target/popover-target.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<p> | ||
You can choose a dynamic target with manual triggers. This is useful when adding tooltips | ||
to dynamic html content. | ||
</p> | ||
|
||
<ng-template #popContent let-text="text" let-href="href"><a [attr.href]="href" target="_blank">open {{text}} in a new window</a></ng-template> | ||
|
||
<p [ngbPopover]="popContent" autoClose="outside" triggers="manual" #paragraphElement> | ||
Add tooltips to dynamic html that contains links like <a data-description="Angular Framework" href="https://angular.io">angular</a> or <a data-description="Angular Bootstrap Components" href="https://ng-bootstrap.github.io">ng-bootstrap</a> | ||
</p> | ||
|
13 changes: 13 additions & 0 deletions
13
demo/src/app/components/popover/demos/custom-target/popover-target.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
import {NgbdPopoverTarget} from './popover-target'; | ||
|
||
@NgModule({ | ||
imports: [BrowserModule, NgbModule], | ||
declarations: [NgbdPopoverTarget], | ||
exports: [NgbdPopoverTarget], | ||
bootstrap: [NgbdPopoverTarget] | ||
}) | ||
export class NgbdPopoverTargetModule {} |
21 changes: 21 additions & 0 deletions
21
demo/src/app/components/popover/demos/custom-target/popover-target.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {Component, HostListener, ViewChild} from '@angular/core'; | ||
import {NgbPopover} from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
@Component({ | ||
selector: 'ngbd-popover-target', | ||
templateUrl: './popover-target.html' | ||
}) | ||
export class NgbdPopoverTarget { | ||
@ViewChild(NgbPopover, {static: false}) popover: NgbPopover; | ||
|
||
@HostListener('mouseover', ['$event.target']) | ||
onMouseOver(el: HTMLAnchorElement) { | ||
if (el.dataset.description) { | ||
if (this.popover.isOpen() && this.popover.target !== el) { | ||
this.popover.close(); | ||
} | ||
this.popover.target = el; | ||
this.popover.open({text: el.dataset.description, href: el.href}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters