mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-02 22:03:11 +02:00
Resolve bug 533 (#736)
* Add placeholder options to demo page * Use constant types in components * Refactor adding predefined groups/items/choices * Add 'highlighted' flag to Item type * Fix dispatch param type * Build * Add jsdoc comments to utils * Remove unused file * Add default values to js doc comments * Use Redux Action type * Housekeeping * Increase utils coverage * Apply suggestions from code review * Add _getTemplate unit tests * Resolve #533 * Add tests
This commit is contained in:
parent
ab22347d7b
commit
f30b976424
|
@ -82,19 +82,6 @@ class Choices {
|
||||||
{ arrayMerge: (_, sourceArray) => [...sourceArray] },
|
{ 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);
|
const invalidConfigOptions = diff(this.config, DEFAULT_CONFIG);
|
||||||
if (invalidConfigOptions.length) {
|
if (invalidConfigOptions.length) {
|
||||||
console.warn(
|
console.warn(
|
||||||
|
@ -103,10 +90,6 @@ class Choices {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!['auto', 'always'].includes(this.config.renderSelectedChoices)) {
|
|
||||||
this.config.renderSelectedChoices = 'auto';
|
|
||||||
}
|
|
||||||
|
|
||||||
const passedElement =
|
const passedElement =
|
||||||
typeof element === 'string' ? document.querySelector(element) : element;
|
typeof element === 'string' ? document.querySelector(element) : element;
|
||||||
|
|
||||||
|
@ -127,6 +110,25 @@ class Choices {
|
||||||
this._isSelectElement =
|
this._isSelectElement =
|
||||||
this._isSelectOneElement || this._isSelectMultipleElement;
|
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) {
|
if (this._isTextElement) {
|
||||||
this.passedElement = new WrappedInput({
|
this.passedElement = new WrappedInput({
|
||||||
element: passedElement,
|
element: passedElement,
|
||||||
|
|
|
@ -63,6 +63,36 @@ describe('choices', () => {
|
||||||
...config,
|
...config,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('passing the searchEnabled config option with a value of 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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('passing the renderSelectedChoices config option with an unexpected value', () => {
|
||||||
|
it('sets renderSelectedChoices to "auto"', () => {
|
||||||
|
document.body.innerHTML = `
|
||||||
|
<select data-choice multiple></select>
|
||||||
|
`;
|
||||||
|
|
||||||
|
instance = new Choices('[data-choice]', {
|
||||||
|
renderSelectedChoices: 'test',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(instance.config.renderSelectedChoices).to.equal('auto');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue