slim-select 2.4.0 → 2.4.1

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/render.d.ts CHANGED
@@ -93,7 +93,7 @@ export default class Render {
93
93
  updateClassStyles(): void;
94
94
  updateAriaAttributes(): void;
95
95
  mainDiv(): Main;
96
- mainFocus(trigger: boolean, eventType: string | null): void;
96
+ mainFocus(eventType: string | null): void;
97
97
  placeholder(): HTMLDivElement;
98
98
  renderValues(): void;
99
99
  private renderSingleValue;
@@ -102,7 +102,7 @@ export default class Render {
102
102
  contentDiv(): Content;
103
103
  moveContent(): void;
104
104
  searchDiv(): Search;
105
- searchFocus(trigger: boolean): void;
105
+ searchFocus(): void;
106
106
  getOptions(notPlaceholder?: boolean, notDisabled?: boolean, notHidden?: boolean): HTMLDivElement[];
107
107
  highlight(dir: 'up' | 'down'): void;
108
108
  listDiv(): HTMLDivElement;
@@ -6,8 +6,7 @@ export default class Settings {
6
6
  class: string[];
7
7
  isMultiple: boolean;
8
8
  isOpen: boolean;
9
- isWindowFocused: boolean;
10
- triggerFocus: boolean;
9
+ isFullOpen: boolean;
11
10
  intervalMove: NodeJS.Timeout | null;
12
11
  disabled: boolean;
13
12
  alwaysOpen: boolean;
@@ -59,8 +59,7 @@ class Settings {
59
59
  this.class = [];
60
60
  this.isMultiple = false;
61
61
  this.isOpen = false;
62
- this.isWindowFocused = true;
63
- this.triggerFocus = true;
62
+ this.isFullOpen = false;
64
63
  this.intervalMove = null;
65
64
  if (!settings) {
66
65
  settings = {};
@@ -503,14 +502,10 @@ class Render {
503
502
  },
504
503
  };
505
504
  }
506
- mainFocus(trigger, eventType) {
507
- if (!trigger) {
508
- this.settings.triggerFocus = false;
509
- }
505
+ mainFocus(eventType) {
510
506
  if (eventType !== 'click') {
511
507
  this.main.main.focus({ preventScroll: true });
512
508
  }
513
- this.settings.triggerFocus = true;
514
509
  }
515
510
  placeholder() {
516
511
  const placeholderOption = this.store.filter((o) => o.placeholder, false);
@@ -744,7 +739,6 @@ class Render {
744
739
  switch (e.key) {
745
740
  case 'ArrowUp':
746
741
  case 'ArrowDown':
747
- this.callbacks.open();
748
742
  e.key === 'ArrowDown' ? this.highlight('down') : this.highlight('up');
749
743
  return false;
750
744
  case 'Tab':
@@ -767,12 +761,6 @@ class Render {
767
761
  return false;
768
762
  }
769
763
  };
770
- input.onfocus = () => {
771
- if (this.settings.isOpen) {
772
- return;
773
- }
774
- this.callbacks.open();
775
- };
776
764
  main.appendChild(input);
777
765
  if (this.callbacks.addable) {
778
766
  addable.classList.add(this.classes.addable);
@@ -845,12 +833,8 @@ class Render {
845
833
  }
846
834
  return searchReturn;
847
835
  }
848
- searchFocus(trigger) {
849
- if (!trigger) {
850
- this.settings.triggerFocus = false;
851
- }
836
+ searchFocus() {
852
837
  this.content.search.input.focus();
853
- this.settings.triggerFocus = true;
854
838
  }
855
839
  getOptions(notPlaceholder = false, notDisabled = false, notHidden = false) {
856
840
  let query = '.' + this.classes.option;
@@ -1507,13 +1491,13 @@ class SlimSelect {
1507
1491
  afterClose: undefined,
1508
1492
  };
1509
1493
  this.windowResize = debounce(() => {
1510
- if (!this.settings.isOpen) {
1494
+ if (!this.settings.isOpen && !this.settings.isFullOpen) {
1511
1495
  return;
1512
1496
  }
1513
1497
  this.render.moveContent();
1514
1498
  });
1515
1499
  this.windowScroll = debounce(() => {
1516
- if (!this.settings.isOpen) {
1500
+ if (!this.settings.isOpen && !this.settings.isFullOpen) {
1517
1501
  return;
1518
1502
  }
1519
1503
  this.render.moveContent();
@@ -1528,14 +1512,8 @@ class SlimSelect {
1528
1512
  };
1529
1513
  this.windowVisibilityChange = () => {
1530
1514
  if (document.hidden) {
1531
- this.settings.isWindowFocused = false;
1532
1515
  this.close();
1533
1516
  }
1534
- else {
1535
- setTimeout(() => {
1536
- this.settings.isWindowFocused = true;
1537
- }, 20);
1538
- }
1539
1517
  };
1540
1518
  this.selectEl = (typeof config.select === 'string' ? document.querySelector(config.select) : config.select);
1541
1519
  if (!this.selectEl) {
@@ -1705,13 +1683,16 @@ class SlimSelect {
1705
1683
  }
1706
1684
  this.render.open();
1707
1685
  if (this.settings.showSearch) {
1708
- this.render.searchFocus(false);
1686
+ this.render.searchFocus();
1709
1687
  }
1688
+ this.settings.isOpen = true;
1710
1689
  setTimeout(() => {
1711
1690
  if (this.events.afterOpen) {
1712
1691
  this.events.afterOpen();
1713
1692
  }
1714
- this.settings.isOpen = true;
1693
+ if (this.settings.isOpen) {
1694
+ this.settings.isFullOpen = true;
1695
+ }
1715
1696
  }, this.settings.timeoutDelay);
1716
1697
  if (this.settings.contentPosition === 'absolute') {
1717
1698
  if (this.settings.intervalMove) {
@@ -1731,12 +1712,13 @@ class SlimSelect {
1731
1712
  if (this.render.content.search.input.value !== '') {
1732
1713
  this.search('');
1733
1714
  }
1734
- this.render.mainFocus(false, eventType);
1715
+ this.render.mainFocus(eventType);
1716
+ this.settings.isOpen = false;
1717
+ this.settings.isFullOpen = false;
1735
1718
  setTimeout(() => {
1736
1719
  if (this.events.afterClose) {
1737
1720
  this.events.afterClose();
1738
1721
  }
1739
- this.settings.isOpen = false;
1740
1722
  }, this.settings.timeoutDelay);
1741
1723
  if (this.settings.intervalMove) {
1742
1724
  clearInterval(this.settings.intervalMove);
@@ -57,8 +57,7 @@ class Settings {
57
57
  this.class = [];
58
58
  this.isMultiple = false;
59
59
  this.isOpen = false;
60
- this.isWindowFocused = true;
61
- this.triggerFocus = true;
60
+ this.isFullOpen = false;
62
61
  this.intervalMove = null;
63
62
  if (!settings) {
64
63
  settings = {};
@@ -501,14 +500,10 @@ class Render {
501
500
  },
502
501
  };
503
502
  }
504
- mainFocus(trigger, eventType) {
505
- if (!trigger) {
506
- this.settings.triggerFocus = false;
507
- }
503
+ mainFocus(eventType) {
508
504
  if (eventType !== 'click') {
509
505
  this.main.main.focus({ preventScroll: true });
510
506
  }
511
- this.settings.triggerFocus = true;
512
507
  }
513
508
  placeholder() {
514
509
  const placeholderOption = this.store.filter((o) => o.placeholder, false);
@@ -742,7 +737,6 @@ class Render {
742
737
  switch (e.key) {
743
738
  case 'ArrowUp':
744
739
  case 'ArrowDown':
745
- this.callbacks.open();
746
740
  e.key === 'ArrowDown' ? this.highlight('down') : this.highlight('up');
747
741
  return false;
748
742
  case 'Tab':
@@ -765,12 +759,6 @@ class Render {
765
759
  return false;
766
760
  }
767
761
  };
768
- input.onfocus = () => {
769
- if (this.settings.isOpen) {
770
- return;
771
- }
772
- this.callbacks.open();
773
- };
774
762
  main.appendChild(input);
775
763
  if (this.callbacks.addable) {
776
764
  addable.classList.add(this.classes.addable);
@@ -843,12 +831,8 @@ class Render {
843
831
  }
844
832
  return searchReturn;
845
833
  }
846
- searchFocus(trigger) {
847
- if (!trigger) {
848
- this.settings.triggerFocus = false;
849
- }
834
+ searchFocus() {
850
835
  this.content.search.input.focus();
851
- this.settings.triggerFocus = true;
852
836
  }
853
837
  getOptions(notPlaceholder = false, notDisabled = false, notHidden = false) {
854
838
  let query = '.' + this.classes.option;
@@ -1505,13 +1489,13 @@ class SlimSelect {
1505
1489
  afterClose: undefined,
1506
1490
  };
1507
1491
  this.windowResize = debounce(() => {
1508
- if (!this.settings.isOpen) {
1492
+ if (!this.settings.isOpen && !this.settings.isFullOpen) {
1509
1493
  return;
1510
1494
  }
1511
1495
  this.render.moveContent();
1512
1496
  });
1513
1497
  this.windowScroll = debounce(() => {
1514
- if (!this.settings.isOpen) {
1498
+ if (!this.settings.isOpen && !this.settings.isFullOpen) {
1515
1499
  return;
1516
1500
  }
1517
1501
  this.render.moveContent();
@@ -1526,14 +1510,8 @@ class SlimSelect {
1526
1510
  };
1527
1511
  this.windowVisibilityChange = () => {
1528
1512
  if (document.hidden) {
1529
- this.settings.isWindowFocused = false;
1530
1513
  this.close();
1531
1514
  }
1532
- else {
1533
- setTimeout(() => {
1534
- this.settings.isWindowFocused = true;
1535
- }, 20);
1536
- }
1537
1515
  };
1538
1516
  this.selectEl = (typeof config.select === 'string' ? document.querySelector(config.select) : config.select);
1539
1517
  if (!this.selectEl) {
@@ -1703,13 +1681,16 @@ class SlimSelect {
1703
1681
  }
1704
1682
  this.render.open();
1705
1683
  if (this.settings.showSearch) {
1706
- this.render.searchFocus(false);
1684
+ this.render.searchFocus();
1707
1685
  }
1686
+ this.settings.isOpen = true;
1708
1687
  setTimeout(() => {
1709
1688
  if (this.events.afterOpen) {
1710
1689
  this.events.afterOpen();
1711
1690
  }
1712
- this.settings.isOpen = true;
1691
+ if (this.settings.isOpen) {
1692
+ this.settings.isFullOpen = true;
1693
+ }
1713
1694
  }, this.settings.timeoutDelay);
1714
1695
  if (this.settings.contentPosition === 'absolute') {
1715
1696
  if (this.settings.intervalMove) {
@@ -1729,12 +1710,13 @@ class SlimSelect {
1729
1710
  if (this.render.content.search.input.value !== '') {
1730
1711
  this.search('');
1731
1712
  }
1732
- this.render.mainFocus(false, eventType);
1713
+ this.render.mainFocus(eventType);
1714
+ this.settings.isOpen = false;
1715
+ this.settings.isFullOpen = false;
1733
1716
  setTimeout(() => {
1734
1717
  if (this.events.afterClose) {
1735
1718
  this.events.afterClose();
1736
1719
  }
1737
- this.settings.isOpen = false;
1738
1720
  }, this.settings.timeoutDelay);
1739
1721
  if (this.settings.intervalMove) {
1740
1722
  clearInterval(this.settings.intervalMove);
@@ -60,8 +60,7 @@ var SlimSelect = (function () {
60
60
  this.class = [];
61
61
  this.isMultiple = false;
62
62
  this.isOpen = false;
63
- this.isWindowFocused = true;
64
- this.triggerFocus = true;
63
+ this.isFullOpen = false;
65
64
  this.intervalMove = null;
66
65
  if (!settings) {
67
66
  settings = {};
@@ -504,14 +503,10 @@ var SlimSelect = (function () {
504
503
  },
505
504
  };
506
505
  }
507
- mainFocus(trigger, eventType) {
508
- if (!trigger) {
509
- this.settings.triggerFocus = false;
510
- }
506
+ mainFocus(eventType) {
511
507
  if (eventType !== 'click') {
512
508
  this.main.main.focus({ preventScroll: true });
513
509
  }
514
- this.settings.triggerFocus = true;
515
510
  }
516
511
  placeholder() {
517
512
  const placeholderOption = this.store.filter((o) => o.placeholder, false);
@@ -745,7 +740,6 @@ var SlimSelect = (function () {
745
740
  switch (e.key) {
746
741
  case 'ArrowUp':
747
742
  case 'ArrowDown':
748
- this.callbacks.open();
749
743
  e.key === 'ArrowDown' ? this.highlight('down') : this.highlight('up');
750
744
  return false;
751
745
  case 'Tab':
@@ -768,12 +762,6 @@ var SlimSelect = (function () {
768
762
  return false;
769
763
  }
770
764
  };
771
- input.onfocus = () => {
772
- if (this.settings.isOpen) {
773
- return;
774
- }
775
- this.callbacks.open();
776
- };
777
765
  main.appendChild(input);
778
766
  if (this.callbacks.addable) {
779
767
  addable.classList.add(this.classes.addable);
@@ -846,12 +834,8 @@ var SlimSelect = (function () {
846
834
  }
847
835
  return searchReturn;
848
836
  }
849
- searchFocus(trigger) {
850
- if (!trigger) {
851
- this.settings.triggerFocus = false;
852
- }
837
+ searchFocus() {
853
838
  this.content.search.input.focus();
854
- this.settings.triggerFocus = true;
855
839
  }
856
840
  getOptions(notPlaceholder = false, notDisabled = false, notHidden = false) {
857
841
  let query = '.' + this.classes.option;
@@ -1508,13 +1492,13 @@ var SlimSelect = (function () {
1508
1492
  afterClose: undefined,
1509
1493
  };
1510
1494
  this.windowResize = debounce(() => {
1511
- if (!this.settings.isOpen) {
1495
+ if (!this.settings.isOpen && !this.settings.isFullOpen) {
1512
1496
  return;
1513
1497
  }
1514
1498
  this.render.moveContent();
1515
1499
  });
1516
1500
  this.windowScroll = debounce(() => {
1517
- if (!this.settings.isOpen) {
1501
+ if (!this.settings.isOpen && !this.settings.isFullOpen) {
1518
1502
  return;
1519
1503
  }
1520
1504
  this.render.moveContent();
@@ -1529,14 +1513,8 @@ var SlimSelect = (function () {
1529
1513
  };
1530
1514
  this.windowVisibilityChange = () => {
1531
1515
  if (document.hidden) {
1532
- this.settings.isWindowFocused = false;
1533
1516
  this.close();
1534
1517
  }
1535
- else {
1536
- setTimeout(() => {
1537
- this.settings.isWindowFocused = true;
1538
- }, 20);
1539
- }
1540
1518
  };
1541
1519
  this.selectEl = (typeof config.select === 'string' ? document.querySelector(config.select) : config.select);
1542
1520
  if (!this.selectEl) {
@@ -1706,13 +1684,16 @@ var SlimSelect = (function () {
1706
1684
  }
1707
1685
  this.render.open();
1708
1686
  if (this.settings.showSearch) {
1709
- this.render.searchFocus(false);
1687
+ this.render.searchFocus();
1710
1688
  }
1689
+ this.settings.isOpen = true;
1711
1690
  setTimeout(() => {
1712
1691
  if (this.events.afterOpen) {
1713
1692
  this.events.afterOpen();
1714
1693
  }
1715
- this.settings.isOpen = true;
1694
+ if (this.settings.isOpen) {
1695
+ this.settings.isFullOpen = true;
1696
+ }
1716
1697
  }, this.settings.timeoutDelay);
1717
1698
  if (this.settings.contentPosition === 'absolute') {
1718
1699
  if (this.settings.intervalMove) {
@@ -1732,12 +1713,13 @@ var SlimSelect = (function () {
1732
1713
  if (this.render.content.search.input.value !== '') {
1733
1714
  this.search('');
1734
1715
  }
1735
- this.render.mainFocus(false, eventType);
1716
+ this.render.mainFocus(eventType);
1717
+ this.settings.isOpen = false;
1718
+ this.settings.isFullOpen = false;
1736
1719
  setTimeout(() => {
1737
1720
  if (this.events.afterClose) {
1738
1721
  this.events.afterClose();
1739
1722
  }
1740
- this.settings.isOpen = false;
1741
1723
  }, this.settings.timeoutDelay);
1742
1724
  if (this.settings.intervalMove) {
1743
1725
  clearInterval(this.settings.intervalMove);
@@ -63,8 +63,7 @@
63
63
  this.class = [];
64
64
  this.isMultiple = false;
65
65
  this.isOpen = false;
66
- this.isWindowFocused = true;
67
- this.triggerFocus = true;
66
+ this.isFullOpen = false;
68
67
  this.intervalMove = null;
69
68
  if (!settings) {
70
69
  settings = {};
@@ -507,14 +506,10 @@
507
506
  },
508
507
  };
509
508
  }
510
- mainFocus(trigger, eventType) {
511
- if (!trigger) {
512
- this.settings.triggerFocus = false;
513
- }
509
+ mainFocus(eventType) {
514
510
  if (eventType !== 'click') {
515
511
  this.main.main.focus({ preventScroll: true });
516
512
  }
517
- this.settings.triggerFocus = true;
518
513
  }
519
514
  placeholder() {
520
515
  const placeholderOption = this.store.filter((o) => o.placeholder, false);
@@ -748,7 +743,6 @@
748
743
  switch (e.key) {
749
744
  case 'ArrowUp':
750
745
  case 'ArrowDown':
751
- this.callbacks.open();
752
746
  e.key === 'ArrowDown' ? this.highlight('down') : this.highlight('up');
753
747
  return false;
754
748
  case 'Tab':
@@ -771,12 +765,6 @@
771
765
  return false;
772
766
  }
773
767
  };
774
- input.onfocus = () => {
775
- if (this.settings.isOpen) {
776
- return;
777
- }
778
- this.callbacks.open();
779
- };
780
768
  main.appendChild(input);
781
769
  if (this.callbacks.addable) {
782
770
  addable.classList.add(this.classes.addable);
@@ -849,12 +837,8 @@
849
837
  }
850
838
  return searchReturn;
851
839
  }
852
- searchFocus(trigger) {
853
- if (!trigger) {
854
- this.settings.triggerFocus = false;
855
- }
840
+ searchFocus() {
856
841
  this.content.search.input.focus();
857
- this.settings.triggerFocus = true;
858
842
  }
859
843
  getOptions(notPlaceholder = false, notDisabled = false, notHidden = false) {
860
844
  let query = '.' + this.classes.option;
@@ -1511,13 +1495,13 @@
1511
1495
  afterClose: undefined,
1512
1496
  };
1513
1497
  this.windowResize = debounce(() => {
1514
- if (!this.settings.isOpen) {
1498
+ if (!this.settings.isOpen && !this.settings.isFullOpen) {
1515
1499
  return;
1516
1500
  }
1517
1501
  this.render.moveContent();
1518
1502
  });
1519
1503
  this.windowScroll = debounce(() => {
1520
- if (!this.settings.isOpen) {
1504
+ if (!this.settings.isOpen && !this.settings.isFullOpen) {
1521
1505
  return;
1522
1506
  }
1523
1507
  this.render.moveContent();
@@ -1532,14 +1516,8 @@
1532
1516
  };
1533
1517
  this.windowVisibilityChange = () => {
1534
1518
  if (document.hidden) {
1535
- this.settings.isWindowFocused = false;
1536
1519
  this.close();
1537
1520
  }
1538
- else {
1539
- setTimeout(() => {
1540
- this.settings.isWindowFocused = true;
1541
- }, 20);
1542
- }
1543
1521
  };
1544
1522
  this.selectEl = (typeof config.select === 'string' ? document.querySelector(config.select) : config.select);
1545
1523
  if (!this.selectEl) {
@@ -1709,13 +1687,16 @@
1709
1687
  }
1710
1688
  this.render.open();
1711
1689
  if (this.settings.showSearch) {
1712
- this.render.searchFocus(false);
1690
+ this.render.searchFocus();
1713
1691
  }
1692
+ this.settings.isOpen = true;
1714
1693
  setTimeout(() => {
1715
1694
  if (this.events.afterOpen) {
1716
1695
  this.events.afterOpen();
1717
1696
  }
1718
- this.settings.isOpen = true;
1697
+ if (this.settings.isOpen) {
1698
+ this.settings.isFullOpen = true;
1699
+ }
1719
1700
  }, this.settings.timeoutDelay);
1720
1701
  if (this.settings.contentPosition === 'absolute') {
1721
1702
  if (this.settings.intervalMove) {
@@ -1735,12 +1716,13 @@
1735
1716
  if (this.render.content.search.input.value !== '') {
1736
1717
  this.search('');
1737
1718
  }
1738
- this.render.mainFocus(false, eventType);
1719
+ this.render.mainFocus(eventType);
1720
+ this.settings.isOpen = false;
1721
+ this.settings.isFullOpen = false;
1739
1722
  setTimeout(() => {
1740
1723
  if (this.events.afterClose) {
1741
1724
  this.events.afterClose();
1742
1725
  }
1743
- this.settings.isOpen = false;
1744
1726
  }, this.settings.timeoutDelay);
1745
1727
  if (this.settings.intervalMove) {
1746
1728
  clearInterval(this.settings.intervalMove);