mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-02 14:02:17 +02:00
Minor fixes
This commit is contained in:
parent
e79aeaa93e
commit
d48fdf4e02
|
@ -1750,6 +1750,7 @@ class Choices {
|
||||||
this.showDropdown(true);
|
this.showDropdown(true);
|
||||||
} else {
|
} else {
|
||||||
this.showDropdown();
|
this.showDropdown();
|
||||||
|
// code smell
|
||||||
this.containerOuter.focus();
|
this.containerOuter.focus();
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
|
@ -1783,10 +1784,12 @@ class Choices {
|
||||||
*/
|
*/
|
||||||
_onMouseOver(e) {
|
_onMouseOver(e) {
|
||||||
// If the dropdown is either the target or one of its children is the target
|
// If the dropdown is either the target or one of its children is the target
|
||||||
if (
|
const targetWithinDropdown = (
|
||||||
(e.target === this.dropdown || this.dropdown.element.contains(e.target)) &&
|
e.target === this.dropdown || this.dropdown.element.contains(e.target)
|
||||||
e.target.hasAttribute('data-choice')
|
);
|
||||||
) {
|
const shouldHighlightChoice = targetWithinDropdown && e.target.hasAttribute('data-choice');
|
||||||
|
|
||||||
|
if (shouldHighlightChoice) {
|
||||||
this._highlightChoice(e.target);
|
this._highlightChoice(e.target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,12 @@
|
||||||
|
/* eslint-disable no-unused-expressions */
|
||||||
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 'custom-event-autopolyfill';
|
import 'custom-event-autopolyfill';
|
||||||
import { expect } from 'chai';
|
import { expect, assert } from 'chai';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
|
|
||||||
import Choices from './choices';
|
import Choices from './choices';
|
||||||
import itemReducer from './reducers/items';
|
|
||||||
import choiceReducer from './reducers/choices';
|
|
||||||
import {
|
|
||||||
addItem as addItemAction,
|
|
||||||
} from './actions/items';
|
|
||||||
import {
|
|
||||||
addChoice as addChoiceAction,
|
|
||||||
} from './actions/choices';
|
|
||||||
import Dropdown from './components/dropdown';
|
import Dropdown from './components/dropdown';
|
||||||
import Container from './components/container';
|
import Container from './components/container';
|
||||||
import Input from './components/input';
|
import Input from './components/input';
|
||||||
|
@ -38,7 +31,7 @@ describe('Choices', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be defined', () => {
|
it('should be defined', () => {
|
||||||
expect(instance).not.be.undefined;
|
expect(instance).to.not.be.undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have initialised', () => {
|
it('should have initialised', () => {
|
||||||
|
@ -74,7 +67,8 @@ describe('Choices', () => {
|
||||||
expect(instance.config.searchChoices).to.be.a('boolean');
|
expect(instance.config.searchChoices).to.be.a('boolean');
|
||||||
expect(instance.config.searchFloor).to.be.a('number');
|
expect(instance.config.searchFloor).to.be.a('number');
|
||||||
expect(instance.config.searchResultLimit).to.be.a('number');
|
expect(instance.config.searchResultLimit).to.be.a('number');
|
||||||
// expect(instance.config.searchFields).to.equal(jasmine.any(Array) || jasmine.any(String));
|
expect(instance.config.searchFields, 'should be string or array').to.satisfy(searchFields =>
|
||||||
|
Array.isArray(searchFields) || typeof searchFields === 'string');
|
||||||
expect(instance.config.position).to.be.a('string');
|
expect(instance.config.position).to.be.a('string');
|
||||||
expect(instance.config.regexFilter).to.be.null;
|
expect(instance.config.regexFilter).to.be.null;
|
||||||
expect(instance.config.sortFilter).to.be.a('function');
|
expect(instance.config.sortFilter).to.be.a('function');
|
||||||
|
@ -835,7 +829,11 @@ describe('Choices', () => {
|
||||||
instance.disable();
|
instance.disable();
|
||||||
|
|
||||||
expect(instance.input.element.disabled).to.be.true;
|
expect(instance.input.element.disabled).to.be.true;
|
||||||
expect(instance.containerOuter.element.classList.contains(instance.config.classNames.disabledState)).to.be.true;
|
expect(
|
||||||
|
instance.containerOuter.element.classList.contains(
|
||||||
|
instance.config.classNames.disabledState,
|
||||||
|
),
|
||||||
|
).to.be.true;
|
||||||
expect(instance.containerOuter.element.getAttribute('aria-disabled')).to.equal('true');
|
expect(instance.containerOuter.element.getAttribute('aria-disabled')).to.equal('true');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -843,7 +841,11 @@ describe('Choices', () => {
|
||||||
instance.enable();
|
instance.enable();
|
||||||
|
|
||||||
expect(instance.input.element.disabled).to.be.false;
|
expect(instance.input.element.disabled).to.be.false;
|
||||||
expect(instance.containerOuter.element.classList.contains(instance.config.classNames.disabledState)).to.be.false;
|
expect(
|
||||||
|
instance.containerOuter.element.classList.contains(
|
||||||
|
instance.config.classNames.disabledState,
|
||||||
|
),
|
||||||
|
).to.be.false;
|
||||||
expect(instance.containerOuter.element.hasAttribute('aria-disabled')).to.be.false;
|
expect(instance.containerOuter.element.hasAttribute('aria-disabled')).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1038,94 +1040,6 @@ describe('Choices', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should allow custom properties provided by the user on items or choices', () => {
|
|
||||||
it('should allow the user to supply custom properties for an item', () => {
|
|
||||||
const randomItem = {
|
|
||||||
id: 8999,
|
|
||||||
choiceId: 9000,
|
|
||||||
groupId: 9001,
|
|
||||||
value: 'value',
|
|
||||||
label: 'label',
|
|
||||||
customProperties: {
|
|
||||||
foo: 'bar',
|
|
||||||
},
|
|
||||||
placeholder: false,
|
|
||||||
keyCode: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
const expectedState = [{
|
|
||||||
id: randomItem.id,
|
|
||||||
choiceId: randomItem.choiceId,
|
|
||||||
groupId: randomItem.groupId,
|
|
||||||
value: randomItem.value,
|
|
||||||
label: randomItem.label,
|
|
||||||
active: true,
|
|
||||||
highlighted: false,
|
|
||||||
customProperties: randomItem.customProperties,
|
|
||||||
placeholder: randomItem.placeholder,
|
|
||||||
keyCode: randomItem.keyCode,
|
|
||||||
}];
|
|
||||||
|
|
||||||
const action = addItemAction(
|
|
||||||
randomItem.value,
|
|
||||||
randomItem.label,
|
|
||||||
randomItem.id,
|
|
||||||
randomItem.choiceId,
|
|
||||||
randomItem.groupId,
|
|
||||||
randomItem.customProperties,
|
|
||||||
randomItem.placeholder,
|
|
||||||
randomItem.keyCode,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(itemReducer([], action)).to.deep.equal(expectedState);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should allow the user to supply custom properties for a choice', () => {
|
|
||||||
const randomChoice = {
|
|
||||||
id: 123,
|
|
||||||
elementId: 321,
|
|
||||||
groupId: 213,
|
|
||||||
value: 'value',
|
|
||||||
label: 'label',
|
|
||||||
disabled: false,
|
|
||||||
customProperties: {
|
|
||||||
foo: 'bar',
|
|
||||||
},
|
|
||||||
placeholder: false,
|
|
||||||
keyCode: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
const expectedState = [{
|
|
||||||
id: randomChoice.id,
|
|
||||||
elementId: randomChoice.elementId,
|
|
||||||
groupId: randomChoice.groupId,
|
|
||||||
value: randomChoice.value,
|
|
||||||
label: randomChoice.label,
|
|
||||||
disabled: randomChoice.disabled,
|
|
||||||
selected: false,
|
|
||||||
active: true,
|
|
||||||
score: 9999,
|
|
||||||
customProperties: randomChoice.customProperties,
|
|
||||||
placeholder: randomChoice.placeholder,
|
|
||||||
keyCode: randomChoice.keyCode,
|
|
||||||
}];
|
|
||||||
|
|
||||||
const action = addChoiceAction(
|
|
||||||
randomChoice.value,
|
|
||||||
randomChoice.label,
|
|
||||||
randomChoice.id,
|
|
||||||
randomChoice.groupId,
|
|
||||||
randomChoice.disabled,
|
|
||||||
randomChoice.elementId,
|
|
||||||
randomChoice.customProperties,
|
|
||||||
randomChoice.placeholder,
|
|
||||||
randomChoice.keyCode,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(choiceReducer([], action)).to.deep.equal(expectedState);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('should allow custom properties provided by the user on items or choices', () => {
|
describe('should allow custom properties provided by the user on items or choices', () => {
|
||||||
let input;
|
let input;
|
||||||
let instance;
|
let instance;
|
||||||
|
|
Loading…
Reference in a new issue