@danielgindi/selectbox 1.0.123 → 1.0.124

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.123
2
+ * @danielgindi/selectbox 1.0.124
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  import { createElement, closestUntil, setElementAttrs, next, prev } from '@danielgindi/dom-utils/lib/Dom';
@@ -7,7 +7,7 @@ import { remove, toggleClass, before, append, getRootNode } from '@danielgindi/d
7
7
  import { setCssProps, getElementOffset, getElementHeight, getElementWidth, anchoredPosition, setElementHeight, parseTransition, setElementWidth, getPseudoElementWidth, getCssProps } from '@danielgindi/dom-utils/lib/Css';
8
8
  import DomEventsSink from '@danielgindi/dom-utils/lib/DomEventsSink';
9
9
  import VirtualListHelper from '@danielgindi/virtual-list-helper';
10
- import { VALUE_ESCAPE, VALUE_SPACE, VALUE_ENTER, VALUE_DOWN, VALUE_UP, VALUE_END, VALUE_HOME, VALUE_PAGE_DOWN, VALUE_PAGE_UP, VALUE_TAB, VALUE_DELETE, VALUE_BACK_SPACE, VALUE_LEFT, VALUE_RIGHT } from 'keycode-js';
10
+ import { VALUE_ESCAPE, VALUE_SPACE, VALUE_ENTER, VALUE_RIGHT, VALUE_LEFT, VALUE_DOWN, VALUE_UP, VALUE_END, VALUE_HOME, VALUE_PAGE_DOWN, VALUE_PAGE_UP, VALUE_TAB, VALUE_DELETE, VALUE_BACK_SPACE } from 'keycode-js';
11
11
  import mitt from 'mitt';
12
12
 
13
13
  var escapeRegex = value => value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
@@ -331,9 +331,9 @@ class DropList {
331
331
  remove(p.el);
332
332
  }
333
333
 
334
- if (p._currentSubDropList) {
335
- p._currentSubDropList?.droplist?.destroy();
336
- p._currentSubDropList = null;
334
+ if (p.currentSubDropList) {
335
+ p.currentSubDropList?.droplist?.destroy();
336
+ p.currentSubDropList = null;
337
337
  }
338
338
 
339
339
  if (!p.ownsEl) {
@@ -364,6 +364,22 @@ class DropList {
364
364
  return this._p.el;
365
365
  }
366
366
 
367
+ /**
368
+ * Returns true if other is an inclusive descendant of node, and false otherwise.
369
+ * @param {Node} other
370
+ * @param {boolean} [considerSubmenus=true]
371
+ * @returns {boolean}
372
+ */
373
+ elContains(other, considerSubmenus = true) {
374
+ if (this.el.contains(other))
375
+ return true;
376
+
377
+ if (considerSubmenus && this._p.currentSubDropList?.droplist?.elContains(other))
378
+ return true;
379
+
380
+ return false;
381
+ }
382
+
367
383
  /**
368
384
  * @param {string|string[]} classes
369
385
  * @returns {DropList}
@@ -501,7 +517,7 @@ class DropList {
501
517
  if (!item)
502
518
  return;
503
519
 
504
- if (p._currentSubDropList) {
520
+ if (p.currentSubDropList) {
505
521
  this._hideSublist();
506
522
  }
507
523
 
@@ -1294,7 +1310,7 @@ class DropList {
1294
1310
  if (this[DestroyedSymbol$1]) return;
1295
1311
  this._trigger('hide:after');
1296
1312
 
1297
- if (p._currentSubDropList) {
1313
+ if (p.currentSubDropList) {
1298
1314
  this._hideSublist();
1299
1315
  }
1300
1316
  }
@@ -1420,7 +1436,7 @@ class DropList {
1420
1436
  updateWidth: true,
1421
1437
  });
1422
1438
 
1423
- p._currentSubDropList = {
1439
+ p.currentSubDropList = {
1424
1440
  item: item,
1425
1441
  itemElement: itemElement,
1426
1442
  droplist: droplist,
@@ -1430,13 +1446,13 @@ class DropList {
1430
1446
  _hideSublist() {
1431
1447
  const p = this._p;
1432
1448
 
1433
- if (!p._currentSubDropList)
1449
+ if (!p.currentSubDropList)
1434
1450
  return;
1435
1451
 
1436
- const data = p._currentSubDropList;
1452
+ const data = p.currentSubDropList;
1437
1453
  data.droplist.hide();
1438
1454
  data.droplist.destroy();
1439
- p._currentSubDropList = null;
1455
+ p.currentSubDropList = null;
1440
1456
 
1441
1457
  this._trigger('hide_subitems', {
1442
1458
  value: data.item.value,
@@ -1686,7 +1702,7 @@ class DropList {
1686
1702
  }
1687
1703
 
1688
1704
  _handleMouseOver(event, itemEl) {
1689
- this._focus(event, itemEl);
1705
+ this._focus(event, itemEl, true);
1690
1706
  }
1691
1707
 
1692
1708
  _hookTouchEvents() {
@@ -1752,7 +1768,7 @@ class DropList {
1752
1768
  let itemEl = p.focusItemEl || // focused item
1753
1769
  p.el.firstChild; // or the first item
1754
1770
 
1755
- this._focus(event, itemEl);
1771
+ this._focus(event, itemEl, false);
1756
1772
  })
1757
1773
  .add(p.el, 'blur', () => {
1758
1774
  setTimeout(() => {
@@ -1811,6 +1827,21 @@ class DropList {
1811
1827
  }
1812
1828
  break;
1813
1829
 
1830
+ case VALUE_LEFT:
1831
+ case VALUE_RIGHT:
1832
+ if (event.key === VALUE_RIGHT && getComputedStyle(event.target).direction !== 'rtl' ||
1833
+ event.key === VALUE_LEFT && getComputedStyle(event.target).direction === 'rtl') {
1834
+ let item = p.items[p.focusItemIndex];
1835
+ if (p.focusItemIndex > -1 && item._subitems)
1836
+ this._showSublist(item, p.focusItemEl);
1837
+ } else {
1838
+ if (p.currentSubDropList) {
1839
+ p.currentSubDropList.hide();
1840
+ preventDefault = false;
1841
+ }
1842
+ }
1843
+ break;
1844
+
1814
1845
  case VALUE_ENTER:
1815
1846
  this.triggerItemSelection(null, event);
1816
1847
  event.preventDefault();
@@ -1887,7 +1918,7 @@ class DropList {
1887
1918
 
1888
1919
  if (matchIndex > -1) {
1889
1920
  let next = p.virtualListHelper.getItemElementAt(matchIndex);
1890
- this._focus(evt, next || null, matchIndex);
1921
+ this._focus(evt, next || null, matchIndex, true);
1891
1922
 
1892
1923
  if (!this.isVisible()) {
1893
1924
  this.triggerItemSelection(next ? null : p.items[matchIndex], evt);
@@ -1906,7 +1937,7 @@ class DropList {
1906
1937
  }
1907
1938
  }
1908
1939
 
1909
- _focus(event, itemEl, itemIndex) {
1940
+ _focus(event, itemEl, itemIndex, openSubitems) {
1910
1941
  const p = this._p;
1911
1942
 
1912
1943
  if (!itemIndex && itemEl) {
@@ -1943,7 +1974,9 @@ class DropList {
1943
1974
  event: event,
1944
1975
  el: focusItemEl,
1945
1976
  });
1946
- this._showSublist(item, focusItemEl);
1977
+
1978
+ if (openSubitems)
1979
+ this._showSublist(item, focusItemEl);
1947
1980
  }
1948
1981
 
1949
1982
  _delayBlurItemOnBlur() {
@@ -2087,7 +2120,7 @@ class DropList {
2087
2120
  }
2088
2121
 
2089
2122
  next = p.virtualListHelper.getItemElementAt(nextIndex);
2090
- this._focus(event, next || null, nextIndex);
2123
+ this._focus(event, next || null, nextIndex, false);
2091
2124
 
2092
2125
  if (!this.isVisible()) {
2093
2126
  this.triggerItemSelection(item, event);