Resolve an issue with disabling/enabling instances

This commit is contained in:
Josh Johnson 2018-10-21 19:26:08 +01:00
parent 620bfeae0d
commit 4193422cf6
2 changed files with 17 additions and 12 deletions

View file

@ -118,6 +118,7 @@ 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;
@ -214,7 +215,7 @@ class Choices {
}
enable() {
if (!this.initialised) {
if (!this._isDisabled) {
return this;
}
@ -226,11 +227,13 @@ class Choices {
this.containerOuter.enable();
}
this._isDisabled = false;
return this;
}
disable() {
if (!this.initialised) {
if (this._isDisabled) {
return this;
}
@ -242,6 +245,8 @@ class Choices {
this.containerOuter.disable();
}
this._isDisabled = true;
return this;
}

View file

@ -200,9 +200,9 @@ describe('choices', () => {
inputEnableSpy.restore();
});
describe('not already initialised', () => {
describe('when already enabled', () => {
beforeEach(() => {
instance.initialised = false;
instance._isDisabled = false;
output = instance.enable();
});
@ -216,10 +216,10 @@ describe('choices', () => {
});
});
describe('when already initialised', () => {
describe('when not already enabled', () => {
describe('containerOuter enabled', () => {
beforeEach(() => {
instance.initialised = true;
instance._isDisabled = true;
output = instance.enable();
});
@ -232,7 +232,7 @@ describe('choices', () => {
describe('containerOuter disabled', () => {
beforeEach(() => {
instance.initialised = true;
instance._isDisabled = true;
instance.containerOuter.isDisabled = true;
instance.enable();
});
@ -272,9 +272,9 @@ describe('choices', () => {
inputDisableSpy.restore();
});
describe('not already initialised', () => {
describe('when already disabled', () => {
beforeEach(() => {
instance.initialised = false;
instance._isDisabled = true;
output = instance.disable();
});
@ -288,10 +288,10 @@ describe('choices', () => {
});
});
describe('when already initialised', () => {
describe('when not already disabled', () => {
describe('containerOuter disabled', () => {
beforeEach(() => {
instance.initialised = true;
instance._isDisabled = false;
instance.containerOuter.isDisabled = true;
output = instance.disable();
});
@ -305,7 +305,7 @@ describe('choices', () => {
describe('containerOuter enabled', () => {
beforeEach(() => {
instance.initialised = true;
instance._isDisabled = false;
instance.containerOuter.isDisabled = false;
instance.disable();
});