Disable input when loading remote data

This commit is contained in:
Josh Johnson 2018-11-03 13:24:52 +00:00
parent 307881a068
commit 496db95153
3 changed files with 14 additions and 16 deletions

View file

@ -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');
});
});
});

View file

@ -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');
});
});
});

View file

@ -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) {