From 55fca5d402bbc696cbda53040076b1acabda7170 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Fri, 6 Oct 2017 09:07:49 +0100 Subject: [PATCH] Begin to abstract passedElement code --- src/scripts/src/components/wrapped-element.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/scripts/src/components/wrapped-element.js diff --git a/src/scripts/src/components/wrapped-element.js b/src/scripts/src/components/wrapped-element.js new file mode 100644 index 0000000..cdadf6a --- /dev/null +++ b/src/scripts/src/components/wrapped-element.js @@ -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'); + } +}