2017-10-13 14:43:58 +02:00
|
|
|
import WrappedElement from './wrapped-element';
|
2017-12-18 13:06:38 +01:00
|
|
|
import templates from './../templates';
|
2017-10-13 14:43:58 +02:00
|
|
|
|
|
|
|
export default class WrappedSelect extends WrappedElement {
|
|
|
|
constructor(instance, element, classNames) {
|
|
|
|
super(instance, element, classNames);
|
|
|
|
this.parentInstance = instance;
|
|
|
|
this.element = element;
|
|
|
|
this.classNames = classNames;
|
|
|
|
}
|
|
|
|
|
2017-10-18 14:05:07 +02:00
|
|
|
getElement() {
|
|
|
|
super.getElement();
|
|
|
|
}
|
|
|
|
|
2017-10-13 14:43:58 +02:00
|
|
|
conceal() {
|
|
|
|
super.conceal();
|
|
|
|
}
|
|
|
|
|
|
|
|
reveal() {
|
|
|
|
super.reveal();
|
|
|
|
}
|
2017-10-18 09:43:56 +02:00
|
|
|
|
|
|
|
enable() {
|
|
|
|
super.enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
disable() {
|
2017-12-19 14:08:57 +01:00
|
|
|
super.disable();
|
2017-10-18 09:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getPlaceholderOption() {
|
|
|
|
return this.element.querySelector('option[placeholder]');
|
|
|
|
}
|
|
|
|
|
|
|
|
getOptions() {
|
|
|
|
return Array.from(this.element.options);
|
|
|
|
}
|
|
|
|
|
|
|
|
getOptionGroups() {
|
|
|
|
return Array.from(this.element.getElementsByTagName('OPTGROUP'));
|
|
|
|
}
|
2017-12-18 13:06:38 +01:00
|
|
|
|
|
|
|
setOptions(options) {
|
|
|
|
const fragment = document.createDocumentFragment();
|
|
|
|
const addOptionToFragment = (data) => {
|
|
|
|
// Create a standard select option
|
|
|
|
const template = templates.option(data);
|
|
|
|
// Append it to fragment
|
|
|
|
fragment.appendChild(template);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Add each list item to list
|
|
|
|
options.forEach(optionData => addOptionToFragment(optionData));
|
|
|
|
|
|
|
|
this.appendDocFragment(fragment);
|
|
|
|
}
|
|
|
|
|
|
|
|
appendDocFragment(fragment) {
|
|
|
|
this.element.innerHTML = '';
|
|
|
|
this.element.appendChild(fragment);
|
|
|
|
}
|
2017-10-13 14:43:58 +02:00
|
|
|
}
|