@internetstiftelsen/styleguide 4.0.13 → 4.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -69,6 +69,7 @@ var MultiSelect = function () {
|
|
|
69
69
|
|
|
70
70
|
this.getData();
|
|
71
71
|
this.attach();
|
|
72
|
+
this.sync();
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
_createClass(MultiSelect, [{
|
|
@@ -117,15 +118,34 @@ var MultiSelect = function () {
|
|
|
117
118
|
});
|
|
118
119
|
})));
|
|
119
120
|
}
|
|
121
|
+
}, {
|
|
122
|
+
key: 'sync',
|
|
123
|
+
value: function sync() {
|
|
124
|
+
var _this3 = this;
|
|
125
|
+
|
|
126
|
+
var inputs = this.element.querySelectorAll('input[name="' + this.name + '[]"]');
|
|
127
|
+
|
|
128
|
+
this.selectedItems = [];
|
|
129
|
+
|
|
130
|
+
inputs.forEach(function (input) {
|
|
131
|
+
var item = _this3.data.find(function (d) {
|
|
132
|
+
return d.value === input.value;
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
if (item) {
|
|
136
|
+
_this3.addItem(item, false);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
120
140
|
}, {
|
|
121
141
|
key: 'filterData',
|
|
122
142
|
value: function filterData(query) {
|
|
123
|
-
var
|
|
143
|
+
var _this4 = this;
|
|
124
144
|
|
|
125
145
|
return this.data.filter(function (item) {
|
|
126
146
|
return item.name.toLowerCase().startsWith(query.toLowerCase());
|
|
127
147
|
}).filter(function (item) {
|
|
128
|
-
return !
|
|
148
|
+
return !_this4.selectedItems.includes(item.name);
|
|
129
149
|
});
|
|
130
150
|
}
|
|
131
151
|
}, {
|
|
@@ -173,7 +193,9 @@ var MultiSelect = function () {
|
|
|
173
193
|
}, {
|
|
174
194
|
key: 'addItem',
|
|
175
195
|
value: function addItem(item) {
|
|
176
|
-
var
|
|
196
|
+
var _this5 = this;
|
|
197
|
+
|
|
198
|
+
var save = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
177
199
|
|
|
178
200
|
if (!item) {
|
|
179
201
|
return;
|
|
@@ -195,7 +217,7 @@ var MultiSelect = function () {
|
|
|
195
217
|
|
|
196
218
|
// Event listener for removing the selected item
|
|
197
219
|
removeBtn.addEventListener('click', function () {
|
|
198
|
-
|
|
220
|
+
_this5.removeItem(item);
|
|
199
221
|
});
|
|
200
222
|
|
|
201
223
|
newItem.appendChild(removeBtn);
|
|
@@ -203,18 +225,20 @@ var MultiSelect = function () {
|
|
|
203
225
|
this.selectedItemsList.appendChild(newItem);
|
|
204
226
|
this.selectedItems.push(item);
|
|
205
227
|
|
|
206
|
-
|
|
228
|
+
if (save) {
|
|
229
|
+
var itemInput = document.createElement('input');
|
|
207
230
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
231
|
+
itemInput.type = 'hidden';
|
|
232
|
+
itemInput.name = this.name + '[]';
|
|
233
|
+
itemInput.value = item.value;
|
|
211
234
|
|
|
212
|
-
|
|
235
|
+
this.element.appendChild(itemInput);
|
|
236
|
+
}
|
|
213
237
|
}
|
|
214
238
|
}, {
|
|
215
239
|
key: 'removeHighlight',
|
|
216
240
|
value: function removeHighlight() {
|
|
217
|
-
var items = this.suggestionsBox.getElementsByClassName(this.baseClassName + '__suggestion-btn');
|
|
241
|
+
var items = this.suggestionsBox.getElementsByClassName((0, _className2.default)(this.baseClassName + '__suggestion-btn'));
|
|
218
242
|
|
|
219
243
|
[].forEach.call(items, function (item) {
|
|
220
244
|
item.classList.remove('autocomplete-active');
|
|
@@ -223,7 +247,7 @@ var MultiSelect = function () {
|
|
|
223
247
|
}, {
|
|
224
248
|
key: 'highlight',
|
|
225
249
|
value: function highlight(direction) {
|
|
226
|
-
var items = this.suggestionsBox.getElementsByClassName(this.baseClassName + '__suggestion-btn');
|
|
250
|
+
var items = this.suggestionsBox.getElementsByClassName((0, _className2.default)(this.baseClassName + '__suggestion-btn'));
|
|
227
251
|
var focus = this.currentFocus;
|
|
228
252
|
|
|
229
253
|
if (direction === 'down') {
|
package/package.json
CHANGED
|
@@ -14,6 +14,7 @@ class MultiSelect {
|
|
|
14
14
|
|
|
15
15
|
this.getData();
|
|
16
16
|
this.attach();
|
|
17
|
+
this.sync();
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
getData() {
|
|
@@ -53,6 +54,20 @@ class MultiSelect {
|
|
|
53
54
|
];
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
sync() {
|
|
58
|
+
const inputs = this.element.querySelectorAll(`input[name="${this.name}[]"]`);
|
|
59
|
+
|
|
60
|
+
this.selectedItems = [];
|
|
61
|
+
|
|
62
|
+
inputs.forEach((input) => {
|
|
63
|
+
const item = this.data.find((d) => d.value === input.value);
|
|
64
|
+
|
|
65
|
+
if (item) {
|
|
66
|
+
this.addItem(item, false);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
56
71
|
filterData(query) {
|
|
57
72
|
return this.data
|
|
58
73
|
.filter((item) => item.name.toLowerCase().startsWith(query.toLowerCase()))
|
|
@@ -112,7 +127,7 @@ class MultiSelect {
|
|
|
112
127
|
itemInput.remove();
|
|
113
128
|
}
|
|
114
129
|
|
|
115
|
-
addItem(item) {
|
|
130
|
+
addItem(item, save = true) {
|
|
116
131
|
if (!item) {
|
|
117
132
|
return;
|
|
118
133
|
}
|
|
@@ -141,17 +156,19 @@ class MultiSelect {
|
|
|
141
156
|
this.selectedItemsList.appendChild(newItem);
|
|
142
157
|
this.selectedItems.push(item);
|
|
143
158
|
|
|
144
|
-
|
|
159
|
+
if (save) {
|
|
160
|
+
const itemInput = document.createElement('input');
|
|
145
161
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
162
|
+
itemInput.type = 'hidden';
|
|
163
|
+
itemInput.name = `${this.name}[]`;
|
|
164
|
+
itemInput.value = item.value;
|
|
149
165
|
|
|
150
|
-
|
|
166
|
+
this.element.appendChild(itemInput);
|
|
167
|
+
}
|
|
151
168
|
}
|
|
152
169
|
|
|
153
170
|
removeHighlight() {
|
|
154
|
-
const items = this.suggestionsBox.getElementsByClassName(`${this.baseClassName}__suggestion-btn`);
|
|
171
|
+
const items = this.suggestionsBox.getElementsByClassName(className(`${this.baseClassName}__suggestion-btn`));
|
|
155
172
|
|
|
156
173
|
[].forEach.call(items, (item) => {
|
|
157
174
|
item.classList.remove('autocomplete-active');
|
|
@@ -159,7 +176,7 @@ class MultiSelect {
|
|
|
159
176
|
}
|
|
160
177
|
|
|
161
178
|
highlight(direction) {
|
|
162
|
-
const items = this.suggestionsBox.getElementsByClassName(`${this.baseClassName}__suggestion-btn`);
|
|
179
|
+
const items = this.suggestionsBox.getElementsByClassName(className(`${this.baseClassName}__suggestion-btn`));
|
|
163
180
|
let focus = this.currentFocus;
|
|
164
181
|
|
|
165
182
|
if (direction === 'down') {
|