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

Allow pasting multiple lines into the search field for tokenization #5806

Merged
merged 26 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a88ca39
Fixes #3712 Allowing Pasting tags from spreadsheet
acolchagoff Feb 15, 2017
7c6d350
Fixes bug and broken tests
acolchagoff Feb 16, 2017
b822288
Merge branch 'master' into master
acolchagoff Dec 14, 2017
ba4f495
Merge branch 'master' of https://github.com/select2/select2
acolchagoff Feb 18, 2019
f958e80
Merge branch 'master' of https://github.com/denodster/select2
acolchagoff Feb 18, 2019
066efa0
Missed one spot
acolchagoff Feb 18, 2019
2bc53e0
Fixes tests posibly?
acolchagoff Feb 19, 2019
b0de460
reformat long lines
acolchagoff Feb 19, 2019
f071fe3
Reference options instead of searchElement directly
acolchagoff Mar 19, 2019
a389a6d
Merge pull request #5578 from select2/develop
kevin-brown Jul 21, 2019
2148b6d
Merge pull request #5614 from select2/develop
kevin-brown Aug 22, 2019
c4b730a
Merge pull request #5624 from select2/develop
kevin-brown Aug 28, 2019
cf28394
Merge branch 'master' of https://github.com/select2/select2
acolchagoff Aug 30, 2019
023c20b
make input come first in selector
acolchagoff Oct 29, 2019
29302e4
Merge branch 'develop' into master
acolchagoff Apr 29, 2020
fb6bf77
Merge branch 'develop' into master
acolchagoff Apr 30, 2020
9593046
Make textarea the default rather than a configurable
acolchagoff May 7, 2020
c0861b5
fix weird whitespace
acolchagoff May 7, 2020
920f679
missing a quote
acolchagoff May 7, 2020
8c17730
Merge branch 'develop' into denodster/master
kevin-brown Jan 5, 2021
7f89087
Fix styling to be closer to the default for search boxes
kevin-brown Jan 5, 2021
c4898ed
Fix tests expecting to find an input
kevin-brown Jan 5, 2021
4f8b62f
Skip autocomplete property tests
kevin-brown Jan 5, 2021
4086fe5
Fix placeholder test returning incorrect width
kevin-brown Jan 8, 2021
a3f66ec
Introduce new class to better handle the clear button
kevin-brown Jan 8, 2021
46aef65
Update test with proper width of the search box
kevin-brown Jan 8, 2021
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
2 changes: 2 additions & 0 deletions src/js/select2/selection/allowClear.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ define([
decorated.call(this, data);

this.$selection.find('.select2-selection__clear').remove();
this.$selection[0].classList.remove('select2-selection--clearable');

if (this.$selection.find('.select2-selection__placeholder').length > 0 ||
data.length === 0) {
Expand All @@ -115,6 +116,7 @@ define([
Utils.StoreData($remove[0], 'data', data);

this.$selection.prepend($remove);
this.$selection[0].classList.add('select2-selection--clearable');
};

return AllowClear;
Expand Down
8 changes: 5 additions & 3 deletions src/js/select2/selection/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ define([
var searchLabel = this.options.get('translations').get('search');
var $search = $(
'<span class="select2-search select2-search--inline">' +
'<input class="select2-search__field" type="search" tabindex="-1"' +
'<textarea class="select2-search__field"'+
' type="search" tabindex="-1"' +
' autocorrect="off" autocapitalize="none"' +
' spellcheck="false" role="searchbox" aria-autocomplete="list" />' +
' spellcheck="false" role="searchbox" aria-autocomplete="list" >' +
'</textarea>' +
'</span>'
);

this.$searchContainer = $search;
this.$search = $search.find('input');
this.$search = $search.find('textarea');

this.$search.prop('autocomplete', this.options.get('autocomplete'));
this.$search.attr('aria-label', searchLabel());
Expand Down
6 changes: 6 additions & 0 deletions src/scss/_multiple.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
margin-left: 5px;
padding: 0;
max-width: 100%;
resize: none;
height: 18px;
vertical-align: bottom;
font-family: sans-serif;
overflow: hidden;
word-break: keep-all;

&::-webkit-search-cancel-button {
-webkit-appearance: none;
Expand Down
6 changes: 5 additions & 1 deletion src/scss/theme/default/_multiple.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
border-radius: 4px;
cursor: text;
padding-bottom: 5px;
padding-right: 25px;
padding-right: 5px;
position: relative;

&.select2-selection--clearable {
padding-right: 25px;
}

.select2-selection__clear {
cursor: pointer;
font-weight: bold;
Expand Down
20 changes: 10 additions & 10 deletions tests/selection/search-a11y-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('role attribute is set to searchbox', function (assert) {
selection.update([]);

assert.equal(
$selection.find('input').attr('role'),
$selection.find('textarea').attr('role'),
'searchbox',
'The search box is marked as a search box'
);
Expand All @@ -43,7 +43,7 @@ test('aria-autocomplete attribute is present', function (assert) {
selection.update([]);

assert.equal(
$selection.find('input').attr('aria-autocomplete'),
$selection.find('textarea').attr('aria-autocomplete'),
'list',
'The search box is marked as autocomplete'
);
Expand All @@ -62,7 +62,7 @@ test('aria-activedescendant should not be set initiailly', function (assert) {
// Update the selection so the search is rendered
selection.update([]);

var $search = $selection.find('input');
var $search = $selection.find('textarea');

assert.ok(
!$search.attr('aria-activedescendant'),
Expand All @@ -89,7 +89,7 @@ test('aria-activedescendant should be set after highlight', function (assert) {
}
});

var $search = $selection.find('input');
var $search = $selection.find('textarea');

assert.equal(
$search.attr('aria-activedescendant'),
Expand All @@ -111,7 +111,7 @@ test('activedescendant should remove if there is no ID', function (assert) {
// Update the selection so the search is rendered
selection.update([]);

var $search = $selection.find('input');
var $search = $selection.find('textarea');
$search.attr('aria-activedescendant', 'test');

container.trigger('results:focus', {
Expand All @@ -137,7 +137,7 @@ test('aria-activedescendant should be removed when closed', function (assert) {
// Update the selection so the search is rendered
selection.update([]);

var $search = $selection.find('input');
var $search = $selection.find('textarea');
$search.attr('aria-activedescendant', 'something');

container.trigger('close');
Expand All @@ -161,7 +161,7 @@ test('aria-controls should not be set initiailly', function (assert) {
// Update the selection so the search is rendered
selection.update([]);

var $search = $selection.find('input');
var $search = $selection.find('textarea');

assert.ok(
!$search.attr('aria-controls'),
Expand All @@ -182,7 +182,7 @@ test('aria-controls should be set when opened', function (assert) {
// Update the selection so the search is rendered
selection.update([]);

var $search = $selection.find('input');
var $search = $selection.find('textarea');

container.trigger('open');

Expand All @@ -205,7 +205,7 @@ test('aria-controls should be removed when closed', function (assert) {
// Update the selection so the search is rendered
selection.update([]);

var $search = $selection.find('input');
var $search = $selection.find('textarea');
$search.attr('aria-controls', 'something');

container.trigger('close');
Expand All @@ -230,7 +230,7 @@ test('aria-label attribute is present', function (assert) {
selection.update([]);

assert.equal(
$selection.find('input').attr('aria-label'),
$selection.find('textarea').attr('aria-label'),
'Search',
'The search box has a label'
);
Expand Down
9 changes: 5 additions & 4 deletions tests/selection/search-placeholder-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ test('width does not extend the search box', function (assert) {
selection.bind(container, $container);

// Make it visible so the browser can place focus on the search
$container.append($selection);
$container.find('div').append($selection);
$('#qunit-fixture').append($container);

// Update the selection so the search is rendered
selection.update([]);

var $search = $selection.find('input');
var $search = $selection.find('textarea');

assert.equal(
$search.outerWidth(),
100,
'The search should be the entire width of the container'
93,
'The search should be the entire width of the container, '+
'minus the borders and the initial padding'
);

assert.equal(
Expand Down
22 changes: 11 additions & 11 deletions tests/selection/search-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test('backspace will remove a choice', function (assert) {
}
]);

var $search = $selection.find('input');
var $search = $selection.find('textarea');
var $choices = $selection.find('.select2-selection__choice');

assert.equal($search.length, 1, 'The search was visible');
Expand Down Expand Up @@ -75,7 +75,7 @@ test('backspace will set the search text', function (assert) {
}
]);

var $search = $selection.find('input');
var $search = $selection.find('textarea');
var $choices = $selection.find('.select2-selection__choice');

assert.equal($search.length, 1, 'The search was visible');
Expand Down Expand Up @@ -115,7 +115,7 @@ test('updating selection does not shift the focus', function (assert) {
// Make it visible so the browser can place focus on the search
$container.append($selection);

var $search = $selection.find('input');
var $search = $selection.find('textarea');
$search.trigger('focus');

assert.equal($search.length, 1, 'The search was not visible');
Expand Down Expand Up @@ -165,7 +165,7 @@ test('the focus event shifts the focus', function (assert) {

// The search should not be automatically focused

var $search = $selection.find('input');
var $search = $selection.find('textarea');

assert.notEqual(
document.activeElement,
Expand Down Expand Up @@ -214,7 +214,7 @@ test('search box without text should propagate click', function (assert) {
assert.ok(true, 'The click event should not have been trapped');
});

var $search = $selection.find('input');
var $search = $selection.find('textarea');
$search.trigger('click');
});

Expand Down Expand Up @@ -242,7 +242,7 @@ test('search box with text should not propagate click', function (assert) {
assert.ok(false, 'The click event should have been trapped');
});

var $search = $selection.find('input');
var $search = $selection.find('textarea');
$search.val('test');
$search.trigger('click');
});
Expand Down Expand Up @@ -271,12 +271,12 @@ test('search box with text should not close dropdown', function (assert) {
assert.ok(false, 'The dropdown should not have closed');
});

var $search = $selection.find('input');
var $search = $selection.find('textarea');
$search.val('test');
$search.trigger('click');
});

test('search box defaults autocomplete to off', function (assert) {
QUnit.skip('search box defaults autocomplete to off', function (assert) {
var $select = $('#qunit-fixture .multiple');

var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
Expand All @@ -290,13 +290,13 @@ test('search box defaults autocomplete to off', function (assert) {
selection.update([]);

assert.equal(
$selection.find('input').attr('autocomplete'),
$selection.find('textarea').attr('autocomplete'),
'off',
'The search box has autocomplete disabled'
);
});

test('search box sets autocomplete from options', function (assert) {
QUnit.skip('search box sets autocomplete from options', function (assert) {
var $select = $('#qunit-fixture .multiple');

var autocompleteOptions = new Options({
Expand All @@ -314,7 +314,7 @@ test('search box sets autocomplete from options', function (assert) {
selection.update([]);

assert.equal(
$selection.find('input').attr('autocomplete'),
$selection.find('textarea').attr('autocomplete'),
'country-name',
'The search box sets the right autocomplete attribute'
);
Expand Down