This commit is contained in:
Josh Johnson 2019-11-03 18:01:00 +00:00
parent 1ede39fa77
commit 688ad3f534
2 changed files with 35 additions and 17 deletions

View file

@ -82,19 +82,6 @@ class Choices {
{ arrayMerge: (_, sourceArray) => [...sourceArray] },
);
// Convert addItemFilter to function
if (
userConfig.addItemFilter &&
typeof userConfig.addItemFilter !== 'function'
) {
const re =
userConfig.addItemFilter instanceof RegExp
? userConfig.addItemFilter
: new RegExp(userConfig.addItemFilter);
this.config.addItemFilter = re.test.bind(re);
}
const invalidConfigOptions = diff(this.config, DEFAULT_CONFIG);
if (invalidConfigOptions.length) {
console.warn(
@ -103,10 +90,6 @@ class Choices {
);
}
if (!['auto', 'always'].includes(this.config.renderSelectedChoices)) {
this.config.renderSelectedChoices = 'auto';
}
const passedElement =
typeof element === 'string' ? document.querySelector(element) : element;
@ -127,6 +110,25 @@ class Choices {
this._isSelectElement =
this._isSelectOneElement || this._isSelectMultipleElement;
this.config.searchEnabled =
this._isSelectMultipleElement || this.config.searchEnabled;
if (!['auto', 'always'].includes(this.config.renderSelectedChoices)) {
this.config.renderSelectedChoices = 'auto';
}
if (
userConfig.addItemFilter &&
typeof userConfig.addItemFilter !== 'function'
) {
const re =
userConfig.addItemFilter instanceof RegExp
? userConfig.addItemFilter
: new RegExp(userConfig.addItemFilter);
this.config.addItemFilter = re.test.bind(re);
}
if (this._isTextElement) {
this.passedElement = new WrappedInput({
element: passedElement,

View file

@ -63,6 +63,22 @@ describe('choices', () => {
...config,
});
});
describe('passing the searchEnabled config option as false', () => {
describe('passing a select-multiple element', () => {
it('sets searchEnabled to true', () => {
document.body.innerHTML = `
<select data-choice multiple></select>
`;
instance = new Choices('[data-choice]', {
searchEnabled: false,
});
expect(instance.config.searchEnabled).to.equal(true);
});
});
});
});
});