From df2ef7118cf7ac37a7f86a0c6d2d016080875997 Mon Sep 17 00:00:00 2001 From: Terry Aney Date: Wed, 19 Jan 2022 11:17:50 -0600 Subject: [PATCH] max-height/offsetHeight Calculation Issue, Fixes #2581 --- js/bootstrap-select.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/js/bootstrap-select.js b/js/bootstrap-select.js index f26b9e58c..067a68a6e 100644 --- a/js/bootstrap-select.js +++ b/js/bootstrap-select.js @@ -2118,6 +2118,16 @@ if (doneButton) menu.appendChild(doneButton); newElement.appendChild(menu); + var newElementAnchor = $('a', $(li)); + // Get 'visible' css items to restore after calculation is done + var newElementAnchorDisplay = newElementAnchor.css('display'); + var newElementAnchorVisibility = newElementAnchor.css('visibility'); + newElementAnchor.show(); // always make sure first item is shown, otherwise offsetHeight = 0 + if (newElementAnchor.text() === '') { + // If blank, set text to non-breaking space otherwise offsetHeight = 8 (or some portion of full height) + newElementAnchor.text = ' '; + } + document.body.appendChild(newElement); var liHeight = li.offsetHeight, @@ -2170,6 +2180,9 @@ this.sizeInfo.scrollBarWidth = scrollBarWidth; this.sizeInfo.selectHeight = this.$newElement[0].offsetHeight; + if (newElementAnchorDisplay !== undefined && newElementAnchorDisplay !== '') newElementAnchor.css('display', newElementAnchorDisplay); + if (newElementAnchorVisibility !== undefined && newElementAnchorVisibility !== '') newElementAnchor.css('visibility', newElementAnchorVisibility); + this.setPositionData(); },