Do not open dropdown if element is disabled

This commit is contained in:
Josh Johnson 2018-10-30 20:28:40 +00:00
parent 798b49d565
commit b0f3b28ef4
3 changed files with 7 additions and 49 deletions

View file

@ -292,31 +292,10 @@ describe('Choices - select multiple', () => {
});
describe('on click', () => {
it('opens choice dropdown', () => {
it('does not open choice dropdown', () => {
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices__list--dropdown')
.should('be.visible');
});
});
describe('attempting to select choice', () => {
let selectedChoice;
it('does not select choice', () => {
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices__list--dropdown .choices__item')
.last()
.then($lastChoice => {
selectedChoice = $lastChoice;
})
.click();
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices__list--multiple .choices__item')
.last()
.should($item => {
expect($item.text()).to.not.contain(selectedChoice.text());
});
.should('not.be.visible');
});
});
});
@ -335,31 +314,10 @@ describe('Choices - select multiple', () => {
});
describe('on click', () => {
it('opens choice dropdown', () => {
it('does not opens choice dropdown', () => {
cy.get('[data-test-hook=disabled-via-attr]')
.find('.choices__list--dropdown')
.should('be.visible');
});
});
describe('attempting to select choice', () => {
let selectedChoice;
it('does not select choice', () => {
cy.get('[data-test-hook=disabled-via-attr]')
.find('.choices__list--dropdown .choices__item')
.last()
.then($lastChoice => {
selectedChoice = $lastChoice;
})
.click();
cy.get('[data-test-hook=disabled-via-attr]')
.find('.choices__list--multiple .choices__item')
.last()
.should($item => {
expect($item.text()).to.not.contain(selectedChoice.text());
});
.should('not.be.visible');
});
});
});

View file

@ -240,10 +240,10 @@ describe('Choices - select one', () => {
});
describe('on click', () => {
it('opens choice dropdown', () => {
it('does not open choice dropdown', () => {
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices__list--dropdown')
.should('be.visible');
.should('not.be.visible');
});
});

View file

@ -1406,7 +1406,7 @@ class Choices {
_onClick({ target }) {
if (this.containerOuter.element.contains(target)) {
if (!this.dropdown.isActive) {
if (!this.dropdown.isActive && !this.containerOuter.isDisabled) {
if (this._isTextElement) {
if (document.activeElement !== this.input.element) {
this.input.focus();