aboutsummaryrefslogtreecommitdiffstats
path: root/ui/selectmenu.js
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2014-07-29 10:40:02 -0400
committerScott González <scott.gonzalez@gmail.com>2014-07-29 13:17:30 -0400
commit45e13ed208b3533e91d008789d61e5138501428a (patch)
treed6aac009c75da5b1cffe2d9c30a2b3b2b9a671d4 /ui/selectmenu.js
parentd1e327c189cb12661f53d6962ece07b31dec86cb (diff)
downloadjquery-ui-45e13ed208b3533e91d008789d61e5138501428a.tar.gz
jquery-ui-45e13ed208b3533e91d008789d61e5138501428a.zip
Selectmenu: Properly set width for button
Fixes #10145 Closes gh-1296
Diffstat (limited to 'ui/selectmenu.js')
-rw-r--r--ui/selectmenu.js22
1 files changed, 16 insertions, 6 deletions
diff --git a/ui/selectmenu.js b/ui/selectmenu.js
index 2107285fe..0b47feb53 100644
--- a/ui/selectmenu.js
+++ b/ui/selectmenu.js
@@ -106,7 +106,7 @@ return $.widget( "ui.selectmenu", {
.appendTo( this.button );
this._setText( this.buttonText, this.element.find( "option:selected" ).text() );
- this._setOption( "width", this.options.width );
+ this._resizeButton();
this._on( this.button, this._buttonEvents );
this.button.one( "focusin", function() {
@@ -186,7 +186,9 @@ return $.widget( "ui.selectmenu", {
refresh: function() {
this._refreshMenu();
this._setText( this.buttonText, this._getSelectedItem().text() );
- this._setOption( "width", this.options.width );
+ if ( !this.options.width ) {
+ this._resizeButton();
+ }
},
_refreshMenu: function() {
@@ -475,10 +477,7 @@ return $.widget( "ui.selectmenu", {
}
if ( key === "width" ) {
- if ( !value ) {
- value = this.element.outerWidth();
- }
- this.button.outerWidth( value );
+ this._resizeButton();
}
},
@@ -511,6 +510,17 @@ return $.widget( "ui.selectmenu", {
this.menu.attr( "aria-hidden", !this.isOpen );
},
+ _resizeButton: function() {
+ var width = this.options.width;
+
+ if ( !width ) {
+ width = this.element.show().outerWidth();
+ this.element.hide();
+ }
+
+ this.button.outerWidth( width );
+ },
+
_resizeMenu: function() {
this.menu.outerWidth( Math.max(
this.button.outerWidth(),