Skip to content

Commit

Permalink
Menu: Account for scrollbars in jQuery 3.2
Browse files Browse the repository at this point in the history
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 gh-1929
  • Loading branch information
mgol committed Jul 23, 2020
1 parent 5e2fc44 commit 1712b9b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ui/widgets/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,13 @@ return $.widget( "ui.menu", {
}
if ( this._hasScroll() ) {
base = this.active.offset().top;
height = this.element.height();
height = this.element.innerHeight();

// jQuery 3.2 doesn't include scrollbars in innerHeight, add it back.
if ( $.fn.jquery.indexOf( "3.2." ) === 0 ) {
height += this.element[ 0 ].offsetHeight - this.element.outerHeight();
}

this.active.nextAll( ".ui-menu-item" ).each( function() {
item = $( this );
return item.offset().top - base - height < 0;
Expand All @@ -650,7 +656,13 @@ return $.widget( "ui.menu", {
}
if ( this._hasScroll() ) {
base = this.active.offset().top;
height = this.element.height();
height = this.element.innerHeight();

// jQuery 3.2 doesn't include scrollbars in innerHeight, add it back.
if ( $.fn.jquery.indexOf( "3.2." ) === 0 ) {
height += this.element[ 0 ].offsetHeight - this.element.outerHeight();
}

this.active.prevAll( ".ui-menu-item" ).each( function() {
item = $( this );
return item.offset().top - base + height > 0;
Expand Down

0 comments on commit 1712b9b

Please sign in to comment.