@danielgindi/selectbox 1.0.145 → 1.0.147

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/DropList.js CHANGED
@@ -701,7 +701,10 @@ class DropList {
701
701
 
702
702
  p.virtualListHelper.setCount(0);
703
703
 
704
- return this.addItems(items);
704
+ this.addItems(items);
705
+ this.updateSublist();
706
+
707
+ return this;
705
708
  }
706
709
 
707
710
  updateItemByValue(value, newItem) {
@@ -1465,20 +1468,21 @@ class DropList {
1465
1468
  droplist: droplist,
1466
1469
  });
1467
1470
 
1468
- droplist.show( {
1469
- target: itemElement,
1470
- position: { x: 'start', y: 'top' },
1471
- anchor: { x: 'end', y: 'top' },
1472
- offset: { x: 0, y: 0 },
1473
- updateWidth: false,
1474
- });
1475
-
1476
1471
  p.currentSubDropList = {
1477
1472
  item: item,
1478
1473
  itemElement: itemElement,
1479
1474
  droplist: droplist,
1475
+ showOptions: {
1476
+ target: itemElement,
1477
+ position: { x: 'start', y: 'top' },
1478
+ anchor: { x: 'end', y: 'top' },
1479
+ offset: { x: 0, y: 0 },
1480
+ updateWidth: false,
1481
+ },
1480
1482
  };
1481
1483
 
1484
+ droplist.show(p.currentSubDropList.showOptions);
1485
+
1482
1486
  droplist.el.focus();
1483
1487
  }
1484
1488
 
@@ -1507,6 +1511,36 @@ class DropList {
1507
1511
  });
1508
1512
  }
1509
1513
 
1514
+ /**
1515
+ * Updates the current open sublist with new subitems if changed
1516
+ */
1517
+ updateSublist() {
1518
+ const p = this._p;
1519
+
1520
+ if (!p.currentSubDropList)
1521
+ return;
1522
+
1523
+ const originalItem = p.currentSubDropList.item;
1524
+
1525
+ const data = p.currentSubDropList;
1526
+ const newItem = p.items.find(x => x === originalItem) ||
1527
+ p.items.find(x => x.value === data.item.value);
1528
+ if (newItem) {
1529
+ p.currentSubDropList.item = newItem;
1530
+ const itemElement = p.virtualListHelper.getItemElementAt(this._getItemIndex(newItem));
1531
+ p.currentSubDropList.itemElement = itemElement;
1532
+
1533
+ if (newItem._subitems) {
1534
+ p.currentSubDropList.droplist.setItems(newItem._subitems);
1535
+
1536
+ if (itemElement) {
1537
+ p.currentSubDropList.showOptions.target = itemElement;
1538
+ p.currentSubDropList.droplist.relayout(p.currentSubDropList.showOptions);
1539
+ }
1540
+ }
1541
+ }
1542
+ }
1543
+
1510
1544
  setFocusedItem(item) {
1511
1545
  const p = this._p;
1512
1546
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielgindi/selectbox",
3
- "version": "1.0.145",
3
+ "version": "1.0.147",
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",
package/vue/DropList.vue CHANGED
@@ -108,6 +108,10 @@ export default {
108
108
  positionOptions: {
109
109
  type: Object,
110
110
  },
111
+ autoRelayoutOnItemsChange: {
112
+ type: Boolean,
113
+ default: true,
114
+ },
111
115
  },
112
116
 
113
117
  emits: [
@@ -216,10 +220,10 @@ export default {
216
220
  watch: {
217
221
  items(value) {
218
222
  if (this.nonReactive.instance) {
219
- this.nonReactive.instance.removeAllItems();
220
-
221
- if (Array.isArray(value))
222
- this.nonReactive.instance.addItems(value);
223
+ const instance = this.nonReactive.instance;
224
+ instance.setItems(Array.isArray(value) ? value : []);
225
+ if (this.autoRelayoutOnItemsChange && instance.isVisible())
226
+ instance.relayout(this.positionOptions);
223
227
  }
224
228
  },
225
229