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._prevState = {};
this._currentValue = ''; this._currentValue = '';
this._canSearch = this.config.searchEnabled; this._canSearch = this.config.searchEnabled;
this._isDisabled = this.config.addItems;
this._isScrollingOnIe = false; this._isScrollingOnIe = false;
this._highlightPosition = 0; this._highlightPosition = 0;
this._wasTap = true; this._wasTap = true;
@ -214,7 +215,7 @@ class Choices {
} }
enable() { enable() {
if (!this.initialised) { if (!this._isDisabled) {
return this; return this;
} }
@ -226,11 +227,13 @@ class Choices {
this.containerOuter.enable(); this.containerOuter.enable();
} }
this._isDisabled = false;
return this; return this;
} }
disable() { disable() {
if (!this.initialised) { if (this._isDisabled) {
return this; return this;
} }
@ -242,6 +245,8 @@ class Choices {
this.containerOuter.disable(); this.containerOuter.disable();
} }
this._isDisabled = true;
return this; return this;
} }

View file

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