From c1c925c0c5eb8c7b4f8f82b74cd729769db036aa Mon Sep 17 00:00:00 2001 From: Daniel Nelson <844258+daniel-nelson@users.noreply.github.com> Date: Mon, 21 Sep 2020 16:10:33 -0500 Subject: [PATCH 1/2] Autocomplete respect dropdownOptions. Fix placement when container is document.body --- js/autocomplete.js | 7 ++++--- js/dropdown.js | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/js/autocomplete.js b/js/autocomplete.js index 1bed2301a2..9adde2e89e 100644 --- a/js/autocomplete.js +++ b/js/autocomplete.js @@ -50,7 +50,7 @@ this.$inputField = this.$el.closest('.input-field'); this.$active = $(); this._mousedown = false; - this._setupDropdown(); + this._setupDropdown(options.dropdownOptions); this._setupEventHandlers(); } @@ -145,7 +145,7 @@ /** * Setup dropdown */ - _setupDropdown() { + _setupDropdown(dropdownOptions) { this.container = document.createElement('ul'); this.container.id = `autocomplete-options-${M.guid()}`; $(this.container).addClass('autocomplete-content dropdown-content'); @@ -158,7 +158,8 @@ coverTrigger: false, onItemClick: (itemEl) => { this.selectOption($(itemEl)); - } + }, + ...dropdownOptions }); // Sketchy removal of dropdown click handler diff --git a/js/dropdown.js b/js/dropdown.js index 5fd0d98668..1929f0f650 100644 --- a/js/dropdown.js +++ b/js/dropdown.js @@ -390,10 +390,22 @@ let triggerBRect = this.el.getBoundingClientRect(); let dropdownBRect = this.dropdownEl.getBoundingClientRect(); - let idealHeight = dropdownBRect.height; - let idealWidth = dropdownBRect.width; - let idealXPos = triggerBRect.left - dropdownBRect.left; - let idealYPos = triggerBRect.top - dropdownBRect.top; + let idealHeight; + let idealWidth; + let idealXPos; + let idealYPos; + + if (this.options.container == document.body) { + idealHeight = dropdownBRect.height; + idealWidth = triggerBRect.width; + idealXPos = triggerBRect.left; + idealYPos = triggerBRect.top; + } else { + idealHeight = dropdownBRect.height; + idealWidth = dropdownBRect.width; + idealXPos = triggerBRect.left - dropdownBRect.left; + idealYPos = triggerBRect.top - dropdownBRect.top; + } let dropdownBounds = { left: idealXPos, From d0df3ce3f3487323759a7ab500d13d9fd0a99f2b Mon Sep 17 00:00:00 2001 From: Daniel Nelson <844258+daniel-nelson@users.noreply.github.com> Date: Tue, 22 Sep 2020 12:29:38 -0500 Subject: [PATCH 2/2] Window may be scrolled when modal appears --- js/dropdown.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/dropdown.js b/js/dropdown.js index 1929f0f650..caa748d91f 100644 --- a/js/dropdown.js +++ b/js/dropdown.js @@ -398,8 +398,8 @@ if (this.options.container == document.body) { idealHeight = dropdownBRect.height; idealWidth = triggerBRect.width; - idealXPos = triggerBRect.left; - idealYPos = triggerBRect.top; + idealXPos = triggerBRect.left + window.scrollX; + idealYPos = triggerBRect.top + window.scrollY; } else { idealHeight = dropdownBRect.height; idealWidth = dropdownBRect.width;