@danielgindi/selectbox 1.0.46 → 1.0.50

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 1.0.46
2
+ * @danielgindi/selectbox 1.0.50
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  import { createElement, closestUntil, setElementAttrs, next, prev } from '@danielgindi/dom-utils/lib/Dom';
@@ -51,14 +51,14 @@ const hasOwnProperty = Object.prototype.hasOwnProperty;
51
51
 
52
52
  /**
53
53
  * @typedef {Object} DropList.PositionOptions
54
- * @property {Element} [target] Target element to act as anchor
55
- * @property {{left: number, top: number}} [targetOffset=undefined] Override the offset of target. Automatically calculated if unspecified.
56
- * @property {number} [targetHeight=undefined] Override height of the target
57
- * @property {number} [targetWidth=undefined] Override width of the target
58
- * @property {DropList.PositionAnchor} [position=undefined]
59
- * @property {DropList.PositionAnchor} [anchor=undefined]
60
- * @property {boolean} [updateWidth=false] Should update the width of the menu according to target
61
- * @property {string} [targetRtl=undefined] Override for rtl mode of the target
54
+ * @property {Element?} [target] Target element to act as anchor
55
+ * @property {{left: number, top: number}?} [targetOffset] Override the offset of target. Automatically calculated if unspecified.
56
+ * @property {number?} [targetHeight] Override height of the target
57
+ * @property {number?} [targetWidth] Override width of the target
58
+ * @property {DropList.PositionAnchor?} [position]
59
+ * @property {DropList.PositionAnchor?} [anchor]
60
+ * @property {boolean|number?} [updateWidth=false] `true` to set width of the menu according to `target`'s width, or specify an arbitrary number.
61
+ * @property {string?} [targetRtl] Override for rtl mode of the target
62
62
  * @property {{x: number, y: number}} [offset=undefined] Extra rtl-aware offset to the target
63
63
  * */
64
64
  /** */
@@ -164,7 +164,7 @@ class DropList {
164
164
  let classes = [p.baseClassName];
165
165
 
166
166
  if (p.additionalClasses) {
167
- classes = classes.concat((p.additionalClasses + '').split('').filter(x => x));
167
+ classes = classes.concat((p.additionalClasses + '').split(' ').filter(x => x));
168
168
  }
169
169
 
170
170
  const initialCss = {
@@ -367,6 +367,50 @@ class DropList {
367
367
  return this;
368
368
  }
369
369
 
370
+ /**
371
+ *
372
+ * @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [fn] Function to call when rendering an item element
373
+ * @returns {DropList}
374
+ */
375
+ setRenderItem(fn) {
376
+ const p = this._p;
377
+ p.renderItem = fn;
378
+ return this;
379
+ }
380
+
381
+ /**
382
+ *
383
+ * @property {function(item: DropList.ItemBase, itemEl: Element)} [fn] Function to call when rendering an item element
384
+ * @returns {DropList}
385
+ */
386
+ setUnrenderItem(fn) {
387
+ const p = this._p;
388
+
389
+ p.unrenderItem = fn;
390
+
391
+ if (typeof p.unrenderItem === 'function') {
392
+ const fn = p.unrenderItem;
393
+ p.virtualListHelper.setOnItemUnrender(el => {
394
+ try {
395
+ fn(el[ItemSymbol$1][ItemSymbol$1], el);
396
+ } catch (err) { console.error(err); } // eslint-disable-line no-console
397
+ delete el[ItemSymbol$1];
398
+
399
+ if (p.focusItemEl === el)
400
+ p.focusItemEl = null;
401
+ });
402
+ } else {
403
+ p.virtualListHelper.setOnItemUnrender(el => {
404
+ delete el[ItemSymbol$1];
405
+
406
+ if (p.focusItemEl === el)
407
+ p.focusItemEl = null;
408
+ });
409
+ }
410
+
411
+ return this;
412
+ }
413
+
370
414
  /**
371
415
  * @param {string} prop
372
416
  * @returns {DropList}
@@ -735,7 +779,7 @@ class DropList {
735
779
  }
736
780
 
737
781
  // Now set the width of the dropdown
738
- if (positionOptions.updateWidth) {
782
+ if (positionOptions.updateWidth || typeof positionOptions.updateWidth === 'number') {
739
783
  this._updateWidth(positionOptions);
740
784
  }
741
785
 
@@ -2093,9 +2137,14 @@ class DropList {
2093
2137
  let targetWidth = 0;
2094
2138
 
2095
2139
  if (positionOptions) {
2096
- // Measure target
2097
- targetWidth = positionOptions.targetWidth;
2098
- if (targetWidth == null) {
2140
+ if (typeof positionOptions.updateWidth === 'number') {
2141
+ // Set from width specified
2142
+ targetWidth = positionOptions.updateWidth;
2143
+ } else if (positionOptions.targetWidth != null) {
2144
+ // Set from simulated target width
2145
+ targetWidth = positionOptions.updateWidth;
2146
+ } else {
2147
+ // Measure target
2099
2148
  targetWidth = getElementWidth(positionOptions.target, true, true);
2100
2149
  }
2101
2150
  }