Update readme to document multiple instances

This commit is contained in:
Josh Johnson 2018-10-27 20:03:53 +01:00
parent 315b2f8f36
commit 013058dd7f
2 changed files with 40 additions and 5 deletions

View file

@ -51,9 +51,12 @@ Or include Choices directly:
```
## Setup
If you pass a selector which targets multiple elements, an array of Choices instances
will be returned. If you target one element, that instance will be returned.
```js
// Pass multiple elements:
const choices = new Choices(elements);
const [firstInstance, secondInstance] = new Choices(elements);
// Pass single element:
const choices = new Choices(element);

View file

@ -55,10 +55,12 @@ describe('Choices - text element', () => {
describe('editing items', () => {
beforeEach(() => {
cy.get('[data-test-hook=edit-items]')
.find('.choices__input--cloned')
.type(textInput)
.type('{enter}');
for (let index = 0; index < 3; index++) {
cy.get('[data-test-hook=edit-items]')
.find('.choices__input--cloned')
.type(textInput)
.type('{enter}');
}
});
describe('on back space', () => {
@ -77,6 +79,36 @@ describe('Choices - text element', () => {
});
});
});
describe('on cmd+a', () => {
beforeEach(() => {
cy.get('[data-test-hook=edit-items]')
.find('.choices__input--cloned')
.type('{cmd}a');
});
it('highlights all items', () => {
cy.get('[data-test-hook=edit-items]')
.find('.choices__list--multiple .choices__item')
.each($choice => {
expect($choice.hasClass('is-highlighted')).to.equal(true);
});
});
describe('on backspace', () => {
it('clears all inputted values', () => {
// two backspaces are needed as Cypress has an issue where
// it will also insert an 'a' character into the text input
cy.get('[data-test-hook=edit-items]')
.find('.choices__input--cloned')
.type('{backspace}{backspace}');
cy.get('[data-test-hook=edit-items]')
.find('.choices__list--multiple .choices__item')
.should('have.length', 0);
});
});
});
});
describe('remove button', () => {