Skip to content

Commit 1712b9b

Browse files
authored
Menu: Account for scrollbars in jQuery 3.2
jQuery >=3.2 doesn't include scrollbars in `.height()`, this commit switches it to `.innerHeight()` which does so in jQuery >=3.3. In jQuery 3.2 it doesn't either so include scrollbars in innerHeight, add it back. Using `.innerHeight()` instead of `.height()` should be fine as menu doesn't define padding styles. Closes jquerygh-1929
1 parent 5e2fc44 commit 1712b9b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

ui/widgets/menu.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,13 @@ return $.widget( "ui.menu", {
626626
}
627627
if ( this._hasScroll() ) {
628628
base = this.active.offset().top;
629-
height = this.element.height();
629+
height = this.element.innerHeight();
630+
631+
// jQuery 3.2 doesn't include scrollbars in innerHeight, add it back.
632+
if ( $.fn.jquery.indexOf( "3.2." ) === 0 ) {
633+
height += this.element[ 0 ].offsetHeight - this.element.outerHeight();
634+
}
635+
630636
this.active.nextAll( ".ui-menu-item" ).each( function() {
631637
item = $( this );
632638
return item.offset().top - base - height < 0;
@@ -650,7 +656,13 @@ return $.widget( "ui.menu", {
650656
}
651657
if ( this._hasScroll() ) {
652658
base = this.active.offset().top;
653-
height = this.element.height();
659+
height = this.element.innerHeight();
660+
661+
// jQuery 3.2 doesn't include scrollbars in innerHeight, add it back.
662+
if ( $.fn.jquery.indexOf( "3.2." ) === 0 ) {
663+
height += this.element[ 0 ].offsetHeight - this.element.outerHeight();
664+
}
665+
654666
this.active.prevAll( ".ui-menu-item" ).each( function() {
655667
item = $( this );
656668
return item.offset().top - base + height > 0;

0 commit comments

Comments
 (0)