@danielgindi/selectbox 1.0.31 → 1.0.32

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.
package/lib/SelectBox.js CHANGED
@@ -100,7 +100,9 @@ const inputBackbufferCssProps = [
100
100
  * @property {string} [multiItemLabelProp='short_label']
101
101
  * @property {number} [maxMultiItems] maximum number of multi items. The rest will get a single item to represent.
102
102
  * @property {function(count: number, items: DropList.ItemBase[]):string} [multiItemsRestLabelProvider] label for the item representing the rest of the items.
103
- * @property {DropList.ItemBase[]|null} [items]
103
+ * @property {DropList.ItemBase[]|null} [items] initial items
104
+ * @property {*[]|null} [selectedValues] initial selected values
105
+ * @property {*|*[]|null} [value] initial selected value
104
106
  * @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderSingleItem]
105
107
  * @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderSingleItem]
106
108
  * @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderMultiItem]
@@ -141,6 +143,8 @@ const defaultOptions = {
141
143
  maxMultiItems: null,
142
144
  multiItemsRestLabelProvider: null,
143
145
  items: [],
146
+ selectedValues: undefined,
147
+ value: undefined,
144
148
  isLoadingMode: false,
145
149
  };
146
150
 
@@ -239,12 +243,12 @@ class SelectBox {
239
243
  renderNoResultsItem: o.renderNoResultsItem,
240
244
  unrenderNoResultsItem: o.unrenderNoResultsItem,
241
245
  filterFn: o.filterFn,
242
- on: o.on,
246
+ on: null,
243
247
  additionalClasses: o.additionalClasses,
244
248
 
245
249
  isLoadingMode: !!o.isLoadingMode,
246
250
 
247
- items: o.items || [],
251
+ items: [],
248
252
  filteredItems: null,
249
253
  itemsChanged: true,
250
254
 
@@ -338,7 +342,16 @@ class SelectBox {
338
342
  p.sink.add(window, 'resize', () => this._resizeInput());
339
343
  p.sink.add(window, 'orientationchange', () => this._resizeInput());
340
344
 
341
- this.setItems(p.items);
345
+ this.setItems(o.items);
346
+
347
+ if (o.multi && Array.isArray(o.selectedValues)) {
348
+ this.setSelectedValues(o.selectedValues);
349
+ } else if (o.value != null) {
350
+ this.setValue(o.value);
351
+ }
352
+
353
+ // Start firing events
354
+ p.on = o.on || null;
342
355
 
343
356
  this._scheduleSync();
344
357
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielgindi/selectbox",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "description": "A collection of dom utilities. So you can work natively with the dom without dom frameworks.",
5
5
  "main": "dist/lib.cjs.min.js",
6
6
  "module": "lib/index.js",