Skip to content

Commit

Permalink
fix(tooltip): handle body removal (#1131)
Browse files Browse the repository at this point in the history
  • Loading branch information
Theeraphat-Sorasetsakul authored Mar 28, 2024
1 parent fbd717c commit 347f98e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 12 deletions.
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/demo-block/src/demo-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ versionTag.style.marginLeft = '8px';
versionTag.style.color = '#334BFF';
themeLabel.appendChild(versionTag);

document.body.appendChild(nextBtn);
document.body.appendChild(prevBtn);
document.body.appendChild(themeLabel);
document.body?.appendChild(nextBtn);
document.body?.appendChild(prevBtn);
document.body?.appendChild(themeLabel);

@customElement('demo-block', { theme: false })
export class DemoBlock extends BasicElement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ export class ScrollLockManager {
this.scrollLeft = document.scrollingElement.scrollLeft;
} else {
// Since we don't know if is the body or html, get max.
this.scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
this.scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
this.scrollTop = Math.max(document.documentElement.scrollTop, document.body?.scrollTop ?? 0);
this.scrollLeft = Math.max(document.documentElement.scrollLeft, document.body?.scrollLeft ?? 0);
}
}

Expand All @@ -181,8 +181,12 @@ export class ScrollLockManager {
document.scrollingElement.scrollLeft = this.scrollLeft;
} else {
// Since we don't know if is the body or html, set both.
document.documentElement.scrollTop = document.body.scrollTop = this.scrollTop;
document.documentElement.scrollLeft = document.body.scrollLeft = this.scrollLeft;
document.documentElement.scrollTop = this.scrollTop;
document.documentElement.scrollLeft = this.scrollTop;
if (document.body) {
document.body.scrollTop = this.scrollTop;
document.body.scrollLeft = this.scrollLeft;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/elements/src/overlay/managers/viewport-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class ViewportManager {
// @ts-ignore
// TODO: Remove @ts-ignore and re-test again when standardized zoom is implemented across major browsers and TypeScript, https://github.com/w3c/csswg-drafts/issues/5623
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const zoom = parseFloat(window.getComputedStyle(document.body).zoom);
const zoom = document.body ? parseFloat(window.getComputedStyle(document.body).zoom) : 1;
const screenHeight = screenRect.height / zoom;
const screenWidth = screenRect.width / zoom;

Expand Down
2 changes: 1 addition & 1 deletion packages/elements/src/tooltip/elements/tooltip-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ tooltipElement.condition = condition;
tooltipElement.renderer = renderer;

const appendTitleTooltip = (): void => {
document.body.appendChild(tooltipElement);
document.body?.appendChild(tooltipElement);
};

if (document.body) {
Expand Down
4 changes: 2 additions & 2 deletions packages/elements/src/tooltip/managers/tooltip-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class TooltipManager {
document.addEventListener('mouseleave', this.onMouseLeave, eventOptions);
document.addEventListener('wheel', this.onWheel, eventOptions);
document.addEventListener('keydown', this.onKeyDown, eventOptions);
document.body.addEventListener('blur', this.onBlur, eventOptions);
document.body?.addEventListener('blur', this.onBlur, eventOptions);

const clickEventOptions = supportOptions ? { passive: true, capture: true } : true;
document.addEventListener('click', this.onClick, clickEventOptions);
Expand All @@ -132,7 +132,7 @@ class TooltipManager {
document.removeEventListener('mouseleave', this.onMouseLeave);
document.removeEventListener('wheel', this.onWheel);
document.removeEventListener('keydown', this.onKeyDown);
document.body.removeEventListener('blur', this.onBlur);
document.body?.removeEventListener('blur', this.onBlur);

document.removeEventListener('click', this.onClick, true);
document.removeEventListener('contextmenu', this.onClick, true);
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sonar.projectKey=refinitiv_refinitiv-ui
sonar.organization=refinitiv
sonar.exclusions=documents/**, packages/*-theme/**, packages/configurations/**, *.config.js, cli.js, packages/elements/scripts/**, packages/*/*.config.js, **/__snapshots__/**, **/__demo__/**, **/__test__/**
sonar.javascript.lcov.reportPaths=**/coverage/lcov.info
sonar.coverage.exclusions=scripts/**, packages/phrasebook/**, packages/utils/**, packages/polyfills/**, packages/theme-compiler/**, packages/create-efx/**, packages/demo-block/**
sonar.coverage.exclusions=**/scripts/**, packages/phrasebook/**, packages/utils/**, packages/polyfills/**, packages/theme-compiler/**, packages/create-efx/**, packages/demo-block/**

# This is the name and version displayed in the SonarCloud UI.
#sonar.projectName=dtanp-rft_refinitiv-ui
Expand Down

0 comments on commit 347f98e

Please sign in to comment.