Skip to content

Commit e76ce85

Browse files
author
Andrea Barbasso
committed
[UXP-126] edit tooltip positioning
1 parent 82b8233 commit e76ce85

4 files changed

Lines changed: 46 additions & 10 deletions

File tree

src/app/directives/text-select/text-select.directive.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ export class TextSelectDirective implements OnInit, OnDestroy {
127127

128128
document.body.appendChild(domElem);
129129

130-
this.componentRef.instance.left = localRectangle.left + localRectangle.width / 2;
131-
this.componentRef.instance.top = localRectangle.top;
130+
this.componentRef.instance.rectangleLeft = localRectangle.left;
131+
this.componentRef.instance.rectangleTop = localRectangle.top;
132+
this.componentRef.instance.rectangleWidth = localRectangle.width;
133+
this.componentRef.instance.rectangleHeight = localRectangle.height;
132134
this.componentRef.instance.text = stringSelection;
133135

134136
this.selectedText = stringSelection;
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
<p (mousedown)="textToSpeech($event)">Click me for TTS</p>
1+
<div class="p-2 text-white">
2+
<i (click)="textToSpeech($event)" class="button fa fa-volume-high"></i>
3+
</div>
4+
<div class="pointer-down">&nbsp;</div>
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
:host {
22
position: absolute;
33
z-index: 9999;
4-
background-color: #f5f5f5;
4+
background-color: var(--bs-gray-900);
55
transform: translate(-50%, -100%);
66
}
77

8-
p {
8+
i.button {
99
cursor: pointer;
1010
}
11+
12+
div.pointer-down {
13+
position: absolute;
14+
bottom: 0;
15+
left: 50%;
16+
background-color: var(--bs-gray-900);
17+
transform: translateX(-50%) translateY(50%) rotate(45deg);
18+
width: 12px;
19+
height: 12px;
20+
}

src/app/directives/text-select/text-selection-tooltip/text-selection-tooltip.component.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectionStrategy, Component, HostBinding, HostListener, Input, OnDestroy } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, HostBinding, HostListener, Input, OnDestroy, OnInit } from '@angular/core';
22

33
@Component({
44
selector: 'ds-text-selection-tooltip',
@@ -7,21 +7,42 @@ import { ChangeDetectionStrategy, Component, HostBinding, HostListener, Input, O
77
changeDetection: ChangeDetectionStrategy.OnPush,
88
standalone: true
99
})
10-
export class TextSelectionTooltipComponent implements OnDestroy {
10+
export class TextSelectionTooltipComponent implements OnInit, OnDestroy {
1111

1212
@Input()
13+
rectangleLeft = 0;
14+
15+
@Input()
16+
rectangleTop = 0;
17+
18+
@Input()
19+
rectangleWidth = 0;
20+
21+
@Input()
22+
rectangleHeight = 0;
23+
24+
@Input()
25+
text: string;
26+
1327
@HostBinding('style.left.px')
1428
left: number;
1529

16-
@Input()
1730
@HostBinding('style.top.px')
1831
top: number;
1932

20-
@Input()
21-
text: string;
33+
@HostBinding('style.right.px')
34+
right: number;
35+
36+
@HostBinding('style.bottom.px')
37+
bottom: number;
2238

2339
utterance: SpeechSynthesisUtterance;
2440

41+
ngOnInit(): void {
42+
this.top = this.rectangleTop - 6;
43+
this.left = this.rectangleLeft + this.rectangleWidth / 2;
44+
}
45+
2546
// listen to mousedown on host element to avoid clearing selection
2647
@HostListener('mousedown', ['$event'])
2748
public handleMousedown(event: MouseEvent): void {

0 commit comments

Comments
 (0)