Skip to content

Commit 5a7d250

Browse files
committed
Merge pull request select2#2444 from surgeforward/undefined-top
Fix error: Cannot read property 'top' of undefined
2 parents 3fee8fc + 0675805 commit 5a7d250

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

select2.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ the specific language governing permissions and limitations under the Apache Lic
14831483

14841484
// abstract
14851485
ensureHighlightVisible: function () {
1486-
var results = this.results, children, index, child, hb, rb, y, more;
1486+
var results = this.results, children, index, child, hb, rb, y, more, topOffset;
14871487

14881488
index = this.highlight();
14891489

@@ -1503,7 +1503,9 @@ the specific language governing permissions and limitations under the Apache Lic
15031503

15041504
child = $(children[index]);
15051505

1506-
hb = child.offset().top + child.outerHeight(true);
1506+
topOffset = (child.offset() || {}).top || 0;
1507+
1508+
hb = topOffset + child.outerHeight(true);
15071509

15081510
// if this is the last child lets also make sure select2-more-results is visible
15091511
if (index === children.length - 1) {
@@ -1517,7 +1519,7 @@ the specific language governing permissions and limitations under the Apache Lic
15171519
if (hb > rb) {
15181520
results.scrollTop(results.scrollTop() + (hb - rb));
15191521
}
1520-
y = child.offset().top - results.offset().top;
1522+
y = topOffset - results.offset().top;
15211523

15221524
// make sure the top of the element is visible
15231525
if (y < 0 && child.css('display') != 'none' ) {

0 commit comments

Comments
 (0)