Skip to content

Commit

Permalink
fix: fix bug breaking single-element highlight w/out popover
Browse files Browse the repository at this point in the history
  • Loading branch information
josias-r committed Mar 23, 2023
1 parent 0ff550e commit 92d7bfb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib/core/highlight-element.ts
Expand Up @@ -3,7 +3,7 @@ import {
CLASS_ACTIVE_HIGHLIGHTED_ELEMENT,
CLASS_POPOVER_NO_ELEMENT,
} from "../common/constants";
import { assertVarIsNotFalsy, bringInView } from "../common/utils";
import { bringInView } from "../common/utils";
import Popover from "./popover";

/** The options of popover that will come from the top-level but can also be overwritten */
Expand Down Expand Up @@ -165,21 +165,21 @@ class HighlightElement {
*/
public getDOMRect() {
// We get the popover, to possibly mark it w/ CLASS_POPOVER_NO_ELEMENT
// Note: Popover might not exist, for boarding.highlight w/out popover, therefore no asserIsNotFalsy
const popoverWrapper = this.popover?.getPopoverElements()?.popoverWrapper;
assertVarIsNotFalsy(popoverWrapper);

const element = this.getElement();
const domRect = element.getBoundingClientRect();

// if element is not connected to the DOM, fallback to cached version if available
if (!element.isConnected) {
// mark popover as "no element found"
popoverWrapper.classList.add(CLASS_POPOVER_NO_ELEMENT);
popoverWrapper?.classList.add(CLASS_POPOVER_NO_ELEMENT);
return this.lastKnownDomRect || domRect;
}

// make sure CLASS_POPOVER_NO_ELEMENT is not there
popoverWrapper.classList.remove(CLASS_POPOVER_NO_ELEMENT);
popoverWrapper?.classList.remove(CLASS_POPOVER_NO_ELEMENT);
this.lastKnownDomRect = domRect;
return domRect;
}
Expand Down

0 comments on commit 92d7bfb

Please sign in to comment.