@danielgindi/selectbox 1.0.79 → 1.0.81

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
@@ -1625,7 +1625,6 @@ class DropList {
1625
1625
  const p = this._p;
1626
1626
 
1627
1627
  p.sink.add(p.el, 'keydown', evt => this._keydown(evt));
1628
- p.sink.add(p.el, 'keypress', evt => this._keydown(evt));
1629
1628
  }
1630
1629
 
1631
1630
  _keydown(event) {
package/lib/SelectBox.js CHANGED
@@ -1917,9 +1917,7 @@ class SelectBox {
1917
1917
  if (!dropList) return;
1918
1918
 
1919
1919
  let avoidToggleFromClick = false,
1920
- currentTouchId = null,
1921
- suppressKeyPress = false,
1922
- suppressKeyPressRepeat = false;
1920
+ currentTouchId = null;
1923
1921
 
1924
1922
  const keyEventsTarget = p.multi || p.searchable ? p.input : p.el;
1925
1923
 
@@ -1928,8 +1926,10 @@ class SelectBox {
1928
1926
  if ((/**@type HTMLInputElement*/evt.currentTarget).readOnly)
1929
1927
  return;
1930
1928
 
1931
- suppressKeyPress = false;
1932
- suppressKeyPressRepeat = false;
1929
+ let suppressEnterSpaceToggle = false;
1930
+ let lastKeyAllowsNonTypeKeys = p.lastKeyAllowsNonTypeKeys;
1931
+ p.lastKeyAllowsNonTypeKeys = false;
1932
+ let hasInputText = p.input && p.input.value.length > 0;
1933
1933
 
1934
1934
  switch (evt.key) {
1935
1935
  case VALUE_PAGE_UP:
@@ -1939,14 +1939,13 @@ class SelectBox {
1939
1939
  case VALUE_HOME:
1940
1940
  case VALUE_END:
1941
1941
  if ((evt.key === VALUE_HOME || evt.key === VALUE_END) &&
1942
- p.input && p.input.value.length > 0 && !p.lastKeyAllowsNonTypeKeys) {
1942
+ hasInputText && !lastKeyAllowsNonTypeKeys) {
1943
1943
  // Allow using HOME/END button within the textbox
1944
- suppressKeyPressRepeat = true;
1945
1944
  dropList._keydownFreeType(evt);
1946
1945
  break;
1947
1946
  }
1948
1947
 
1949
- suppressKeyPress = true;
1948
+ p.lastKeyAllowsNonTypeKeys = true;
1950
1949
  evt.preventDefault();
1951
1950
 
1952
1951
  switch (evt.key) {
@@ -1984,10 +1983,11 @@ class SelectBox {
1984
1983
  break;
1985
1984
 
1986
1985
  case VALUE_SPACE:
1987
- if (p.lastKeyAllowsNonTypeKeys) {
1986
+ if (lastKeyAllowsNonTypeKeys) {
1987
+ p.lastKeyAllowsNonTypeKeys = true;
1988
+
1988
1989
  if (dropList.isVisible() && dropList.hasFocusedItem()) {
1989
- suppressKeyPress = true;
1990
- suppressKeyPressRepeat = true;
1990
+ suppressEnterSpaceToggle = true;
1991
1991
  if (p.multi)
1992
1992
  dropList.toggleFocusedItem(evt);
1993
1993
  else dropList.triggerItemSelection(evt);
@@ -1998,8 +1998,7 @@ class SelectBox {
1998
1998
 
1999
1999
  case VALUE_ENTER:
2000
2000
  if (dropList.isVisible() && dropList.hasFocusedItem()) {
2001
- suppressKeyPress = true;
2002
- suppressKeyPressRepeat = true;
2001
+ suppressEnterSpaceToggle = true;
2003
2002
  evt.preventDefault();
2004
2003
  dropList.triggerItemSelection(evt);
2005
2004
  }
@@ -2020,39 +2019,21 @@ class SelectBox {
2020
2019
  break;
2021
2020
 
2022
2021
  default:
2023
- suppressKeyPressRepeat = true;
2024
2022
  dropList._keydownFreeType(evt);
2025
2023
  break;
2026
2024
  }
2027
2025
 
2028
- p.lastKeyAllowsNonTypeKeys = evt.key === VALUE_UP ||
2029
- evt.key === VALUE_DOWN ||
2030
- evt.key === VALUE_PAGE_UP ||
2031
- evt.key === VALUE_PAGE_DOWN ||
2032
- evt.key === VALUE_HOME ||
2033
- evt.key === VALUE_END ||
2034
- (evt.key === VALUE_SPACE && !!p.lastKeyAllowsNonTypeKeys);
2035
- })
2036
- .add(keyEventsTarget, 'keypress.dropdown', evt => {
2037
- if (suppressKeyPress) {
2038
- suppressKeyPress = false;
2039
- evt.preventDefault();
2040
- return;
2041
- }
2042
-
2043
- if (suppressKeyPressRepeat)
2044
- return;
2045
-
2046
- if (evt.key === VALUE_ENTER || (
2047
- evt.key === VALUE_SPACE &&
2048
- p.lastKeyAllowsNonTypeKeys &&
2049
- !p.multi &&
2050
- !dropList.hasFocusedItem()
2051
- )
2052
- ) {
2053
- this.toggleList();
2054
- evt.preventDefault();
2055
- evt.stopPropagation();
2026
+ if (!suppressEnterSpaceToggle) {
2027
+ if (evt.key === VALUE_ENTER || (
2028
+ evt.key === VALUE_SPACE &&
2029
+ p.lastKeyAllowsNonTypeKeys &&
2030
+ !p.multi &&
2031
+ !dropList.hasFocusedItem()
2032
+ )) {
2033
+ this.toggleList();
2034
+ evt.preventDefault();
2035
+ evt.stopPropagation();
2036
+ }
2056
2037
  }
2057
2038
  });
2058
2039
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielgindi/selectbox",
3
- "version": "1.0.79",
3
+ "version": "1.0.81",
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",