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

allowClear no longer shifts selections to a new line #5603

Merged
merged 2 commits into from Aug 5, 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/scss/theme/default/_multiple.scss
Expand Up @@ -22,6 +22,12 @@
font-weight: bold;
margin-top: 5px;
margin-right: 10px;

// This padding is to account for the bottom border for the first
// selection row and the top border of the second selection row.
// Without it, selections on the first row may be offset incorrectly
// and appear in their own row instead of going to the second row
padding: 1px;
}

.select2-selection__choice {
Expand Down
70 changes: 70 additions & 0 deletions tests/selection/allowClear-tests.js
Expand Up @@ -4,6 +4,7 @@ var Placeholder = require('select2/selection/placeholder');
var AllowClear = require('select2/selection/allowClear');

var SingleSelection = require('select2/selection/single');
var MultipleSelection = require('select2/selection/multiple');

var $ = require('jquery');
var Options = require('select2/options');
Expand Down Expand Up @@ -328,3 +329,72 @@ test('clear does not work when disabled', function (assert) {
'The placeholder should not have been set'
);
});

test('clear button doesnt visually break selected options', function (assert) {
var $element = $('<select></select>');

var Selection = Utils.Decorate(
Utils.Decorate(MultipleSelection, Placeholder),
AllowClear
);

var selection = new Selection(
$element,
allowClearOptions
);
var container = new MockContainer();

var $container = $(
'<span class="select2-container select2-container--default"></span>'
);
$('#qunit-fixture').append($container);

var $selection = selection.render();
$container.append($selection);
$container.css('width', '100px');

selection.bind(container, $container);

selection.update([{
id: '1',
text: '1'
}]);

var singleHeight = $container.height();

selection.update([
{
id: '10',
text: '10'
},
{
id: '20',
text: '20'
}
]);

var doubleHeight = $container.height();

selection.update([
{
id: '1',
text: '1'
},
{
id: '2',
text: '2'
}
]);

assert.notEqual(
singleHeight,
doubleHeight,
'The height of the two different rows should be different'
);

assert.equal(
$container.height(),
doubleHeight,
'There should be two full lines of selections'
);
});