mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-29 10:50:03 +02:00
Begin to abstract passedElement code
This commit is contained in:
parent
b8c53bdd49
commit
55fca5d402
38
src/scripts/src/components/wrapped-element.js
Normal file
38
src/scripts/src/components/wrapped-element.js
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import { isType } from '../lib/utils';
|
||||||
|
|
||||||
|
export default class WrappedElement {
|
||||||
|
constructor(instance, element, classNames) {
|
||||||
|
this.instance = instance;
|
||||||
|
this.element = isType('String', element) ? document.querySelector(element) : element;
|
||||||
|
|
||||||
|
if (!this.element || !['text', 'select-one', 'select-multiple'].includes(this.element.type)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.classNames = classNames;
|
||||||
|
this.type = this.element.type;
|
||||||
|
this.placeholder = this.element.getAttribute('placeholder');
|
||||||
|
}
|
||||||
|
|
||||||
|
hide() {
|
||||||
|
// Hide passed input
|
||||||
|
this.element.classList.add(
|
||||||
|
this.classNames.input,
|
||||||
|
this.classNames.hiddenState,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Remove element from tab index
|
||||||
|
this.element.tabIndex = '-1';
|
||||||
|
|
||||||
|
// Backup original styles if any
|
||||||
|
const origStyle = this.element.getAttribute('style');
|
||||||
|
|
||||||
|
if (origStyle) {
|
||||||
|
this.element.setAttribute('data-choice-orig-style', origStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.element.setAttribute('style', 'display:none;');
|
||||||
|
this.element.setAttribute('aria-hidden', 'true');
|
||||||
|
this.element.setAttribute('data-choice', 'active');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue