@danielgindi/selectbox 2.0.50 → 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/dist/lib.es6.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/selectbox 2.0.50
2
+ * @danielgindi/selectbox 2.0.52
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  import { createElement, closestUntil, setElementAttrs, next, prev } from '@danielgindi/dom-utils/lib/Dom';
@@ -91,7 +91,8 @@ const hasOwnProperty = Object.prototype.hasOwnProperty;
91
91
  * @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderNoResultsItem]
92
92
  * @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderNoResultsItem]
93
93
  * @property {function(name: string, data: *)} [on]
94
- * @property {boolean} [isHeaderVisible=false] show header element
94
+ * @property {boolean} [isHeaderVisible=false] show header element
95
+ * @property {boolean} [isFooterVisible=false] show footer element
95
96
  * @property {boolean} [searchable=false] include inline search box
96
97
  * @property {string} [noResultsText='No matching results'] text for no results (empty for none)
97
98
  * @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
@@ -164,7 +165,8 @@ const DefaultOptions$1 = {
164
165
 
165
166
  on: null,
166
167
 
167
- isHeaderVisible: false,
168
+ isHeaderVisible: false,
169
+ isFooterVisible: false,
168
170
  searchable: false,
169
171
  noResultsText: 'No matching results',
170
172
  filterThrottleWindow: 300,
@@ -237,7 +239,8 @@ class DropList {
237
239
  positionOptionsProvider: o.positionOptionsProvider ?? null,
238
240
 
239
241
  searchable: o.searchable,
240
- isHeaderVisible: o.isHeaderVisible,
242
+ isHeaderVisible: o.isHeaderVisible,
243
+ isFooterVisible: o.isFooterVisible,
241
244
 
242
245
  silenceEvents: true,
243
246
  mitt: mitt(),
@@ -291,20 +294,27 @@ class DropList {
291
294
  menuEl.role = 'menu';
292
295
  p.menuEl = menuEl;
293
296
 
294
- p.headerEl = createElement('div', {
295
- class: p.baseClassName + '_header',
296
- });
297
-
298
- if (o.searchable) {
299
- this.setSearchable(true);
300
- }
301
-
302
- if (o.isHeaderVisible)
303
- this.setHeaderVisible(o.isHeaderVisible);
304
-
305
- wrapperEl.appendChild(menuEl);
297
+ p.headerEl = createElement('div', {
298
+ class: p.baseClassName + '_header',
299
+ });
300
+
301
+ p.footerEl = createElement('div', {
302
+ class: p.baseClassName + '_footer',
303
+ });
304
+
305
+ if (o.searchable) {
306
+ this.setSearchable(true);
307
+ }
306
308
 
307
- p.items = [];
309
+ if (o.isHeaderVisible)
310
+ this.setHeaderVisible(o.isHeaderVisible);
311
+
312
+ wrapperEl.appendChild(menuEl);
313
+
314
+ if (o.isFooterVisible)
315
+ this.setFooterVisible(o.isFooterVisible);
316
+
317
+ p.items = [];
308
318
  p.groupCount = 0; // This will keep state of how many `group` items we have
309
319
  p.mouseHandled = false;
310
320
 
@@ -1555,17 +1565,23 @@ class DropList {
1555
1565
  let verticalBorderWidth = (parseFloat(elComputedStyle.borderTopWidth) || 0) +
1556
1566
  (parseFloat(elComputedStyle.borderBottomWidth) || 0);
1557
1567
 
1558
- let headerHeight = 0;
1559
- if (p.headerEl) {
1560
- headerHeight = getElementHeight(p.headerEl, true, true);
1561
- }
1562
-
1563
- if (p.virtualListHelper.isVirtual()) {
1564
- maxViewHeight =
1565
- p.virtualListHelper.estimateFullHeight() +
1566
- verticalPadding +
1567
- verticalBorderWidth +
1568
- headerHeight;
1568
+ let headerHeight = 0;
1569
+ if (p.headerEl) {
1570
+ headerHeight = getElementHeight(p.headerEl, true, true);
1571
+ }
1572
+
1573
+ let footerHeight = 0;
1574
+ if (p.footerEl) {
1575
+ footerHeight = getElementHeight(p.footerEl, true, true);
1576
+ }
1577
+
1578
+ if (p.virtualListHelper.isVirtual()) {
1579
+ maxViewHeight =
1580
+ p.virtualListHelper.estimateFullHeight() +
1581
+ verticalPadding +
1582
+ verticalBorderWidth +
1583
+ headerHeight +
1584
+ footerHeight;
1569
1585
  } else {
1570
1586
  // Another method to calculate height is measuring the whole thing at once.
1571
1587
  // This causes relayout of course.
@@ -1706,12 +1722,12 @@ class DropList {
1706
1722
  viewCss.left += 'px';
1707
1723
  viewCss.top += 'px';
1708
1724
  setCssProps(el, viewCss);
1709
- setElementHeight(el, viewSize.height, true, true);
1710
-
1711
- if (menuEl !== el) {
1712
- let menuHeight = viewSize.height - headerHeight - verticalBorderWidth - verticalPadding;
1713
- setElementHeight(menuEl, menuHeight, true, true);
1714
- }
1725
+ setElementHeight(el, viewSize.height, true, true);
1726
+
1727
+ if (menuEl !== el) {
1728
+ let menuHeight = viewSize.height - headerHeight - footerHeight - verticalBorderWidth - verticalPadding;
1729
+ setElementHeight(menuEl, menuHeight, true, true);
1730
+ }
1715
1731
 
1716
1732
  // Update the scroll position for virtual lists
1717
1733
  p.virtualListHelper.render();
@@ -2041,13 +2057,46 @@ class DropList {
2041
2057
  * Get a reference to the header element in order to add custom content.
2042
2058
  * @returns {Element}
2043
2059
  */
2044
- getHeaderElement() {
2045
- return this._p.headerEl;
2046
- }
2047
-
2048
- /**
2049
- * Set inline search visibility
2050
- * You should probably call `relayout()` after this.
2060
+ getHeaderElement() {
2061
+ return this._p.headerEl;
2062
+ }
2063
+
2064
+ /**
2065
+ * Change visibility of the footer element
2066
+ * You should probably call `relayout()` after this.
2067
+ * @param {boolean} visible
2068
+ */
2069
+ setFooterVisible(visible) {
2070
+ let isVisible = this.isFooterVisible();
2071
+ if (isVisible === !!visible)
2072
+ return;
2073
+
2074
+ if (visible) {
2075
+ this._p.el.appendChild(this._p.footerEl);
2076
+ } else {
2077
+ this._p.footerEl.remove();
2078
+ }
2079
+ }
2080
+
2081
+ /**
2082
+ * Is the footer element visible?
2083
+ * @returns {boolean}
2084
+ */
2085
+ isFooterVisible() {
2086
+ return !!this._p.footerEl.parentNode;
2087
+ }
2088
+
2089
+ /**
2090
+ * Get a reference to the footer element in order to add custom content.
2091
+ * @returns {Element}
2092
+ */
2093
+ getFooterElement() {
2094
+ return this._p.footerEl;
2095
+ }
2096
+
2097
+ /**
2098
+ * Set inline search visibility
2099
+ * You should probably call `relayout()` after this.
2051
2100
  * @param {boolean} searchable
2052
2101
  */
2053
2102
  setSearchable(searchable) {
@@ -6626,10 +6675,12 @@ class SelectBox {
6626
6675
  event.preventDefault();
6627
6676
  } else if (event.key === VALUE_BACK_SPACE && target.value.length === 0) {
6628
6677
  const itemEl = p.multiItemEls[p.multiItemEls.length - 1];
6629
- if (!itemEl || itemEl[ItemSymbol].value === undefined)
6678
+ if (!itemEl)
6630
6679
  return;
6631
6680
 
6632
6681
  const item = itemEl[ItemSymbol], value = item[p.valueProp];
6682
+ if (value === undefined)
6683
+ return;
6633
6684
 
6634
6685
  let removeselEvt = { value: value, item: item, cancel: false };
6635
6686
  this._trigger('removesel:before', removeselEvt);