diff --git a/src/scripts/choices.js b/src/scripts/choices.js index 6c2e291..c1fbc32 100644 --- a/src/scripts/choices.js +++ b/src/scripts/choices.js @@ -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; } diff --git a/src/scripts/choices.test.js b/src/scripts/choices.test.js index 800e83d..a86bdca 100644 --- a/src/scripts/choices.test.js +++ b/src/scripts/choices.test.js @@ -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(); });