Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added multi class functionality #907

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 95 additions & 29 deletions public/assets/scripts/choices.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! choices.js v9.0.1 | © 2019 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/*! choices.js v9.0.1 | © 2020 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
Expand Down Expand Up @@ -1214,8 +1214,11 @@ function () {
});

WrappedElement.prototype.conceal = function () {
// Hide passed input
this.element.classList.add(this.classNames.input);
var _a; // Hide passed input


(_a = this.element.classList).add.apply(_a, this.classNames.input.split(" "));

this.element.hidden = true; // Remove element from tab index

this.element.tabIndex = -1; // Backup original styles if any
Expand All @@ -1230,8 +1233,11 @@ function () {
};

WrappedElement.prototype.reveal = function () {
// Reinstate passed element
this.element.classList.remove(this.classNames.input);
var _a; // Reinstate passed element


(_a = this.element.classList).remove.apply(_a, this.classNames.input.split(" "));

this.element.hidden = false;
this.element.removeAttribute('tabindex'); // Recover original styles if any

Expand Down Expand Up @@ -3064,6 +3070,8 @@ function () {
};

Choices.prototype._highlightChoice = function (el) {
var _a;

var _this = this;

if (el === void 0) {
Expand All @@ -3080,7 +3088,10 @@ function () {
var highlightedChoices = Array.from(this.dropdown.element.querySelectorAll("." + this.config.classNames.highlightedState)); // Remove any highlighted choices

highlightedChoices.forEach(function (choice) {
choice.classList.remove(_this.config.classNames.highlightedState);
var _a;

(_a = choice.classList).remove.apply(_a, _this.config.classNames.highlightedState.split(" "));

choice.setAttribute('aria-selected', 'false');
});

Expand All @@ -3101,7 +3112,8 @@ function () {
}
}

passedEl.classList.add(this.config.classNames.highlightedState);
(_a = passedEl.classList).add.apply(_a, this.config.classNames.highlightedState.split(" "));

passedEl.setAttribute('aria-selected', 'true');
this.passedElement.triggerEvent(constants_1.EVENTS.highlightChoice, {
el: passedEl
Expand Down Expand Up @@ -3577,7 +3589,7 @@ function () {
};

Choices.prototype._generatePlaceholderValue = function () {
if (this._isSelectElement) {
if (this._isSelectElement && this.passedElement.placeholderOption) {
var placeholderOption = this.passedElement.placeholderOption;
return placeholderOption ? placeholderOption.text : null;
}
Expand Down Expand Up @@ -4447,7 +4459,10 @@ function () {


Dropdown.prototype.show = function () {
this.element.classList.add(this.classNames.activeState);
var _a;

(_a = this.element.classList).add.apply(_a, this.classNames.activeState.split(" "));

this.element.setAttribute('aria-expanded', 'true');
this.isActive = true;
return this;
Expand All @@ -4458,7 +4473,10 @@ function () {


Dropdown.prototype.hide = function () {
this.element.classList.remove(this.classNames.activeState);
var _a;

(_a = this.element.classList).remove.apply(_a, this.classNames.activeState.split(" "));

this.element.setAttribute('aria-expanded', 'false');
this.isActive = false;
return this;
Expand Down Expand Up @@ -4547,24 +4565,32 @@ function () {
};

Container.prototype.open = function (dropdownPos) {
this.element.classList.add(this.classNames.openState);
var _a, _b;

(_a = this.element.classList).add.apply(_a, this.classNames.openState.split(" "));

this.element.setAttribute('aria-expanded', 'true');
this.isOpen = true;

if (this.shouldFlip(dropdownPos)) {
this.element.classList.add(this.classNames.flippedState);
(_b = this.element.classList).add.apply(_b, this.classNames.flippedState.split(" "));

this.isFlipped = true;
}
};

Container.prototype.close = function () {
this.element.classList.remove(this.classNames.openState);
var _a, _b;

(_a = this.element.classList).remove.apply(_a, this.classNames.openState.split(" "));

this.element.setAttribute('aria-expanded', 'false');
this.removeActiveDescendant();
this.isOpen = false; // A dropdown flips if it does not have space within the page

if (this.isFlipped) {
this.element.classList.remove(this.classNames.flippedState);
(_b = this.element.classList).remove.apply(_b, this.classNames.flippedState.split(" "));

this.isFlipped = false;
}
};
Expand All @@ -4576,15 +4602,22 @@ function () {
};

Container.prototype.addFocusState = function () {
this.element.classList.add(this.classNames.focusState);
var _a;

(_a = this.element.classList).add.apply(_a, this.classNames.focusState.split(" "));
};

Container.prototype.removeFocusState = function () {
this.element.classList.remove(this.classNames.focusState);
var _a;

(_a = this.element.classList).remove.apply(_a, this.classNames.focusState.split(" "));
};

Container.prototype.enable = function () {
this.element.classList.remove(this.classNames.disabledState);
var _a;

(_a = this.element.classList).remove.apply(_a, this.classNames.disabledState.split(" "));

this.element.removeAttribute('aria-disabled');

if (this.type === constants_1.SELECT_ONE_TYPE) {
Expand All @@ -4595,7 +4628,10 @@ function () {
};

Container.prototype.disable = function () {
this.element.classList.add(this.classNames.disabledState);
var _a;

(_a = this.element.classList).add.apply(_a, this.classNames.disabledState.split(" "));

this.element.setAttribute('aria-disabled', 'true');

if (this.type === constants_1.SELECT_ONE_TYPE) {
Expand All @@ -4619,13 +4655,19 @@ function () {
};

Container.prototype.addLoadingState = function () {
this.element.classList.add(this.classNames.loadingState);
var _a;

(_a = this.element.classList).add.apply(_a, this.classNames.loadingState.split(" "));

this.element.setAttribute('aria-busy', 'true');
this.isLoading = true;
};

Container.prototype.removeLoadingState = function () {
this.element.classList.remove(this.classNames.loadingState);
var _a;

(_a = this.element.classList).remove.apply(_a, this.classNames.loadingState.split(" "));

this.element.removeAttribute('aria-busy');
this.isLoading = false;
};
Expand Down Expand Up @@ -5113,6 +5155,20 @@ exports.default = WrappedSelect;
"use strict";


var __spreadArrays = this && this.__spreadArrays || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) {
s += arguments[i].length;
}

for (var r = Array(s), k = 0, i = 0; i < il; i++) {
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) {
r[k] = a[j];
}
}

return r;
};

Object.defineProperty(exports, "__esModule", {
value: true
});
Expand Down Expand Up @@ -5171,6 +5227,8 @@ var templates = {
});
},
item: function item(_a, _b, removeItemButton) {
var _c, _d, _e;

var item = _a.item,
button = _a.button,
highlightedState = _a.highlightedState,
Expand Down Expand Up @@ -5204,14 +5262,14 @@ var templates = {
}

if (isPlaceholder) {
div.classList.add(placeholder);
(_c = div.classList).add.apply(_c, placeholder.split(' '));
}

div.classList.add(highlighted ? highlightedState : itemSelectable);
(_d = div.classList).add.apply(_d, highlighted ? highlightedState.split(' ') : itemSelectable.split(' '));

if (removeItemButton) {
if (disabled) {
div.classList.remove(itemSelectable);
(_e = div.classList).remove.apply(_e, itemSelectable.split(' '));
}

div.dataset.deletable = '';
Expand Down Expand Up @@ -5271,6 +5329,8 @@ var templates = {
return div;
},
choice: function choice(_a, _b, selectText) {
var _c, _d, _e, _f;

var item = _a.item,
itemChoice = _a.itemChoice,
itemSelectable = _a.itemSelectable,
Expand All @@ -5292,11 +5352,11 @@ var templates = {
});

if (isSelected) {
div.classList.add(selectedState);
(_c = div.classList).add.apply(_c, selectedState.split(' '));
}

if (isPlaceholder) {
div.classList.add(placeholder);
(_d = div.classList).add.apply(_d, placeholder.split(' '));
}

div.setAttribute('role', groupId && groupId > 0 ? 'treeitem' : 'option');
Expand All @@ -5308,11 +5368,13 @@ var templates = {
});

if (isDisabled) {
div.classList.add(itemDisabled);
(_e = div.classList).add.apply(_e, itemDisabled.split(' '));

div.dataset.choiceDisabled = '';
div.setAttribute('aria-disabled', 'true');
} else {
div.classList.add(itemSelectable);
(_f = div.classList).add.apply(_f, itemSelectable.split(' '));

div.dataset.choiceSelectable = '';
}

Expand All @@ -5334,10 +5396,14 @@ var templates = {
return inp;
},
dropdown: function dropdown(_a) {
var _b;

var list = _a.list,
listDropdown = _a.listDropdown;
var div = document.createElement('div');
div.classList.add(list, listDropdown);

(_b = div.classList).add.apply(_b, __spreadArrays(list.split(' '), listDropdown.split(' ')));

div.setAttribute('aria-expanded', 'false');
return div;
},
Expand Down Expand Up @@ -5556,4 +5622,4 @@ exports.setIsLoading = function (isLoading) {

/***/ })
/******/ ])["default"];
});
});
6 changes: 3 additions & 3 deletions public/assets/scripts/choices.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/scripts/choices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@ class Choices {

// Remove any highlighted choices
highlightedChoices.forEach(choice => {
choice.classList.remove(this.config.classNames.highlightedState);
choice.classList.remove(...this.config.classNames.highlightedState.split(" "));
choice.setAttribute('aria-selected', 'false');
});

Expand All @@ -1884,7 +1884,7 @@ class Choices {
}
}

passedEl.classList.add(this.config.classNames.highlightedState);
passedEl.classList.add(...this.config.classNames.highlightedState.split(" "));
passedEl.setAttribute('aria-selected', 'true');
this.passedElement.triggerEvent(EVENTS.highlightChoice, { el: passedEl });

Expand Down
20 changes: 10 additions & 10 deletions src/scripts/components/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,25 @@ export default class Container {
}

open(dropdownPos: number): void {
this.element.classList.add(this.classNames.openState);
this.element.classList.add(...this.classNames.openState.split(" "));
this.element.setAttribute('aria-expanded', 'true');
this.isOpen = true;

if (this.shouldFlip(dropdownPos)) {
this.element.classList.add(this.classNames.flippedState);
this.element.classList.add(...this.classNames.flippedState.split(" "));
this.isFlipped = true;
}
}

close(): void {
this.element.classList.remove(this.classNames.openState);
this.element.classList.remove(...this.classNames.openState.split(" "));
this.element.setAttribute('aria-expanded', 'false');
this.removeActiveDescendant();
this.isOpen = false;

// A dropdown flips if it does not have space within the page
if (this.isFlipped) {
this.element.classList.remove(this.classNames.flippedState);
this.element.classList.remove(...this.classNames.flippedState.split(" "));
this.isFlipped = false;
}
}
Expand All @@ -108,15 +108,15 @@ export default class Container {
}

addFocusState(): void {
this.element.classList.add(this.classNames.focusState);
this.element.classList.add(...this.classNames.focusState.split(" "));
}

removeFocusState(): void {
this.element.classList.remove(this.classNames.focusState);
this.element.classList.remove(...this.classNames.focusState.split(" "));
}

enable(): void {
this.element.classList.remove(this.classNames.disabledState);
this.element.classList.remove(...this.classNames.disabledState.split(" "));
this.element.removeAttribute('aria-disabled');
if (this.type === SELECT_ONE_TYPE) {
this.element.setAttribute('tabindex', '0');
Expand All @@ -125,7 +125,7 @@ export default class Container {
}

disable(): void {
this.element.classList.add(this.classNames.disabledState);
this.element.classList.add(...this.classNames.disabledState.split(" "));
this.element.setAttribute('aria-disabled', 'true');
if (this.type === SELECT_ONE_TYPE) {
this.element.setAttribute('tabindex', '-1');
Expand All @@ -147,13 +147,13 @@ export default class Container {
}

addLoadingState(): void {
this.element.classList.add(this.classNames.loadingState);
this.element.classList.add(...this.classNames.loadingState.split(" "));
this.element.setAttribute('aria-busy', 'true');
this.isLoading = true;
}

removeLoadingState(): void {
this.element.classList.remove(this.classNames.loadingState);
this.element.classList.remove(...this.classNames.loadingState.split(" "));
this.element.removeAttribute('aria-busy');
this.isLoading = false;
}
Expand Down
Loading