Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add computedstyle option for calculating the width #5559

Merged
merged 1 commit into from Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/js/select2/core.js
Expand Up @@ -162,6 +162,12 @@ define([
return null;
}

if (method == 'computedstyle') {
var computedStyle = window.getComputedStyle($element[0]);

return computedStyle.width;
}

return method;
};

Expand Down
18 changes: 18 additions & 0 deletions tests/options/width-tests.js
Expand Up @@ -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');
});