Skip to content

Commit ddc7bb8

Browse files
authored
Merge pull request #1366 from Choices-js/fix-searchEnabled-select-multiple
Fix `searchEnabled` being disabled for `select-multiple` did not work
2 parents d6a79be + 43210ca commit ddc7bb8

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
- Define `[aria-selected]` for selectable choices per WAI-ARIA 1.2 spec, and avoid triple state with aria-selected [#1330](https://github.com/Choices-js/Choices/pull/1330)
2020
- Fix `appendGroupInSearch` option was non-functional [#1324](https://github.com/Choices-js/Choices/pull/1324)
2121
- When resolving the remove item/label/icon, add a 3rd argument item argument. Update default remove item label to use this (Fixes #1296) [#1323](https://github.com/Choices-js/Choices/pull/1323)
22-
- Fix `searchResultLimit` could not be set to -1 when renderChoiceLimit was set [#1322](https://github.com/Choices-js/Choices/pull/1322)
22+
- Fix `searchResultLimit` could not be set to `-1` when `renderChoiceLimit` was set [#1322](https://github.com/Choices-js/Choices/pull/1322)
2323
- Fix dropdown would stick closed when a search loses focus [#1308](https://github.com/Choices-js/Choices/pull/1308)
24+
- Fix `searchEnabled` being disabled for `select-multiple` did not work [#1366](https://github.com/Choices-js/Choices/pull/1366)
2425

2526
### Chore
2627
- Update callback argument documentation

public/test/select-multiple/index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,28 @@ <h2>Select multiple inputs</h2>
478478
</script>
479479
</div>
480480

481+
<div data-test-hook="search-disabled">
482+
<label for="choices-search-disabled">Search disabled</label>
483+
<select
484+
class="form-control"
485+
name="choices-search-disabled"
486+
id="choices-search-disabled"
487+
multiple
488+
>
489+
<option value="Choice 1">Choice 1</option>
490+
<option value="Choice 2">Choice 2</option>
491+
<option value="Choice 3">Choice 3</option>
492+
</select>
493+
<script>
494+
document.addEventListener('DOMContentLoaded', function() {
495+
new Choices('#choices-search-disabled', {
496+
allowHTML: true,
497+
searchEnabled: false,
498+
});
499+
});
500+
</script>
501+
</div>
502+
481503
<div data-test-hook="search-floor">
482504
<label for="choices-search-floor">Search floor</label>
483505
<select

src/scripts/choices.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class Choices {
260260

261261
this._store = new Store(config);
262262
this._currentValue = '';
263-
config.searchEnabled = (!isText && config.searchEnabled) || isSelectMultiple;
263+
config.searchEnabled = !isText && config.searchEnabled;
264264
this._canSearch = config.searchEnabled;
265265
this._isScrollingOnIe = false;
266266
this._highlightPosition = 0;
@@ -2288,26 +2288,26 @@ class Choices {
22882288
// Wrapper inner container with outer container
22892289
containerOuter.wrap(containerInner.element);
22902290

2291+
containerOuter.element.appendChild(containerInner.element);
2292+
containerOuter.element.appendChild(dropdownElement);
2293+
containerInner.element.appendChild(this.itemList.element);
2294+
dropdownElement.appendChild(this.choiceList.element);
2295+
22912296
if (this._isSelectOneElement) {
22922297
this.input.placeholder = this.config.searchPlaceholderValue || '';
2298+
if (this.config.searchEnabled) {
2299+
dropdownElement.insertBefore(this.input.element, dropdownElement.firstChild);
2300+
}
22932301
} else {
2302+
if (!this._isSelectMultipleElement || this.config.searchEnabled) {
2303+
containerInner.element.appendChild(this.input.element);
2304+
}
22942305
if (this._placeholderValue) {
22952306
this.input.placeholder = this._placeholderValue;
22962307
}
22972308
this.input.setWidth();
22982309
}
22992310

2300-
containerOuter.element.appendChild(containerInner.element);
2301-
containerOuter.element.appendChild(dropdownElement);
2302-
containerInner.element.appendChild(this.itemList.element);
2303-
dropdownElement.appendChild(this.choiceList.element);
2304-
2305-
if (!this._isSelectOneElement) {
2306-
containerInner.element.appendChild(this.input.element);
2307-
} else if (this.config.searchEnabled) {
2308-
dropdownElement.insertBefore(this.input.element, dropdownElement.firstChild);
2309-
}
2310-
23112311
this._highlightPosition = 0;
23122312
this._isSearching = false;
23132313
}

test-e2e/tests/select-multiple.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,6 @@ describe(`Choices - select multiple`, () => {
595595
});
596596
});
597597

598-
/*
599598
describe('search disabled', () => {
600599
const testId = 'search-disabled';
601600
test('does not display a search input', async ({ page, bundle }) => {
@@ -616,10 +615,9 @@ describe(`Choices - select multiple`, () => {
616615

617616
await suite.expectedItemCount(1);
618617
await suite.expectedValue(text);
619-
await suite.expectHiddenDropdown();
618+
await suite.expectVisibleDropdown();
620619
});
621620
});
622-
*/
623621

624622
describe('search floor', () => {
625623
const testId = 'search-floor';

test/scripts/choices.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ describe('choices', () => {
9898
searchEnabled: false,
9999
});
100100

101-
expect(instance.config.searchEnabled).to.equal(true);
101+
expect(instance.config.searchEnabled).to.equal(false);
102102
});
103103
});
104104
});

0 commit comments

Comments
 (0)