-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tooltip): fix tooltip position when element its wrapped by a abso…
…lute position div.
- Loading branch information
1 parent
91b4c57
commit 0e8c79d
Showing
3 changed files
with
48 additions
and
40 deletions.
There are no files selected for viewing
62 changes: 36 additions & 26 deletions
62
projects/truly-ui/src/components/tooltip/directives/tooltip.directive.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 |
---|---|---|
@@ -1,41 +1,51 @@ | ||
import { | ||
ComponentFactoryResolver, | ||
Directive, HostListener, Input, | ||
ViewContainerRef | ||
ComponentFactoryResolver, | ||
Directive, HostListener, Input, OnDestroy, | ||
ViewContainerRef | ||
} from '@angular/core'; | ||
import { TlToolTip } from '../tooltip'; | ||
import { TooltipOptions } from '../tooltipOptions'; | ||
|
||
@Directive( { | ||
selector: '[tooltip]' | ||
selector: '[tooltip]' | ||
} ) | ||
export class TooltipDirective { | ||
export class TooltipDirective implements OnDestroy { | ||
|
||
@Input() tooltip: TooltipOptions; | ||
@Input() tooltip: TooltipOptions; | ||
|
||
constructor( private view: ViewContainerRef, private compiler: ComponentFactoryResolver ) { | ||
} | ||
private listenerWheel; | ||
|
||
@HostListener( 'mouseenter' ) | ||
onMouseEnter() { | ||
this.show(); | ||
} | ||
constructor( private view: ViewContainerRef, private compiler: ComponentFactoryResolver ) { | ||
this.listenerWheel = document.addEventListener('mousewheel', () => { | ||
this.hide(); | ||
}); | ||
} | ||
|
||
@HostListener( 'mouseleave' ) | ||
onMouseLeave() { | ||
this.hide(); | ||
} | ||
@HostListener( 'mouseenter' ) | ||
onMouseEnter() { | ||
this.show(); | ||
} | ||
|
||
show() { | ||
if (this.tooltip.text !== '') { | ||
const componentFactory = this.compiler.resolveComponentFactory( TlToolTip ); | ||
const componentRef = this.view.createComponent( componentFactory ); | ||
(<TlToolTip>componentRef.instance).setOptions( this.tooltip ); | ||
(<TlToolTip>componentRef.instance).setPosition( this.view.element ); | ||
} | ||
} | ||
@HostListener( 'mouseleave' ) | ||
onMouseLeave() { | ||
this.hide(); | ||
} | ||
|
||
hide() { | ||
this.view.clear(); | ||
show() { | ||
if ( this.tooltip.text !== '' ) { | ||
const componentFactory = this.compiler.resolveComponentFactory( TlToolTip ); | ||
const componentRef = this.view.createComponent( componentFactory ); | ||
(<TlToolTip>componentRef.instance).setOptions( this.tooltip ); | ||
(<TlToolTip>componentRef.instance).setPosition( this.view.element ); | ||
} | ||
} | ||
|
||
hide() { | ||
this.view.clear(); | ||
} | ||
|
||
ngOnDestroy() { | ||
document.removeEventListener('mousewheel', this.listenerWheel, false); | ||
} | ||
|
||
} |
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