Merge pull request #209 from maximmig/master

Backup & recover original styles: added test
This commit is contained in:
Josh Johnson 2017-07-18 08:39:01 +01:00 committed by GitHub
commit a7ee256a85
5 changed files with 40 additions and 22 deletions

View file

@ -351,11 +351,11 @@ return /******/ (function(modules) { // webpackBootstrap
// Reinstate passed element
this.passedElement.classList.remove(this.config.classNames.input, this.config.classNames.hiddenState);
this.passedElement.removeAttribute('tabindex');
// restore original styles if any
var oldStyle = this.passedElement.getAttribute('data-choices-js-orig-style');
if (Boolean(oldStyle)) {
this.passedElement.removeAttribute('data-choices-js-orig-style');
this.passedElement.setAttribute('style', oldStyle);
// Recover original styles if any
var origStyle = this.passedElement.getAttribute('data-choice-orig-style');
if (Boolean(origStyle)) {
this.passedElement.removeAttribute('data-choice-orig-style');
this.passedElement.setAttribute('style', origStyle);
} else {
this.passedElement.removeAttribute('style');
}
@ -2624,10 +2624,10 @@ return /******/ (function(modules) { // webpackBootstrap
this.passedElement.classList.add(this.config.classNames.input, this.config.classNames.hiddenState);
this.passedElement.tabIndex = '-1';
// persist original styles if any
var oldStyle = this.passedElement.getAttribute('style');
if (Boolean(oldStyle)) {
this.passedElement.setAttribute('data-choices-js-orig-style', oldStyle);
// Backup original styles if any
var origStyle = this.passedElement.getAttribute('style');
if (Boolean(origStyle)) {
this.passedElement.setAttribute('data-choice-orig-style', origStyle);
}
this.passedElement.setAttribute('style', 'display:none;');
this.passedElement.setAttribute('aria-hidden', 'true');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -281,11 +281,11 @@ class Choices {
// Reinstate passed element
this.passedElement.classList.remove(this.config.classNames.input, this.config.classNames.hiddenState);
this.passedElement.removeAttribute('tabindex');
// restore original styles if any
const oldStyle = this.passedElement.getAttribute('data-choices-js-orig-style');
if (Boolean(oldStyle)) {
this.passedElement.removeAttribute('data-choices-js-orig-style');
this.passedElement.setAttribute('style', oldStyle);
// Recover original styles if any
const origStyle = this.passedElement.getAttribute('data-choice-orig-style');
if (Boolean(origStyle)) {
this.passedElement.removeAttribute('data-choice-orig-style');
this.passedElement.setAttribute('style', origStyle);
} else {
this.passedElement.removeAttribute('style');
}
@ -2584,10 +2584,10 @@ class Choices {
);
this.passedElement.tabIndex = '-1';
// persist original styles if any
const oldStyle = this.passedElement.getAttribute('style');
if (Boolean(oldStyle)) {
this.passedElement.setAttribute('data-choices-js-orig-style', oldStyle);
// Backup original styles if any
const origStyle = this.passedElement.getAttribute('style');
if (Boolean(origStyle)) {
this.passedElement.setAttribute('data-choice-orig-style', origStyle);
}
this.passedElement.setAttribute('style', 'display:none;');
this.passedElement.setAttribute('aria-hidden', 'true');

View file

@ -28,7 +28,7 @@ describe('Choices', () => {
expect(this.choices).toBeDefined();
});
it('should have initalised', function() {
it('should have initialised', function() {
expect(this.choices.initialised).toBe(true);
});
@ -135,6 +135,24 @@ describe('Choices', () => {
it('should create a dropdown', function() {
expect(this.choices.dropdown).toEqual(jasmine.any(HTMLElement));
});
it('should backup and recover original styles', function () {
const origStyle = 'background-color: #ccc; margin: 5px padding: 10px;';
this.choices.destroy();
this.input.setAttribute('style', origStyle);
this.choices = new Choices(this.input);
let style = this.input.getAttribute('data-choice-orig-style');
expect(style).toEqual(origStyle);
this.choices.destroy();
style = this.input.getAttribute('data-choice-orig-style');
expect(style).toBeNull();
style = this.input.getAttribute('style');
expect(style).toEqual(origStyle);
});
});
describe('should accept text inputs', function() {