mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-11 10:06:35 +02:00
Update readme to document multiple instances
This commit is contained in:
parent
315b2f8f36
commit
013058dd7f
|
@ -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);
|
||||
|
|
|
@ -55,10 +55,12 @@ describe('Choices - text element', () => {
|
|||
|
||||
describe('editing items', () => {
|
||||
beforeEach(() => {
|
||||
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', () => {
|
||||
|
|
Loading…
Reference in a new issue