@brandup/ui-dropdown 1.0.54 → 1.0.55

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/source/dropdown.ts +21 -13
package/package.json CHANGED
@@ -24,14 +24,14 @@
24
24
  "email": "it@brandup.online"
25
25
  },
26
26
  "license": "Apache-2.0",
27
- "version": "1.0.54",
27
+ "version": "1.0.55",
28
28
  "main": "source/index.ts",
29
29
  "types": "source/index.ts",
30
30
  "dependencies": {
31
31
  "@brandup/ui": "^2.0.9",
32
32
  "@brandup/ui-helpers": "^2.0.9",
33
- "@brandup/ui-input": "^1.0.54",
34
- "@brandup/ui-kit": "^1.0.54"
33
+ "@brandup/ui-input": "^1.0.55",
34
+ "@brandup/ui-kit": "^1.0.55"
35
35
  },
36
36
  "files": [
37
37
  "source",
@@ -33,7 +33,9 @@ class DropDown extends InputControl<HTMLSelectElement, DropDownEvents> {
33
33
  private __textElem: HTMLElement;
34
34
  private __emptyElem: HTMLElement;
35
35
  private __searchInput: HTMLInputElement;
36
+ private __pressPopupFunc: (e: MouseEvent) => void;
36
37
  private __closePopupFunc: (e: MouseEvent) => void;
38
+ private __pressedInPopup = false;
37
39
  private __reposAbort?: AbortController;
38
40
  private __hasEmptyValue: boolean = false;
39
41
 
@@ -128,19 +130,22 @@ class DropDown extends InputControl<HTMLSelectElement, DropDownEvents> {
128
130
  this.__emptyElem = emptyElem;
129
131
  this.__searchInput = searchInput;
130
132
 
131
- this.__closePopupFunc = (e: MouseEvent) => {
132
- const t = e.target as HTMLElement;
133
- const dd = t.closest(`.${ROOT_CLASS}`);
134
- if (
135
- !dd ||
136
- (dd === this.__container &&
137
- !t.closest("li[data-index]") &&
138
- t !== this.__searchInput &&
139
- !t.closest(".search"))
140
- ) {
141
- this.__closePopup();
142
- this.__clearSearch();
143
- }
133
+ // Список закрывает нажатие мимо него, и решает это начало нажатия, а не место, где
134
+ // отпустили: перетаскивание полосы прокрутки списка и выделение текста заканчиваются
135
+ // где угодно, а список при этом закрываться не должен.
136
+ this.__pressPopupFunc = (e: MouseEvent) => {
137
+ this.__pressedInPopup = this.__popupElem.contains(e.target as Node);
138
+ };
139
+
140
+ this.__closePopupFunc = () => {
141
+ const pressedInPopup = this.__pressedInPopup;
142
+ this.__pressedInPopup = false; // жест закончился, следующий начнётся со своего нажатия
143
+
144
+ // внутри списка работают с ним самим: прокрутка, поиск, промах мимо пункта
145
+ if (pressedInPopup) return;
146
+
147
+ this.__closePopup();
148
+ this.__clearSearch();
144
149
  };
145
150
 
146
151
  this.__renderItems();
@@ -367,6 +372,7 @@ class DropDown extends InputControl<HTMLSelectElement, DropDownEvents> {
367
372
 
368
373
  this.__listElem.scrollTo({ left: 0, top: top, behavior: "instant" });
369
374
 
375
+ document.body.addEventListener("mousedown", this.__pressPopupFunc);
370
376
  document.body.addEventListener("mouseup", this.__closePopupFunc);
371
377
  }
372
378
 
@@ -388,8 +394,10 @@ class DropDown extends InputControl<HTMLSelectElement, DropDownEvents> {
388
394
  }
389
395
 
390
396
  private __closePopup() {
397
+ this.__pressedInPopup = false; // от прошлого показа не наследуем
391
398
  document.body.classList.remove(BODY_EXPANDED);
392
399
  this.element.classList.remove("expanded");
400
+ document.body.removeEventListener("mousedown", this.__pressPopupFunc);
393
401
  document.body.removeEventListener("mouseup", this.__closePopupFunc);
394
402
  this.__reposAbort?.abort();
395
403
  this.__reposAbort = undefined;