+
+ if (this.moveMenu) {
+ // Move to body to prevent being trapped within scrollable sections
+ this.rect = this.menu.getBoundingClientRect();
+ this.body.appendChild(this.menu);
+ this.menu.style.position = 'fixed';
+ this.menu.style.left = `${this.rect.left}px`;
+ this.menu.style.top = `${this.rect.top}px`;
+ this.menu.style.width = `${this.rect.width}px`;
+ }
+
+ // Set listener to hide on mouse leave or window click
+ this.menu.addEventListener('mouseleave', this.hide.bind(this));
+ window.addEventListener('click', event => {
+ if (!this.menu.contains(event.target)) {
+ this.hide();
+ }
+ });