Add computedstyle
option for calculating the width (#5559)
This allows for more accurate resolution of the width when compared to the `resolve` method. This is more relevant for jQuery 1.x, where the `resolve` method cannot find the width of a hidden select box, but it also applies to newer versions of jQuery where the `width()` method provided by jQuery doesn't fully match `getComputedStyle()`. Fixes #3278 Fixes #5502 Closes #5259
This commit is contained in:
parent
f9decd6094
commit
b5f136ff72
6
src/js/select2/core.js
vendored
6
src/js/select2/core.js
vendored
@ -162,6 +162,12 @@ define([
|
||||
return null;
|
||||
}
|
||||
|
||||
if (method == 'computedstyle') {
|
||||
var computedStyle = window.getComputedStyle($element[0]);
|
||||
|
||||
return computedStyle.width;
|
||||
}
|
||||
|
||||
return method;
|
||||
};
|
||||
|
||||
|
@ -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 = $(
|
||||
'<style type="text/css">.css-set-width { width: 500px; }</style>'
|
||||
);
|
||||
var $test = $(
|
||||
'<div style="display:none;">' +
|
||||
'<select class="css-set-width"></select>' +
|
||||
'</div>'
|
||||
);
|
||||
|
||||
$('#qunit-fixture').append($style);
|
||||
$('#qunit-fixture').append($test);
|
||||
|
||||
var width = select._resolveWidth($test.find('select'), 'computedstyle');
|
||||
|
||||
assert.equal(width, '500px');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user