mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-17 04:56:34 +02:00
* use template from instance * adjust test * fix lint * try to move `this` out of loop * fixes late init bound
This commit is contained in:
parent
4e8842d013
commit
7de0887e7d
|
@ -101,6 +101,7 @@ class Choices {
|
||||||
this.passedElement = new WrappedSelect({
|
this.passedElement = new WrappedSelect({
|
||||||
element: passedElement,
|
element: passedElement,
|
||||||
classNames: this.config.classNames,
|
classNames: this.config.classNames,
|
||||||
|
template: data => this.config.templates.option(data),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import WrappedElement from './wrapped-element';
|
import WrappedElement from './wrapped-element';
|
||||||
import templates from './../templates';
|
|
||||||
|
|
||||||
export default class WrappedSelect extends WrappedElement {
|
export default class WrappedSelect extends WrappedElement {
|
||||||
constructor({ element, classNames }) {
|
constructor({ element, classNames, template }) {
|
||||||
super({ element, classNames });
|
super({ element, classNames });
|
||||||
|
this.template = template;
|
||||||
}
|
}
|
||||||
|
|
||||||
get placeholderOption() {
|
get placeholderOption() {
|
||||||
|
@ -22,9 +22,9 @@ export default class WrappedSelect extends WrappedElement {
|
||||||
const fragment = document.createDocumentFragment();
|
const fragment = document.createDocumentFragment();
|
||||||
const addOptionToFragment = data => {
|
const addOptionToFragment = data => {
|
||||||
// Create a standard select option
|
// Create a standard select option
|
||||||
const template = templates.option(data);
|
const option = this.template(data);
|
||||||
// Append it to fragment
|
// Append it to fragment
|
||||||
fragment.appendChild(template);
|
fragment.appendChild(option);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add each list item to list
|
// Add each list item to list
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { stub } from 'sinon';
|
import { stub, spy } from 'sinon';
|
||||||
import WrappedElement from './wrapped-element';
|
import WrappedElement from './wrapped-element';
|
||||||
import WrappedSelect from './wrapped-select';
|
import WrappedSelect from './wrapped-select';
|
||||||
import { DEFAULT_CLASSNAMES } from '../constants';
|
import { DEFAULT_CLASSNAMES } from '../constants';
|
||||||
|
import Templates from '../templates';
|
||||||
|
|
||||||
describe('components/wrappedSelect', () => {
|
describe('components/wrappedSelect', () => {
|
||||||
let instance;
|
let instance;
|
||||||
|
@ -28,6 +29,7 @@ describe('components/wrappedSelect', () => {
|
||||||
instance = new WrappedSelect({
|
instance = new WrappedSelect({
|
||||||
element: document.getElementById('target'),
|
element: document.getElementById('target'),
|
||||||
classNames: DEFAULT_CLASSNAMES,
|
classNames: DEFAULT_CLASSNAMES,
|
||||||
|
template: spy(Templates.option),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -133,6 +135,7 @@ describe('components/wrappedSelect', () => {
|
||||||
selectElement.appendChild(fragment);
|
selectElement.appendChild(fragment);
|
||||||
|
|
||||||
expect(fragment).to.be.instanceOf(DocumentFragment);
|
expect(fragment).to.be.instanceOf(DocumentFragment);
|
||||||
|
expect(instance.template.callCount).to.equal(2);
|
||||||
expect(selectElement.options.length).to.equal(2);
|
expect(selectElement.options.length).to.equal(2);
|
||||||
expect(selectElement.options[0].value).to.equal(options[0].value);
|
expect(selectElement.options[0].value).to.equal(options[0].value);
|
||||||
expect(selectElement.options[1].value).to.equal(options[1].value);
|
expect(selectElement.options[1].value).to.equal(options[1].value);
|
||||||
|
|
Loading…
Reference in a new issue