Skip to content
Permalink
Browse files

Selectmenu: better position handling, fixes issue with wrong styles w…

…hen using custom positioning
  • Loading branch information...
fnagel committed Nov 28, 2012
1 parent 36533a7 commit 7328333773ad20d11230b3173e0a71ac39cfaa90
Showing with 8 additions and 8 deletions.
  1. +8 −8 ui/jquery.ui.selectmenu.js
@@ -198,6 +198,10 @@ $.widget( "ui.selectmenu", {

open: function( event ) {
if ( !this.options.disabled ) {
var _position = {
of: this.button
};

// make sure menu is refreshed on first init (needed at least for IE9)
if ( this.isOpen === undefined ) {
this.button.trigger( "focus" );
@@ -207,25 +211,21 @@ $.widget( "ui.selectmenu", {
this._toggleAttr();
this.menu.menu( "focus", event, this._getSelectedItem() );

if ( this.items && !this.options.dropdown ) {
if ( this.items && !this.options.dropdown && this.options.position.my == "left top" && this.options.position.at == "left bottom" ) {
var currentItem = this._getSelectedItem();
// center current item
if ( this.menu.outerHeight() < this.menu.prop( "scrollHeight" ) ) {
this.menuWrap.css( "left" , -10000 );
this.menu.scrollTop( this.menu.scrollTop() + currentItem.position().top - this.menu.outerHeight() / 2 + currentItem.outerHeight() / 2 );
this.menuWrap.css( "left" , "auto" );
}

$.extend( this.options.position, {
my: "left top" + ( this.menu.offset().top - currentItem.offset().top + ( this.button.outerHeight() - currentItem.outerHeight() ) / 2 ),
at: "left top"
});
_position.my = "left top" + ( this.menu.offset().top - currentItem.offset().top + ( this.button.outerHeight() - currentItem.outerHeight() ) / 2 );
_position.at = "left top";
}

this.options.position.of = this.button;
this.menuWrap
.zIndex( this.element.zIndex() + 1 )
.position( this.options.position );
.position( $.extend( {}, this.options.position, _position ) );

this._trigger( "open", event );
}

0 comments on commit 7328333

Please sign in to comment.
You can’t perform that action at this time.