mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-17 21:16:34 +02:00
before: addItems was basically just an alias for disable, now: addItems controls if user can add choices/items
This commit is contained in:
parent
cf34edd0ad
commit
36a5a0bd67
|
@ -304,10 +304,28 @@ describe('Choices - text element', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('adding items disabled', () => {
|
describe('adding items disabled', () => {
|
||||||
it('does not allow me to input data', () => {
|
/*
|
||||||
cy.get('[data-test-hook=adding-items-disabled]')
|
{
|
||||||
|
addItems: false,
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.get('[data-test-hook=add-items-disabled]')
|
||||||
|
.find('.choices')
|
||||||
|
.click();
|
||||||
|
});
|
||||||
|
it('disables adding new items', () => {
|
||||||
|
const newChoice = 'New Choice';
|
||||||
|
cy.get('[data-test-hook=add-items-disabled]')
|
||||||
.find('.choices__input--cloned')
|
.find('.choices__input--cloned')
|
||||||
.should('be.disabled');
|
.type(newChoice)
|
||||||
|
.type('{enter}');
|
||||||
|
cy.get('[data-test-hook=add-items-disabled]')
|
||||||
|
.find('.choices__list--multiple')
|
||||||
|
.last()
|
||||||
|
.should($el => {
|
||||||
|
expect($el).to.not.contain(newChoice);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -105,11 +105,11 @@
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div data-test-hook="adding-items-disabled">
|
<div data-test-hook="add-items-disabled">
|
||||||
<label for="choices-adding-items-disabled">Add items disabled</label>
|
<label for="choices-add-items-disabled">Add items disabled</label>
|
||||||
<input
|
<input
|
||||||
class="form-control"
|
class="form-control"
|
||||||
id="choices-adding-items-disabled"
|
id="choices-add-items-disabled"
|
||||||
type="text"
|
type="text"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -347,10 +347,7 @@ class Choices implements Choices {
|
||||||
this._render();
|
this._render();
|
||||||
this._addEventListeners();
|
this._addEventListeners();
|
||||||
|
|
||||||
let shouldDisable = this.passedElement.element.hasAttribute('disabled');
|
const shouldDisable = this.passedElement.element.hasAttribute('disabled');
|
||||||
if (this._isTextElement) {
|
|
||||||
shouldDisable = shouldDisable || !this.config.addItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldDisable) {
|
if (shouldDisable) {
|
||||||
this.disable();
|
this.disable();
|
||||||
|
@ -1562,7 +1559,8 @@ class Choices implements Choices {
|
||||||
// We are typing into a text input and have a value, we want to show a dropdown
|
// We are typing into a text input and have a value, we want to show a dropdown
|
||||||
// notice. Otherwise hide the dropdown
|
// notice. Otherwise hide the dropdown
|
||||||
if (this._isTextElement) {
|
if (this._isTextElement) {
|
||||||
const canShowDropdownNotice = canAddItem.notice && value;
|
const canShowDropdownNotice =
|
||||||
|
this.config.addItems && canAddItem.notice && value;
|
||||||
|
|
||||||
if (canShowDropdownNotice) {
|
if (canShowDropdownNotice) {
|
||||||
const dropdownItem = this._getTemplate('notice', canAddItem.notice);
|
const dropdownItem = this._getTemplate('notice', canAddItem.notice);
|
||||||
|
|
|
@ -103,7 +103,7 @@ export interface Options {
|
||||||
maxItemCount: number;
|
maxItemCount: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether a user can add items.
|
* Whether a user can add new items.
|
||||||
*
|
*
|
||||||
* **Input types affected:** text, select, select-multiple
|
* **Input types affected:** text, select, select-multiple
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue