Skip to content

Commit 77de06e

Browse files
committed
improve percent width detection. issue select2#115
1 parent 9c864f1 commit 77de06e

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

select2.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,9 +1044,12 @@
10441044
// abstract
10451045
getContainerWidth: function () {
10461046
var style, attrs, matches, i, l;
1047+
1048+
// see if there is width specified in opts
10471049
if (this.opts.width !== undefined)
10481050
return this.opts.width;
10491051

1052+
// next check if there is inline style on the element that contains width
10501053
style = this.opts.element.attr('style');
10511054
if (style !== undefined) {
10521055
attrs = style.split(';');
@@ -1057,6 +1060,13 @@
10571060
return matches[1];
10581061
}
10591062
}
1063+
1064+
// next check if css('width') can resolve a width that is percent based, this is sometimes possible
1065+
// when attached to input type=hidden or elements hidden via css
1066+
style = this.opts.element.css('width');
1067+
if (style.indexOf("%") > 0) return style;
1068+
1069+
// finally, fallback on the calculated width of the element
10601070
return (this.opts.element.width() === 0 ? 'auto' : this.opts.element.width() + 'px');
10611071
}
10621072
});

0 commit comments

Comments
 (0)