mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-18 13:45:12 +02:00
Resolve eslint issues
This commit is contained in:
parent
c9c1eab014
commit
9c4f1f4963
|
@ -131,12 +131,7 @@ class Choices {
|
||||||
// Merge options with user options
|
// Merge options with user options
|
||||||
this.config = extend(defaultConfig, userConfig);
|
this.config = extend(defaultConfig, userConfig);
|
||||||
|
|
||||||
if (this.config.renderSelectedChoices !== 'auto' && this.config.renderSelectedChoices !== 'always') {
|
if (!['auto', 'always'].includes(this.config.renderSelectedChoices)) {
|
||||||
if (!this.config.silent) {
|
|
||||||
console.warn(
|
|
||||||
'renderSelectedChoices: Possible values are \'auto\' and \'always\'. Falling back to \'auto\'.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.config.renderSelectedChoices = 'auto';
|
this.config.renderSelectedChoices = 'auto';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +165,9 @@ class Choices {
|
||||||
|
|
||||||
if (this.config.shouldSortItems === true && this.isSelectOneElement) {
|
if (this.config.shouldSortItems === true && this.isSelectOneElement) {
|
||||||
if (!this.config.silent) {
|
if (!this.config.silent) {
|
||||||
console.warn('shouldSortElements: Type of passed element is \'select-one\', falling back to false.');
|
console.warn(
|
||||||
|
'shouldSortElements: Type of passed element is \'select-one\', falling back to false.',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1398,13 +1395,17 @@ class Choices {
|
||||||
*/
|
*/
|
||||||
_searchChoices(value) {
|
_searchChoices(value) {
|
||||||
const newValue = isType('String', value) ? value.trim() : value;
|
const newValue = isType('String', value) ? value.trim() : value;
|
||||||
const currentValue = isType('String', this.currentValue) ? this.currentValue.trim() : this.currentValue;
|
const currentValue = isType('String', this.currentValue) ?
|
||||||
|
this.currentValue.trim() :
|
||||||
|
this.currentValue;
|
||||||
|
|
||||||
// If new value matches the desired length and is not the same as the current value with a space
|
// If new value matches the desired length and is not the same as the current value with a space
|
||||||
if (newValue.length >= 1 && newValue !== `${currentValue} `) {
|
if (newValue.length >= 1 && newValue !== `${currentValue} `) {
|
||||||
const haystack = this.store.getSearchableChoices();
|
const haystack = this.store.getSearchableChoices();
|
||||||
const needle = newValue;
|
const needle = newValue;
|
||||||
const keys = isType('Array', this.config.searchFields) ? this.config.searchFields : [this.config.searchFields];
|
const keys = isType('Array', this.config.searchFields) ?
|
||||||
|
this.config.searchFields :
|
||||||
|
[this.config.searchFields];
|
||||||
const options = Object.assign(this.config.fuseOptions, { keys });
|
const options = Object.assign(this.config.fuseOptions, { keys });
|
||||||
const fuse = new Fuse(haystack, options);
|
const fuse = new Fuse(haystack, options);
|
||||||
const results = fuse.search(needle);
|
const results = fuse.search(needle);
|
||||||
|
@ -1585,7 +1586,9 @@ class Choices {
|
||||||
|
|
||||||
if (hasActiveDropdown) {
|
if (hasActiveDropdown) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const highlighted = this.dropdown.element.querySelector(`.${this.config.classNames.highlightedState}`);
|
const highlighted = this.dropdown.element.querySelector(
|
||||||
|
`.${this.config.classNames.highlightedState}`,
|
||||||
|
);
|
||||||
|
|
||||||
// If we have a highlighted choice
|
// If we have a highlighted choice
|
||||||
if (highlighted) {
|
if (highlighted) {
|
||||||
|
@ -1625,12 +1628,16 @@ class Choices {
|
||||||
let nextEl;
|
let nextEl;
|
||||||
if (skipKey) {
|
if (skipKey) {
|
||||||
if (directionInt > 0) {
|
if (directionInt > 0) {
|
||||||
nextEl = Array.from(this.dropdown.element.querySelectorAll('[data-choice-selectable]')).pop();
|
nextEl = Array.from(
|
||||||
|
this.dropdown.element.querySelectorAll('[data-choice-selectable]'),
|
||||||
|
).pop();
|
||||||
} else {
|
} else {
|
||||||
nextEl = this.dropdown.element.querySelector('[data-choice-selectable]');
|
nextEl = this.dropdown.element.querySelector('[data-choice-selectable]');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const currentEl = this.dropdown.element.querySelector(`.${this.config.classNames.highlightedState}`);
|
const currentEl = this.dropdown.element.querySelector(
|
||||||
|
`.${this.config.classNames.highlightedState}`,
|
||||||
|
);
|
||||||
if (currentEl) {
|
if (currentEl) {
|
||||||
nextEl = getAdjacentEl(currentEl, '[data-choice-selectable]', directionInt);
|
nextEl = getAdjacentEl(currentEl, '[data-choice-selectable]', directionInt);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2307,7 +2314,9 @@ class Choices {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_addGroup(group, id, valueKey = 'value', labelKey = 'label') {
|
_addGroup(group, id, valueKey = 'value', labelKey = 'label') {
|
||||||
const groupChoices = isType('Object', group) ? group.choices : Array.from(group.getElementsByTagName('OPTION'));
|
const groupChoices = isType('Object', group) ?
|
||||||
|
group.choices :
|
||||||
|
Array.from(group.getElementsByTagName('OPTION'));
|
||||||
const groupId = id || Math.floor(new Date().valueOf() * Math.random());
|
const groupId = id || Math.floor(new Date().valueOf() * Math.random());
|
||||||
const isDisabled = group.disabled ? group.disabled : false;
|
const isDisabled = group.disabled ? group.disabled : false;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
var webpack = require('karma-webpack');
|
let webpack = require('karma-webpack');
|
||||||
|
|
||||||
module.exports = function(config) {
|
module.exports = function(config) {
|
||||||
config.set({
|
config.set({
|
||||||
|
@ -13,35 +13,35 @@ module.exports = function(config) {
|
||||||
'karma-coverage',
|
'karma-coverage',
|
||||||
'karma-spec-reporter',
|
'karma-spec-reporter',
|
||||||
'karma-htmlfile-reporter',
|
'karma-htmlfile-reporter',
|
||||||
'es6-shim'
|
'es6-shim',
|
||||||
],
|
],
|
||||||
browsers: ['PhantomJS'],
|
browsers: ['PhantomJS'],
|
||||||
preprocessors: {
|
preprocessors: {
|
||||||
'**/*_spec.js': ['webpack'],
|
'**/*_spec.js': ['webpack'],
|
||||||
'src/**/*.js': ['webpack']
|
'src/**/*.js': ['webpack'],
|
||||||
},
|
},
|
||||||
reporters: ['spec', 'coverage', 'html'],
|
reporters: ['spec', 'coverage', 'html'],
|
||||||
coverageReporter: {
|
coverageReporter: {
|
||||||
dir: '../tests/reports/coverage',
|
dir: '../tests/reports/coverage',
|
||||||
reporters: [{
|
reporters: [{
|
||||||
type: 'html',
|
type: 'html',
|
||||||
}]
|
}],
|
||||||
},
|
},
|
||||||
webpack: {
|
webpack: {
|
||||||
module: {
|
module: {
|
||||||
loaders: [{
|
loaders: [{
|
||||||
test: /\.(js|jsx)$/,
|
test: /\.(js|jsx)$/,
|
||||||
exclude: /(bower_components|node_modules)/,
|
exclude: /(bower_components|node_modules)/,
|
||||||
loader: 'babel-loader'
|
loader: 'babel-loader',
|
||||||
}],
|
}],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
colors: true,
|
colors: true,
|
||||||
webpackMiddleware: {
|
webpackMiddleware: {
|
||||||
noInfo: true
|
noInfo: true,
|
||||||
},
|
},
|
||||||
htmlReporter: {
|
htmlReporter: {
|
||||||
outputFile: 'results/unit-tests.html'
|
outputFile: 'results/unit-tests.html',
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
|
@ -1,6 +1,7 @@
|
||||||
import 'whatwg-fetch';
|
import 'whatwg-fetch';
|
||||||
import 'es6-promise';
|
import 'es6-promise';
|
||||||
import 'core-js/fn/object/assign';
|
import 'core-js/fn/object/assign';
|
||||||
|
import 'core-js/fn/array/includes';
|
||||||
import Choices from '../../assets/scripts/src/choices';
|
import Choices from '../../assets/scripts/src/choices';
|
||||||
import itemReducer from '../../assets/scripts/src/reducers/items';
|
import itemReducer from '../../assets/scripts/src/reducers/items';
|
||||||
import choiceReducer from '../../assets/scripts/src/reducers/choices';
|
import choiceReducer from '../../assets/scripts/src/reducers/choices';
|
||||||
|
@ -217,7 +218,9 @@ describe('Choices', () => {
|
||||||
ctrlKey: false,
|
ctrlKey: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(this.choices.currentState.items[this.choices.currentState.items.length - 1]).not.toContain(this.choices.input.element.value);
|
expect(
|
||||||
|
this.choices.currentState.items[this.choices.currentState.items.length - 1]
|
||||||
|
).not.toContain(this.choices.input.element.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should filter input if regexFilter is passed', function() {
|
it('should filter input if regexFilter is passed', function() {
|
||||||
|
@ -312,7 +315,9 @@ describe('Choices', () => {
|
||||||
it('should open the choice list on focusing', function() {
|
it('should open the choice list on focusing', function() {
|
||||||
this.choices = new Choices(this.input);
|
this.choices = new Choices(this.input);
|
||||||
this.choices.input.element.focus();
|
this.choices.input.element.focus();
|
||||||
expect(this.choices.dropdown.element.classList).toContain(this.choices.config.classNames.activeState);
|
expect(
|
||||||
|
this.choices.dropdown.element.classList,
|
||||||
|
).toContain(this.choices.config.classNames.activeState);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should select the first choice', function() {
|
it('should select the first choice', function() {
|
||||||
|
@ -405,7 +410,10 @@ describe('Choices', () => {
|
||||||
preventDefault: () => {},
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(document.activeElement === this.choices.input.element && container.classList.contains('is-open')).toBe(true);
|
expect(
|
||||||
|
document.activeElement === this.choices.input.element &&
|
||||||
|
container.classList.contains('is-open'),
|
||||||
|
).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should close the dropdown on double click', function() {
|
it('should close the dropdown on double click', function() {
|
||||||
|
@ -425,7 +433,10 @@ describe('Choices', () => {
|
||||||
preventDefault: () => {},
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(document.activeElement === this.choices.input.element && container.classList.contains(openState)).toBe(false);
|
expect(
|
||||||
|
document.activeElement === this.choices.input.element &&
|
||||||
|
container.classList.contains(openState)
|
||||||
|
).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set scrolling flag and not hide dropdown when scrolling on IE', function() {
|
it('should set scrolling flag and not hide dropdown when scrolling on IE', function() {
|
||||||
|
@ -742,18 +753,26 @@ describe('Choices', () => {
|
||||||
|
|
||||||
it('should handle showDropdown()', function() {
|
it('should handle showDropdown()', function() {
|
||||||
this.choices.showDropdown();
|
this.choices.showDropdown();
|
||||||
const hasOpenState = this.choices.containerOuter.element.classList.contains(this.choices.config.classNames.openState);
|
const hasOpenState = this.choices.containerOuter.element.classList.contains(
|
||||||
|
this.choices.config.classNames.openState,
|
||||||
|
);
|
||||||
const hasAttr = this.choices.containerOuter.element.getAttribute('aria-expanded') === 'true';
|
const hasAttr = this.choices.containerOuter.element.getAttribute('aria-expanded') === 'true';
|
||||||
const hasActiveState = this.choices.dropdown.element.classList.contains(this.choices.config.classNames.activeState);
|
const hasActiveState = this.choices.dropdown.element.classList.contains(
|
||||||
|
this.choices.config.classNames.activeState,
|
||||||
|
);
|
||||||
expect(hasOpenState && hasAttr && hasActiveState).toBe(true);
|
expect(hasOpenState && hasAttr && hasActiveState).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle hideDropdown()', function() {
|
it('should handle hideDropdown()', function() {
|
||||||
this.choices.showDropdown();
|
this.choices.showDropdown();
|
||||||
this.choices.hideDropdown();
|
this.choices.hideDropdown();
|
||||||
const hasOpenState = this.choices.containerOuter.element.classList.contains(this.choices.config.classNames.openState);
|
const hasOpenState = this.choices.containerOuter.element.classList.contains(
|
||||||
|
this.choices.config.classNames.openState,
|
||||||
|
);
|
||||||
const hasAttr = this.choices.containerOuter.element.getAttribute('aria-expanded') === 'true';
|
const hasAttr = this.choices.containerOuter.element.getAttribute('aria-expanded') === 'true';
|
||||||
const hasActiveState = this.choices.dropdown.element.classList.contains(this.choices.config.classNames.activeState);
|
const hasActiveState = this.choices.dropdown.element.classList.contains(
|
||||||
|
this.choices.config.classNames.activeState,
|
||||||
|
);
|
||||||
|
|
||||||
expect(hasOpenState && hasAttr && hasActiveState).toBe(false);
|
expect(hasOpenState && hasAttr && hasActiveState).toBe(false);
|
||||||
});
|
});
|
||||||
|
@ -767,7 +786,9 @@ describe('Choices', () => {
|
||||||
|
|
||||||
it('should handle hideDropdown()', function() {
|
it('should handle hideDropdown()', function() {
|
||||||
this.choices.showDropdown();
|
this.choices.showDropdown();
|
||||||
expect(this.choices.containerOuter.element.classList).toContain(this.choices.config.classNames.openState);
|
expect(
|
||||||
|
this.choices.containerOuter.element.classList,
|
||||||
|
).toContain(this.choices.config.classNames.openState);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle getValue()', function() {
|
it('should handle getValue()', function() {
|
||||||
|
@ -873,7 +894,11 @@ describe('Choices', () => {
|
||||||
this.choices.disable();
|
this.choices.disable();
|
||||||
|
|
||||||
expect(this.choices.input.element.disabled).toBe(true);
|
expect(this.choices.input.element.disabled).toBe(true);
|
||||||
expect(this.choices.containerOuter.element.classList.contains(this.choices.config.classNames.disabledState)).toBe(true);
|
expect(
|
||||||
|
this.choices.containerOuter.element.classList.contains(
|
||||||
|
this.choices.config.classNames.disabledState
|
||||||
|
),
|
||||||
|
).toBe(true);
|
||||||
expect(this.choices.containerOuter.element.getAttribute('aria-disabled')).toBe('true');
|
expect(this.choices.containerOuter.element.getAttribute('aria-disabled')).toBe('true');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -881,7 +906,11 @@ describe('Choices', () => {
|
||||||
this.choices.enable();
|
this.choices.enable();
|
||||||
|
|
||||||
expect(this.choices.input.element.disabled).toBe(false);
|
expect(this.choices.input.element.disabled).toBe(false);
|
||||||
expect(this.choices.containerOuter.element.classList.contains(this.choices.config.classNames.disabledState)).toBe(false);
|
expect(
|
||||||
|
this.choices.containerOuter.element.classList.contains(
|
||||||
|
this.choices.config.classNames.disabledState,
|
||||||
|
),
|
||||||
|
).toBe(false);
|
||||||
expect(this.choices.containerOuter.element.hasAttribute('aria-disabled')).toBe(false);
|
expect(this.choices.containerOuter.element.hasAttribute('aria-disabled')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue