xMerge branch 'master' of https://github.com/maximmig/Choices into maximmig-master

This commit is contained in:
Josh Johnson 2017-07-13 08:55:05 +01:00
commit 3b350eb71e
6 changed files with 27 additions and 11 deletions

View file

@ -376,11 +376,11 @@ const example = new Choices(element, {
**Usage:** Append a value to each item added/selected.
### renderSelectedChoices
**Type:** `String/Boolean` **Default:** `auto`
**Type:** `String` **Default:** `auto`
**Input types affected:** `select-one`, `select-multiple`
**Usage:** Whether selected choices should be removed from the list. By default choices are only removed when they are selected in multiple select box.
**Usage:** Whether selected choices should be removed from the list. By default choices are removed when they are selected in multiple select box. To always render choices pass `always`.
### loadingText
**Type:** `String` **Default:** `Loading...`

View file

@ -195,9 +195,9 @@ return /******/ (function(modules) { // webpackBootstrap
// Merge options with user options
this.config = (0, _utils.extend)(defaultConfig, userConfig);
if (this.config.renderSelectedChoices !== 'auto' && !(0, _utils.isType)('Boolean', this.config.renderSelectedChoices)) {
if (this.config.renderSelectedChoices !== 'auto' && this.config.renderSelectedChoices !== 'always') {
if (!this.config.silent) {
console.warn('renderSelectedChoices: Possible values are \'auto\', true or false. Falling back to \'auto\'.');
console.warn('renderSelectedChoices: Possible values are \'auto\' and \'always\'. Falling back to \'auto\'.');
}
this.config.renderSelectedChoices = 'auto';
}
@ -436,7 +436,7 @@ return /******/ (function(modules) { // webpackBootstrap
var renderSelectedChoices = this.config.renderSelectedChoices;
var appendChoice = function appendChoice(choice) {
var shouldRender = renderSelectedChoices === 'auto' ? _this3.passedElement.type === 'select-one' || !choice.selected : renderSelectedChoices;
var shouldRender = renderSelectedChoices === 'auto' ? _this3.passedElement.type === 'select-one' || !choice.selected : true;
if (shouldRender) {
var dropdownItem = _this3._getTemplate('choice', choice);
choicesFragment.appendChild(dropdownItem);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -129,9 +129,9 @@ class Choices {
// Merge options with user options
this.config = extend(defaultConfig, userConfig);
if (this.config.renderSelectedChoices !== 'auto' && !isType('Boolean', this.config.renderSelectedChoices)) {
if (this.config.renderSelectedChoices !== 'auto' && this.config.renderSelectedChoices !== 'always') {
if (!this.config.silent) {
console.warn('renderSelectedChoices: Possible values are \'auto\', true or false. Falling back to \'auto\'.');
console.warn('renderSelectedChoices: Possible values are \'auto\' and \'always\'. Falling back to \'auto\'.');
}
this.config.renderSelectedChoices = 'auto';
}
@ -355,7 +355,7 @@ class Choices {
const appendChoice = (choice) => {
const shouldRender = renderSelectedChoices === 'auto'
? this.passedElement.type === 'select-one' || !choice.selected
: renderSelectedChoices;
: true;
if (shouldRender) {
const dropdownItem = this._getTemplate('choice', choice);
choicesFragment.appendChild(dropdownItem);

View file

@ -70,7 +70,7 @@ describe('Choices', () => {
expect(this.choices.config.placeholderValue).toEqual(null);
expect(this.choices.config.prependValue).toEqual(null);
expect(this.choices.config.appendValue).toEqual(null);
expect(this.choices.config.renderSelectedChoices).toEqual(jasmine.any(String) || jasmine.any(Boolean));
expect(this.choices.config.renderSelectedChoices).toEqual(jasmine.any(String));
expect(this.choices.config.loadingText).toEqual(jasmine.any(String));
expect(this.choices.config.noResultsText).toEqual(jasmine.any(String));
expect(this.choices.config.noChoicesText).toEqual(jasmine.any(String));
@ -929,6 +929,22 @@ describe('Choices', () => {
this.choices.input.focus();
expect(container.classList.contains(this.choices.config.classNames.flippedState)).toBe(false);
});
it('should render selected choices', function() {
this.choices = new Choices(this.input, {
renderSelectedChoices: 'always'
});
const renderedChoices = this.choices.choiceList.querySelectorAll('.choices__item');
expect(renderedChoices.length).toEqual(3);
});
it('shouldn\'t render selected choices', function() {
this.choices = new Choices(this.input, {
renderSelectedChoices: 'auto'
});
const renderedChoices = this.choices.choiceList.querySelectorAll('.choices__item');
expect(renderedChoices.length).toEqual(1);
});
});
describe('should allow custom properties provided by the user on items or choices', function() {