Skip to content

Commit

Permalink
allow overwriting tooltip text
Browse files Browse the repository at this point in the history
  • Loading branch information
wouter-willems committed May 30, 2024
1 parent 4a881e6 commit 50643bb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion projects/demo/src/app/demo/demo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</div>
</div>

<div class="smallText" klpWithTooltip="black">I am a small bit of text</div>
<div class="smallText" klpWithTooltip="black" tooltipText="Tooltip text overwrite">I am a small bit of text</div>

<div>
<klp-form-element caption="radioButtons classic" spaceDistribution="34-66" verticalAlignment="top">
Expand Down
2 changes: 1 addition & 1 deletion projects/klippa/ngx-enhancy-forms/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@klippa/ngx-enhancy-forms",
"version": "14.19.2",
"version": "14.19.3",
"publishConfig": {
"access": "public"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ export class WithTooltipDirective {
private triangle: HTMLElement;
private triangleWhite: HTMLElement;
@Input() klpWithTooltip: 'orange'| 'black' = 'orange';
@Input() tooltipText: string;
constructor(el: ElementRef) {
el.nativeElement.addEventListener('mouseenter', () => {
const textToDisplay = this.tooltipText || el.nativeElement.innerText.trim();
if (!stringIsSetAndFilled(this.klpWithTooltip)) {
return;
}
if (el.nativeElement.innerText.trim().length < 1) {
if (textToDisplay.length < 1) {
return;
}
if (el.nativeElement.offsetWidth >= el.nativeElement.scrollWidth) {
Expand All @@ -46,7 +48,7 @@ export class WithTooltipDirective {
this.div.style.padding = '0.3rem 0.5rem';
this.div.style.boxSizing = 'border-box';
this.div.style.borderRadius = '3px';
this.div.textContent = el.nativeElement.innerText;
this.div.textContent = textToDisplay;
el.nativeElement.prepend(this.div);

this.triangle = document.createElement('div');
Expand Down

0 comments on commit 50643bb

Please sign in to comment.