From 496db95153fe88585b7b454d41315fac867a9be4 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Sat, 3 Nov 2018 13:24:52 +0000 Subject: [PATCH] Disable input when loading remote data --- cypress/integration/select-multiple.spec.js | 13 +++++-------- cypress/integration/select-one.spec.js | 13 +++++-------- src/scripts/choices.js | 4 ++++ 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/cypress/integration/select-multiple.spec.js b/cypress/integration/select-multiple.spec.js index 0dc8061..606abaa 100644 --- a/cypress/integration/select-multiple.spec.js +++ b/cypress/integration/select-multiple.spec.js @@ -520,16 +520,13 @@ describe('Choices - select multiple', () => { .should('have.attr', 'placeholder', 'Loading...'); }); - describe('opening the dropdown', () => { - it('displays "no choices to choose" prompt', () => { - cy.get('[data-test-hook=remote-data]').click(); + describe('on click', () => { + it('does not opens choice dropdown', () => { cy.get('[data-test-hook=remote-data]') + .find('.choices') + .click() .find('.choices__list--dropdown') - .should('be.visible') - .should($dropdown => { - const dropdownText = $dropdown.text().trim(); - expect(dropdownText).to.equal('No choices to choose from'); - }); + .should('not.have.class', 'is-active'); }); }); }); diff --git a/cypress/integration/select-one.spec.js b/cypress/integration/select-one.spec.js index 6d7e2cd..042f071 100644 --- a/cypress/integration/select-one.spec.js +++ b/cypress/integration/select-one.spec.js @@ -471,16 +471,13 @@ describe('Choices - select one', () => { }); }); - describe('opening the dropdown', () => { - it('displays "no choices to choose" prompt', () => { - cy.get('[data-test-hook=remote-data]').click(); + describe('on click', () => { + it('does not opens choice dropdown', () => { cy.get('[data-test-hook=remote-data]') + .find('.choices') + .click() .find('.choices__list--dropdown') - .should('be.visible') - .should($dropdown => { - const dropdownText = $dropdown.text().trim(); - expect(dropdownText).to.equal('No choices to choose from'); - }); + .should('not.have.class', 'is-active'); }); }); }); diff --git a/src/scripts/choices.js b/src/scripts/choices.js index 03f1c11..3955777 100644 --- a/src/scripts/choices.js +++ b/src/scripts/choices.js @@ -874,8 +874,11 @@ class Choices { let placeholderItem = this.itemList.getChild( `.${this.config.classNames.placeholder}`, ); + if (isLoading) { + this.disable(); this.containerOuter.addLoadingState(); + if (this._isSelectOneElement) { if (!placeholderItem) { placeholderItem = this._getTemplate( @@ -890,6 +893,7 @@ class Choices { this.input.placeholder = this.config.loadingText; } } else { + this.enable(); this.containerOuter.removeLoadingState(); if (this._isSelectOneElement) {