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

Fixed #15468 - Tooltip | tooltipEvent - focus | hover combined #15469

Merged
merged 2 commits into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/app/components/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Tooltip implements AfterViewInit, OnDestroy {
* Event to show the tooltip.
* @group Props
*/
@Input() tooltipEvent: 'hover' | 'focus' | string | any = 'hover';
@Input() tooltipEvent: 'hover' | 'focus' | 'both' | string | any = 'hover';
/**
* Target element to attach the overlay, valid values are "body", "target" or a local ng-F variable of another element (note: use binding with brackets for template variables, e.g. [appendTo]="mydiv" for a div element having #mydiv as variable name).
* @group Props
Expand Down Expand Up @@ -169,14 +169,17 @@ export class Tooltip implements AfterViewInit, OnDestroy {
ngAfterViewInit() {
if (isPlatformBrowser(this.platformId)) {
this.zone.runOutsideAngular(() => {
if (this.getOption('tooltipEvent') === 'hover') {
const tooltipEvent = this.getOption('tooltipEvent');

if (tooltipEvent === 'hover' || tooltipEvent === 'both') {
this.mouseEnterListener = this.onMouseEnter.bind(this);
this.mouseLeaveListener = this.onMouseLeave.bind(this);
this.clickListener = this.onInputClick.bind(this);
this.el.nativeElement.addEventListener('mouseenter', this.mouseEnterListener);
this.el.nativeElement.addEventListener('click', this.clickListener);
this.el.nativeElement.addEventListener('mouseleave', this.mouseLeaveListener);
} else if (this.getOption('tooltipEvent') === 'focus') {
}
if (tooltipEvent === 'focus' || tooltipEvent === 'both') {
this.focusListener = this.onFocus.bind(this);
this.blurListener = this.onBlur.bind(this);

Expand Down Expand Up @@ -633,11 +636,14 @@ export class Tooltip implements AfterViewInit, OnDestroy {
}

unbindEvents() {
if (this.getOption('tooltipEvent') === 'hover') {
const tooltipEvent = this.getOption('tooltipEvent');

if (tooltipEvent === 'hover' || tooltipEvent === 'both') {
this.el.nativeElement.removeEventListener('mouseenter', this.mouseEnterListener);
this.el.nativeElement.removeEventListener('mouseleave', this.mouseLeaveListener);
this.el.nativeElement.removeEventListener('click', this.clickListener);
} else if (this.getOption('tooltipEvent') === 'focus') {
}
if (tooltipEvent === 'focus' || tooltipEvent === 'both') {
let target = this.getTarget(this.el.nativeElement);

target.removeEventListener('focus', this.focusListener);
Expand Down
Loading