Skip to content

Commit

Permalink
fix(core/tooltip): positioning initial (#1036)
Browse files Browse the repository at this point in the history
Co-authored-by: Demirci <ridvan.demirci@siemens.com>
  • Loading branch information
ridvandmrc and Demirci committed Jan 10, 2024
1 parent 84cce07 commit 9ba9823
Showing 1 changed file with 47 additions and 42 deletions.
89 changes: 47 additions & 42 deletions packages/core/src/components/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export class Tooltip {
@Method()
async showTooltip(anchorElement: any) {
clearTimeout(this.hideTooltipTimeout);
await this.computeTooltipPosition(anchorElement);
this.visible = true;
this.computeTooltipPosition(anchorElement);
}

/** @internal */
Expand Down Expand Up @@ -160,50 +160,55 @@ export class Tooltip {
if (!target) {
return;
}
this.disposeAutoUpdate = autoUpdate(
target,
this.hostElement,
async () => {
setTimeout(async () => {
const computeResponse = await computePosition(
target,
this.hostElement,
{
strategy: 'fixed',
placement: this.placement,
middleware: [
shift(),
offset(8),
arrow({
element: this.arrowElement,
}),
flip({
fallbackStrategy: 'initialPlacement',
padding: 10,
}),
],

return new Promise<void>((resolve) => {
this.disposeAutoUpdate = autoUpdate(
target,
this.hostElement,
async () => {
setTimeout(async () => {
const computeResponse = await computePosition(
target,
this.hostElement,
{
strategy: 'fixed',
placement: this.placement,
middleware: [
shift(),
offset(8),
arrow({
element: this.arrowElement,
}),
flip({
fallbackStrategy: 'initialPlacement',
padding: 10,
}),
],
}
);

if (computeResponse.middlewareData.arrow) {
const arrowPosition = this.computeArrowPosition(computeResponse);
Object.assign(this.arrowElement.style, arrowPosition);
}
);

if (computeResponse.middlewareData.arrow) {
const arrowPosition = this.computeArrowPosition(computeResponse);
Object.assign(this.arrowElement.style, arrowPosition);
}
const { x, y } = computeResponse;
Object.assign(this.hostElement.style, {
left: x !== null ? `${x}px` : '',
top: y !== null ? `${y}px` : '',
});

const { x, y } = computeResponse;
Object.assign(this.hostElement.style, {
left: x !== null ? `${x}px` : '',
top: y !== null ? `${y}px` : '',
resolve();
});
});
},
{
ancestorResize: true,
ancestorScroll: true,
elementResize: true,
animationFrame: this.animationFrame,
}
);
},
{
ancestorResize: true,
ancestorScroll: true,
elementResize: true,
animationFrame: this.animationFrame,
}
);
});
}

private clearHideTimeout() {
Expand All @@ -219,7 +224,7 @@ export class Tooltip {
private updateAriaDescribedBy(element: Element, describedBy: string) {
const oldDescribedBy = element.getAttribute('aria-describedby');

if (oldDescribedBy.indexOf(describedBy) != -1) {
if (oldDescribedBy?.indexOf(describedBy) != -1) {
return;
}

Expand Down

0 comments on commit 9ba9823

Please sign in to comment.