Skip to content

Commit

Permalink
feat(mouseover): improve handling of showing popover on mouseover
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanjones243 committed Mar 8, 2024
1 parent efacc6d commit 3e80158
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/auro-popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,6 @@ export class AuroPopover extends LitElement {
}
}

// randomId() {
// const random = (Math.random() + 1).toString(36).substring(7);
// return `popover-${random}`
// }

/**
* Hides the popover.
* @private
Expand All @@ -147,6 +142,8 @@ export class AuroPopover extends LitElement {
this.popper.hide();
this.isPopoverVisible = false;
this.removeAttribute('data-show');

document.querySelector('body').removeEventListener('mouseover', this.mouseoverHandler);
}

/**
Expand All @@ -158,6 +155,22 @@ export class AuroPopover extends LitElement {
this.popper.show();
this.isPopoverVisible = true;
this.setAttribute('data-show', true);

this.mouseoverHandler = (evt) => this.handleMouseoverEvent(evt);

document.querySelector('body').addEventListener('mouseover', this.mouseoverHandler);
}

/**
* Hides the popover when hovering outside of the popover or it's trigger.
* @private
* @param {Event} evt - The event object.
* @returns {void}
*/
handleMouseoverEvent(evt) {
if (this.isPopoverVisible && !evt.composedPath().includes(this)) {
this.toggleHide();
}
}

// function that renders the HTML and CSS into the scope of the component
Expand Down

0 comments on commit 3e80158

Please sign in to comment.