Skip to content

Commit

Permalink
fix(core/tooltip): destroy auto update cycle before starting a new one (
Browse files Browse the repository at this point in the history
#1374)

Co-authored-by: Lukas Maurer <[email protected]>
Co-authored-by: AndreasBerliner <[email protected]>
  • Loading branch information
3 people authored Jul 16, 2024
1 parent 24a9514 commit f57e82f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-apricots-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@siemens/ix": patch
---

fix(core/tooltip): destroy auto update cycle before starting a new one
4 changes: 2 additions & 2 deletions packages/core/component-doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16039,7 +16039,7 @@
"type": "string"
}
],
"optional": false,
"optional": true,
"required": false
},
{
Expand Down Expand Up @@ -16122,7 +16122,7 @@
"type": "string"
}
],
"optional": false,
"optional": true,
"required": false
}
],
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { TabClickDetail } from "./components/tab-item/tab-item";
import { TimePickerCorners } from "./components/time-picker/time-picker";
import { ToastConfig, ToastType } from "./components/toast/toast-utils";
import { ShowToastResult } from "./components/toast/toast-container";
import { Element } from "@stencil/core";
import { TreeContext, TreeItemContext, TreeModel, UpdateCallback } from "./components/tree/tree-model";
import { TextDecoration, TypographyColors, TypographyFormat, TypographyVariants } from "./components/typography/typography";
import { UploadFileState } from "./components/upload/upload-file-state";
Expand Down Expand Up @@ -82,6 +83,7 @@ export { TabClickDetail } from "./components/tab-item/tab-item";
export { TimePickerCorners } from "./components/time-picker/time-picker";
export { ToastConfig, ToastType } from "./components/toast/toast-utils";
export { ShowToastResult } from "./components/toast/toast-container";
export { Element } from "@stencil/core";
export { TreeContext, TreeItemContext, TreeModel, UpdateCallback } from "./components/tree/tree-model";
export { TextDecoration, TypographyColors, TypographyFormat, TypographyVariants } from "./components/typography/typography";
export { UploadFileState } from "./components/upload/upload-file-state";
Expand Down Expand Up @@ -2258,7 +2260,7 @@ export namespace Components {
/**
* CSS selector for hover trigger element e.g. `for="[data-my-custom-select]"`
*/
"for": string | HTMLElement | Promise<HTMLElement>;
"for"?: string | HTMLElement | Promise<HTMLElement>;
"hideDelay": number;
"hideTooltip": () => Promise<void>;
/**
Expand All @@ -2271,11 +2273,11 @@ export namespace Components {
*/
"placement": 'top' | 'right' | 'bottom' | 'left';
"showDelay": number;
"showTooltip": (anchorElement: any) => Promise<void>;
"showTooltip": (anchorElement: Element) => Promise<void>;
/**
* Title of the tooltip
*/
"titleContent": string;
"titleContent"?: string;
}
interface IxTree {
/**
Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/components/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ export class Tooltip implements IxOverlayComponent {
/**
* CSS selector for hover trigger element e.g. `for="[data-my-custom-select]"`
*/
@Prop() for: string | HTMLElement | Promise<HTMLElement>;
@Prop() for?: string | HTMLElement | Promise<HTMLElement>;

/**
* Title of the tooltip
*/
@Prop() titleContent: string;
@Prop() titleContent?: string;

/**
* Define if the user can access the tooltip via mouse.
Expand All @@ -82,13 +82,13 @@ export class Tooltip implements IxOverlayComponent {

@State() visible = false;

@Element() hostElement: HTMLIxTooltipElement;
@Element() hostElement!: HTMLIxTooltipElement;

private observer: MutationObserver;
private hideTooltipTimeout: NodeJS.Timeout;
private showTooltipTimeout: NodeJS.Timeout;
private observer?: MutationObserver;
private hideTooltipTimeout?: NodeJS.Timeout;
private showTooltipTimeout?: NodeJS.Timeout;
private disposeAutoUpdate?: () => void;
private disposeListener: () => void;
private disposeListener?: () => void;

private get arrowElement(): HTMLElement {
return this.hostElement.shadowRoot.querySelector('.arrow');
Expand All @@ -102,7 +102,7 @@ export class Tooltip implements IxOverlayComponent {

/** @internal */
@Method()
async showTooltip(anchorElement: any) {
async showTooltip(anchorElement: Element) {
clearTimeout(this.hideTooltipTimeout);
await this.applyTooltipPosition(anchorElement);

Expand Down Expand Up @@ -166,7 +166,7 @@ export class Tooltip implements IxOverlayComponent {
}

private async computeTooltipPosition(target: Element) {
const computeResponse = await computePosition(target, this.hostElement, {
return computePosition(target, this.hostElement, {
strategy: 'fixed',
placement: this.placement,
middleware: [
Expand All @@ -181,7 +181,6 @@ export class Tooltip implements IxOverlayComponent {
}),
],
});
return computeResponse;
}

private applyTooltipArrowPosition(computeResponse: ComputePositionReturn) {
Expand All @@ -195,6 +194,7 @@ export class Tooltip implements IxOverlayComponent {
}

return new Promise<ComputePositionReturn>((resolve) => {
this.destroyAutoUpdate();
this.disposeAutoUpdate = autoUpdate(
target,
this.hostElement,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ix-angular-example",
"name": "ix-react-example",
"version": "0.1.0",
"private": true,
"dependencies": {
Expand Down

0 comments on commit f57e82f

Please sign in to comment.