choices.js
Advanced tools
Comparing version 6.0.3 to 7.0.0
{ | ||
"name": "choices.js", | ||
"version": "6.0.3", | ||
"version": "7.0.0", | ||
"description": "A vanilla JS customisable text input/select box plugin", | ||
@@ -100,3 +100,2 @@ "main": "./public/assets/scripts/choices.min.js", | ||
"classnames": "^2.2.6", | ||
"custom-event-polyfill": "^0.3.0", | ||
"deepmerge": "^2.2.1", | ||
@@ -103,0 +102,0 @@ "fuse.js": "3.4.2", |
@@ -37,7 +37,7 @@ # Choices.js ![Build Status](https://travis-ci.org/jshjohnson/Choices.svg?branch=master) [![](https://data.jsdelivr.com/v1/package/npm/choices.js/badge?style=rounded)](https://www.jsdelivr.com/package/npm/choices.js) [![npm](https://img.shields.io/npm/v/choices.js.svg)](https://www.npmjs.com/package/choices.js) [![codebeat badge](https://codebeat.co/badges/55120150-5866-42d8-8010-6aaaff5d3fa1)](https://codebeat.co/projects/github-com-jshjohnson-choices-master) | ||
<!-- Include base CSS (optional) --> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/choices.js@4/public/assets/styles/base.min.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/choices.js/public/assets/styles/base.min.css"> | ||
<!-- Include Choices CSS --> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/choices.js@4/public/assets/styles/choices.min.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/choices.js/public/assets/styles/choices.min.css"> | ||
<!-- Include Choices JavaScript --> | ||
<script src="https://cdn.jsdelivr.net/npm/choices.js@4/public/assets/scripts/choices.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/choices.js/public/assets/scripts/choices.min.js"></script> | ||
``` | ||
@@ -751,3 +751,3 @@ | ||
**Usage:** Set choices of select input via an array of objects, a value name and a label name. This behaves the same as passing items via the `choices` option but can be called after initialising Choices. This can also be used to add groups of choices (see example 2); Optionally pass a true `replaceChoices` value to remove any existing choices. Optionally pass a `customProperties` object to add additional data to your choices (useful when searching/filtering etc). | ||
**Usage:** Set choices of select input via an array of objects, a value name and a label name. This behaves the same as passing items via the `choices` option but can be called after initialising Choices. This can also be used to add groups of choices (see example 2); Optionally pass a true `replaceChoices` value to remove any existing choices. Optionally pass a `customProperties` object to add additional data to your choices (useful when searching/filtering etc). Passing an empty array as the first parameter, and a true `replaceChoices` is the same as calling `clearChoices` (see below). | ||
@@ -796,2 +796,7 @@ **Example 1:** | ||
### clearChoices(); | ||
**Input types affected:** `select-one`, `select-multiple` | ||
**Usage:** Clear all choices from select | ||
### getValue(valueOnly) | ||
@@ -921,3 +926,3 @@ **Input types affected:** `text`, `select-one`, `select-multiple` | ||
```html | ||
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=es5,fetch,Element.prototype.classList,requestAnimationFrame,Node.insertBefore,Node.firstChild"></script> | ||
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=es5,fetch,Element.prototype.classList,requestAnimationFrame,Node.insertBefore,Node.firstChild,CustomEvent"></script> | ||
``` | ||
@@ -938,2 +943,3 @@ | ||
* window.requestAnimationFrame | ||
* CustomEvent | ||
@@ -940,0 +946,0 @@ ## Development |
import Fuse from 'fuse.js'; | ||
import merge from 'deepmerge'; | ||
import './lib/polyfills'; | ||
import Store from './store/store'; | ||
@@ -414,3 +413,3 @@ import { | ||
setChoices(choices = [], value = '', label = '', replaceChoices = false) { | ||
if (!this._isSelectElement || !choices.length || !value) { | ||
if (!this._isSelectElement || !value) { | ||
return this; | ||
@@ -421,3 +420,3 @@ } | ||
if (replaceChoices) { | ||
this._clearChoices(); | ||
this.clearChoices(); | ||
} | ||
@@ -453,2 +452,6 @@ | ||
clearChoices() { | ||
this._store.dispatch(clearChoices()); | ||
} | ||
clearStore() { | ||
@@ -1392,3 +1395,3 @@ this._store.dispatch(clearAll()); | ||
// If we have our mouse down on the scrollbar and are on IE11... | ||
if (target === this.choiceList && isIE11()) { | ||
if (this.choiceList.element.contains(target) && isIE11()) { | ||
this._isScrollingOnIe = true; | ||
@@ -1736,6 +1739,2 @@ } | ||
_clearChoices() { | ||
this._store.dispatch(clearChoices()); | ||
} | ||
_addGroup({ group, id, valueKey = 'value', labelKey = 'label' }) { | ||
@@ -1742,0 +1741,0 @@ const groupChoices = isType('Object', group) |
@@ -1342,3 +1342,3 @@ import { expect } from 'chai'; | ||
instance._clearChoices = clearChoicesStub; | ||
instance.clearChoices = clearChoicesStub; | ||
instance._addGroup = addGroupStub; | ||
@@ -1350,3 +1350,3 @@ instance._addChoice = addChoiceStub; | ||
afterEach(() => { | ||
instance._clearChoices.reset(); | ||
instance.clearChoices.reset(); | ||
instance._addGroup.reset(); | ||
@@ -1375,11 +1375,2 @@ instance._addChoice.reset(); | ||
describe('passing invalid arguments', () => { | ||
describe('passing an empty array', () => { | ||
beforeEach(() => { | ||
instance._isSelectElement = true; | ||
instance.setChoices([], value, label, false); | ||
}); | ||
returnsEarly(); | ||
}); | ||
describe('passing no value', () => { | ||
@@ -1435,2 +1426,18 @@ beforeEach(() => { | ||
describe('passing an empty array with a true replaceChoices flag', () => { | ||
it('choices are cleared', () => { | ||
instance._isSelectElement = true; | ||
instance.setChoices([], value, label, true); | ||
expect(clearChoicesStub.called).to.equal(true); | ||
}); | ||
}); | ||
describe('passing an empty array with a false replaceChoices flag', () => { | ||
it('choices stay the same', () => { | ||
instance._isSelectElement = true; | ||
instance.setChoices([], value, label, false); | ||
expect(clearChoicesStub.called).to.equal(false); | ||
}); | ||
}); | ||
describe('passing true replaceChoices flag', () => { | ||
@@ -1437,0 +1444,0 @@ it('choices are cleared', () => { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
4
968
654934
59
15186
- Removedcustom-event-polyfill@^0.3.0
- Removedcustom-event-polyfill@0.3.0(transitive)