1
0
mirror of synced 2024-11-22 04:56:08 +03:00

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:
Kevin Brown 2019-07-09 19:44:33 -04:00 committed by GitHub
parent f9decd6094
commit b5f136ff72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -162,6 +162,12 @@ define([
return null;
}
if (method == 'computedstyle') {
var computedStyle = window.getComputedStyle($element[0]);
return computedStyle.width;
}
return method;
};

View File

@ -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');
});