@danielgindi/selectbox 2.0.51 → 2.0.52

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
@@ -63,7 +63,8 @@ const hasOwnProperty = Object.prototype.hasOwnProperty;
63
63
  * @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderNoResultsItem]
64
64
  * @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderNoResultsItem]
65
65
  * @property {function(name: string, data: *)} [on]
66
- * @property {boolean} [isHeaderVisible=false] show header element
66
+ * @property {boolean} [isHeaderVisible=false] show header element
67
+ * @property {boolean} [isFooterVisible=false] show footer element
67
68
  * @property {boolean} [searchable=false] include inline search box
68
69
  * @property {string} [noResultsText='No matching results'] text for no results (empty for none)
69
70
  * @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
@@ -136,7 +137,8 @@ export const DefaultOptions = {
136
137
 
137
138
  on: null,
138
139
 
139
- isHeaderVisible: false,
140
+ isHeaderVisible: false,
141
+ isFooterVisible: false,
140
142
  searchable: false,
141
143
  noResultsText: 'No matching results',
142
144
  filterThrottleWindow: 300,
@@ -209,7 +211,8 @@ class DropList {
209
211
  positionOptionsProvider: o.positionOptionsProvider ?? null,
210
212
 
211
213
  searchable: o.searchable,
212
- isHeaderVisible: o.isHeaderVisible,
214
+ isHeaderVisible: o.isHeaderVisible,
215
+ isFooterVisible: o.isFooterVisible,
213
216
 
214
217
  silenceEvents: true,
215
218
  mitt: mitt(),
@@ -263,20 +266,27 @@ class DropList {
263
266
  menuEl.role = 'menu';
264
267
  p.menuEl = menuEl;
265
268
 
266
- p.headerEl = createElement('div', {
267
- class: p.baseClassName + '_header',
268
- });
269
-
270
- if (o.searchable) {
271
- this.setSearchable(true);
272
- }
273
-
274
- if (o.isHeaderVisible)
275
- this.setHeaderVisible(o.isHeaderVisible);
276
-
277
- wrapperEl.appendChild(menuEl);
278
-
279
- p.items = [];
269
+ p.headerEl = createElement('div', {
270
+ class: p.baseClassName + '_header',
271
+ });
272
+
273
+ p.footerEl = createElement('div', {
274
+ class: p.baseClassName + '_footer',
275
+ });
276
+
277
+ if (o.searchable) {
278
+ this.setSearchable(true);
279
+ }
280
+
281
+ if (o.isHeaderVisible)
282
+ this.setHeaderVisible(o.isHeaderVisible);
283
+
284
+ wrapperEl.appendChild(menuEl);
285
+
286
+ if (o.isFooterVisible)
287
+ this.setFooterVisible(o.isFooterVisible);
288
+
289
+ p.items = [];
280
290
  p.groupCount = 0; // This will keep state of how many `group` items we have
281
291
  p.mouseHandled = false;
282
292
 
@@ -1527,17 +1537,23 @@ class DropList {
1527
1537
  let verticalBorderWidth = (parseFloat(elComputedStyle.borderTopWidth) || 0) +
1528
1538
  (parseFloat(elComputedStyle.borderBottomWidth) || 0);
1529
1539
 
1530
- let headerHeight = 0;
1531
- if (p.headerEl) {
1532
- headerHeight = getElementHeight(p.headerEl, true, true);
1533
- }
1534
-
1535
- if (p.virtualListHelper.isVirtual()) {
1536
- maxViewHeight =
1537
- p.virtualListHelper.estimateFullHeight() +
1538
- verticalPadding +
1539
- verticalBorderWidth +
1540
- headerHeight;
1540
+ let headerHeight = 0;
1541
+ if (p.headerEl) {
1542
+ headerHeight = getElementHeight(p.headerEl, true, true);
1543
+ }
1544
+
1545
+ let footerHeight = 0;
1546
+ if (p.footerEl) {
1547
+ footerHeight = getElementHeight(p.footerEl, true, true);
1548
+ }
1549
+
1550
+ if (p.virtualListHelper.isVirtual()) {
1551
+ maxViewHeight =
1552
+ p.virtualListHelper.estimateFullHeight() +
1553
+ verticalPadding +
1554
+ verticalBorderWidth +
1555
+ headerHeight +
1556
+ footerHeight;
1541
1557
  } else {
1542
1558
  // Another method to calculate height is measuring the whole thing at once.
1543
1559
  // This causes relayout of course.
@@ -1678,12 +1694,12 @@ class DropList {
1678
1694
  viewCss.left += 'px';
1679
1695
  viewCss.top += 'px';
1680
1696
  setCssProps(el, viewCss);
1681
- setElementHeight(el, viewSize.height, true, true);
1682
-
1683
- if (menuEl !== el) {
1684
- let menuHeight = viewSize.height - headerHeight - verticalBorderWidth - verticalPadding;
1685
- setElementHeight(menuEl, menuHeight, true, true);
1686
- }
1697
+ setElementHeight(el, viewSize.height, true, true);
1698
+
1699
+ if (menuEl !== el) {
1700
+ let menuHeight = viewSize.height - headerHeight - footerHeight - verticalBorderWidth - verticalPadding;
1701
+ setElementHeight(menuEl, menuHeight, true, true);
1702
+ }
1687
1703
 
1688
1704
  // Update the scroll position for virtual lists
1689
1705
  p.virtualListHelper.render();
@@ -2013,13 +2029,46 @@ class DropList {
2013
2029
  * Get a reference to the header element in order to add custom content.
2014
2030
  * @returns {Element}
2015
2031
  */
2016
- getHeaderElement() {
2017
- return this._p.headerEl;
2018
- }
2019
-
2020
- /**
2021
- * Set inline search visibility
2022
- * You should probably call `relayout()` after this.
2032
+ getHeaderElement() {
2033
+ return this._p.headerEl;
2034
+ }
2035
+
2036
+ /**
2037
+ * Change visibility of the footer element
2038
+ * You should probably call `relayout()` after this.
2039
+ * @param {boolean} visible
2040
+ */
2041
+ setFooterVisible(visible) {
2042
+ let isVisible = this.isFooterVisible();
2043
+ if (isVisible === !!visible)
2044
+ return;
2045
+
2046
+ if (visible) {
2047
+ this._p.el.appendChild(this._p.footerEl);
2048
+ } else {
2049
+ this._p.footerEl.remove();
2050
+ }
2051
+ }
2052
+
2053
+ /**
2054
+ * Is the footer element visible?
2055
+ * @returns {boolean}
2056
+ */
2057
+ isFooterVisible() {
2058
+ return !!this._p.footerEl.parentNode;
2059
+ }
2060
+
2061
+ /**
2062
+ * Get a reference to the footer element in order to add custom content.
2063
+ * @returns {Element}
2064
+ */
2065
+ getFooterElement() {
2066
+ return this._p.footerEl;
2067
+ }
2068
+
2069
+ /**
2070
+ * Set inline search visibility
2071
+ * You should probably call `relayout()` after this.
2023
2072
  * @param {boolean} searchable
2024
2073
  */
2025
2074
  setSearchable(searchable) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielgindi/selectbox",
3
- "version": "2.0.51",
3
+ "version": "2.0.52",
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",
@@ -32,14 +32,17 @@
32
32
  max-width: 100%;
33
33
  line-height: 1.3;
34
34
 
35
- .droplist_header {
36
- position: relative;
37
- padding: 0.5em;
38
- box-sizing: inherit;
39
-
40
- input[type=search] {
41
- box-sizing: inherit;
42
- width: 100%;
35
+ .droplist_header,
36
+ .droplist_footer {
37
+ position: relative;
38
+ padding: 0.5em;
39
+ box-sizing: inherit;
40
+ }
41
+
42
+ .droplist_header {
43
+ input[type=search] {
44
+ box-sizing: inherit;
45
+ width: 100%;
43
46
  }
44
47
  }
45
48
 
package/vue/DropList.vue CHANGED
@@ -50,13 +50,17 @@ export const PropTypes = {
50
50
  type: Boolean,
51
51
  default: false,
52
52
  },
53
- isHeaderVisible: {
54
- type: Boolean,
55
- default: false,
56
- },
57
- searchable: {
58
- type: Boolean,
59
- default: false,
53
+ isHeaderVisible: {
54
+ type: Boolean,
55
+ default: false,
56
+ },
57
+ isFooterVisible: {
58
+ type: Boolean,
59
+ default: false,
60
+ },
61
+ searchable: {
62
+ type: Boolean,
63
+ default: false,
60
64
  },
61
65
  noResultsText: {
62
66
  type: String,
@@ -207,12 +211,12 @@ export default {
207
211
  opts.direction = this.direction;
208
212
  }
209
213
 
210
- for (let key of ['autoItemBlur', 'capturesFocus', 'multi',
211
- 'autoCheckGroupChildren', 'useExactTargetWidth', 'constrainToWindow',
212
- 'autoFlipDirection', 'estimateWidth',
213
- 'isHeaderVisible',
214
- 'searchable', 'filterOnEmptyTerm',
215
- 'filterGroups', 'filterEmptyGroups']) {
214
+ for (let key of ['autoItemBlur', 'capturesFocus', 'multi',
215
+ 'autoCheckGroupChildren', 'useExactTargetWidth', 'constrainToWindow',
216
+ 'autoFlipDirection', 'estimateWidth',
217
+ 'isHeaderVisible', 'isFooterVisible',
218
+ 'searchable', 'filterOnEmptyTerm',
219
+ 'filterGroups', 'filterEmptyGroups']) {
216
220
  if (typeof this[key] === 'boolean') {
217
221
  opts[key] = this[key];
218
222
  }
@@ -353,13 +357,19 @@ export default {
353
357
  this.relayout();
354
358
  },
355
359
 
356
- isHeaderVisible(v) {
357
- if (this.nonReactive.instance)
358
- this.nonReactive.instance.setHeaderVisible(v);
359
- this.relayout();
360
- },
361
-
362
- positionOptions: {
360
+ isHeaderVisible(v) {
361
+ if (this.nonReactive.instance)
362
+ this.nonReactive.instance.setHeaderVisible(v);
363
+ this.relayout();
364
+ },
365
+
366
+ isFooterVisible(v) {
367
+ if (this.nonReactive.instance)
368
+ this.nonReactive.instance.setFooterVisible(v);
369
+ this.relayout();
370
+ },
371
+
372
+ positionOptions: {
363
373
  deep: true,
364
374
  handler() {
365
375
  this.relayout();
@@ -453,11 +463,16 @@ export default {
453
463
  }
454
464
 
455
465
  const headerRenderer = createSlotBasedRenderFunc(this, 'header');
456
- if (headerRenderer) {
457
- headerRenderer({}, list.getHeaderElement());
458
- }
459
-
460
- list.show();
466
+ if (headerRenderer) {
467
+ headerRenderer({}, list.getHeaderElement());
468
+ }
469
+
470
+ const footerRenderer = createSlotBasedRenderFunc(this, 'footer');
471
+ if (footerRenderer) {
472
+ footerRenderer({}, list.getFooterElement());
473
+ }
474
+
475
+ list.show();
461
476
 
462
477
  this._setupAutoRelayout();
463
478
  },
@@ -526,12 +541,17 @@ export default {
526
541
  this.nonReactive.instance.relayout();
527
542
  },
528
543
 
529
- getHeaderElement() {
530
- if (this.nonReactive.instance)
531
- this.nonReactive.instance.getHeaderElement();
532
- },
533
-
534
- elContains(other, considerSublists = true) {
544
+ getHeaderElement() {
545
+ if (this.nonReactive.instance)
546
+ return this.nonReactive.instance.getHeaderElement();
547
+ },
548
+
549
+ getFooterElement() {
550
+ if (this.nonReactive.instance)
551
+ return this.nonReactive.instance.getFooterElement();
552
+ },
553
+
554
+ elContains(other, considerSublists = true) {
535
555
  return !!this.listRef?.elContains(other, considerSublists);
536
556
  },
537
557
  },