mirror of
https://github.com/Choices-js/Choices.git
synced 2024-04-27 19:42:51 +02:00
Resolve issue with disable/enable methods
This commit is contained in:
parent
013058dd7f
commit
de71fb7ef4
|
@ -12,7 +12,7 @@
|
|||
"cypress:run": "$(npm bin)/cypress run",
|
||||
"cypress:open": "$(npm bin)/cypress open",
|
||||
"test:unit": "mocha --require ./config/test.js --compilers js:babel-core/register \"./src/**/**/**/**/*.test.js\" --exit",
|
||||
"test:unit:watch": "npm run test -- --watch --inspect=5556",
|
||||
"test:unit:watch": "npm run test:unit -- --watch --inspect=5556",
|
||||
"test:e2e": "run-p --race start cypress:run",
|
||||
"test": "run-p test:unit test:e2e",
|
||||
"js:watch": "NODE_ENV=development node server.js",
|
||||
|
|
|
@ -118,7 +118,6 @@ class Choices {
|
|||
this._prevState = {};
|
||||
this._currentValue = '';
|
||||
this._canSearch = this.config.searchEnabled;
|
||||
this._isDisabled = this.config.addItems;
|
||||
this._isScrollingOnIe = false;
|
||||
this._highlightPosition = 0;
|
||||
this._wasTap = true;
|
||||
|
@ -215,38 +214,30 @@ class Choices {
|
|||
}
|
||||
|
||||
enable() {
|
||||
if (!this._isDisabled) {
|
||||
return this;
|
||||
if (this.passedElement.isDisabled) {
|
||||
this.passedElement.enable();
|
||||
}
|
||||
|
||||
this.passedElement.enable();
|
||||
|
||||
if (this.containerOuter.isDisabled) {
|
||||
this._addEventListeners();
|
||||
this.input.enable();
|
||||
this.containerOuter.enable();
|
||||
}
|
||||
|
||||
this._isDisabled = false;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
disable() {
|
||||
if (this._isDisabled) {
|
||||
return this;
|
||||
if (!this.passedElement.isDisabled) {
|
||||
this.passedElement.disable();
|
||||
}
|
||||
|
||||
this.passedElement.disable();
|
||||
|
||||
if (!this.containerOuter.isDisabled) {
|
||||
this._removeEventListeners();
|
||||
this.input.disable();
|
||||
this.containerOuter.disable();
|
||||
}
|
||||
|
||||
this._isDisabled = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -202,7 +202,8 @@ describe('choices', () => {
|
|||
|
||||
describe('when already enabled', () => {
|
||||
beforeEach(() => {
|
||||
instance._isDisabled = false;
|
||||
instance.passedElement.isDisabled = false;
|
||||
instance.containerOuter.isDisabled = false;
|
||||
output = instance.enable();
|
||||
});
|
||||
|
||||
|
@ -217,37 +218,22 @@ describe('choices', () => {
|
|||
});
|
||||
|
||||
describe('when not already enabled', () => {
|
||||
describe('containerOuter enabled', () => {
|
||||
beforeEach(() => {
|
||||
instance._isDisabled = true;
|
||||
output = instance.enable();
|
||||
});
|
||||
|
||||
returnsInstance(output);
|
||||
|
||||
it('enables passedElement', () => {
|
||||
expect(passedElementEnableSpy.called).to.equal(true);
|
||||
});
|
||||
beforeEach(() => {
|
||||
instance.passedElement.isDisabled = true;
|
||||
instance.containerOuter.isDisabled = true;
|
||||
instance.enable();
|
||||
});
|
||||
|
||||
describe('containerOuter disabled', () => {
|
||||
beforeEach(() => {
|
||||
instance._isDisabled = true;
|
||||
instance.containerOuter.isDisabled = true;
|
||||
instance.enable();
|
||||
});
|
||||
it('adds event listeners', () => {
|
||||
expect(addEventListenersSpy.called).to.equal(true);
|
||||
});
|
||||
|
||||
it('adds event listeners', () => {
|
||||
expect(addEventListenersSpy.called).to.equal(true);
|
||||
});
|
||||
it('enables input', () => {
|
||||
expect(inputEnableSpy.called).to.equal(true);
|
||||
});
|
||||
|
||||
it('enables input', () => {
|
||||
expect(inputEnableSpy.called).to.equal(true);
|
||||
});
|
||||
|
||||
it('enables containerOuter', () => {
|
||||
expect(containerOuterEnableSpy.called).to.equal(true);
|
||||
});
|
||||
it('enables containerOuter', () => {
|
||||
expect(containerOuterEnableSpy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -274,7 +260,8 @@ describe('choices', () => {
|
|||
|
||||
describe('when already disabled', () => {
|
||||
beforeEach(() => {
|
||||
instance._isDisabled = true;
|
||||
instance.passedElement.isDisabled = true;
|
||||
instance.containerOuter.isDisabled = true;
|
||||
output = instance.disable();
|
||||
});
|
||||
|
||||
|
@ -289,38 +276,22 @@ describe('choices', () => {
|
|||
});
|
||||
|
||||
describe('when not already disabled', () => {
|
||||
describe('containerOuter disabled', () => {
|
||||
beforeEach(() => {
|
||||
instance._isDisabled = false;
|
||||
instance.containerOuter.isDisabled = true;
|
||||
output = instance.disable();
|
||||
});
|
||||
|
||||
returnsInstance(output);
|
||||
|
||||
it('disables passedElement', () => {
|
||||
expect(passedElementDisableSpy.called).to.equal(true);
|
||||
});
|
||||
beforeEach(() => {
|
||||
instance.passedElement.isDisabled = false;
|
||||
instance.containerOuter.isDisabled = false;
|
||||
output = instance.disable();
|
||||
});
|
||||
|
||||
describe('containerOuter enabled', () => {
|
||||
beforeEach(() => {
|
||||
instance._isDisabled = false;
|
||||
instance.containerOuter.isDisabled = false;
|
||||
instance.disable();
|
||||
});
|
||||
it('removes event listeners', () => {
|
||||
expect(removeEventListenersSpy.called).to.equal(true);
|
||||
});
|
||||
|
||||
it('removes event listeners', () => {
|
||||
expect(removeEventListenersSpy.called).to.equal(true);
|
||||
});
|
||||
it('disables input', () => {
|
||||
expect(inputDisableSpy.called).to.equal(true);
|
||||
});
|
||||
|
||||
it('disables input', () => {
|
||||
expect(inputDisableSpy.called).to.equal(true);
|
||||
});
|
||||
|
||||
it('enables containerOuter', () => {
|
||||
expect(containerOuterDisableSpy.called).to.equal(true);
|
||||
});
|
||||
it('enables containerOuter', () => {
|
||||
expect(containerOuterDisableSpy.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue