diff --git a/src/js/select2/core.js b/src/js/select2/core.js index 3d4ade2e..92084143 100644 --- a/src/js/select2/core.js +++ b/src/js/select2/core.js @@ -162,6 +162,12 @@ define([ return null; } + if (method == 'computedstyle') { + var computedStyle = window.getComputedStyle($element[0]); + + return computedStyle.width; + } + return method; }; diff --git a/tests/options/width-tests.js b/tests/options/width-tests.js index e7240349..4f774b9c 100644 --- a/tests/options/width-tests.js +++ b/tests/options/width-tests.js @@ -64,3 +64,21 @@ test('resolve falls back to element if there is no style', function (assert) { assert.equal(width, '500px'); }); + +test('computedstyle gets the style if parent is invisible', function (assert) { + var $style = $( + '' + ); + var $test = $( + '
' + ); + + $('#qunit-fixture').append($style); + $('#qunit-fixture').append($test); + + var width = select._resolveWidth($test.find('select'), 'computedstyle'); + + assert.equal(width, '500px'); +});