@brandup/ui-dropdown 1.0.38 → 1.0.40

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 +11 -19
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.38",
27
+ "version": "1.0.40",
28
28
  "main": "source/index.ts",
29
29
  "types": "source/index.ts",
30
30
  "dependencies": {
31
31
  "@brandup/ui": "^2.0.7",
32
32
  "@brandup/ui-helpers": "^2.0.7",
33
- "@brandup/ui-input": "^1.0.38",
34
- "@brandup/ui-kit": "^1.0.38"
33
+ "@brandup/ui-input": "^1.0.40",
34
+ "@brandup/ui-kit": "^1.0.40"
35
35
  },
36
36
  "files": [
37
37
  "source",
@@ -44,8 +44,6 @@ class DropDown extends InputControl<HTMLSelectElement, DropDownEvents> {
44
44
  readonly searchOn: number | boolean;
45
45
 
46
46
  constructor(selectElem: HTMLSelectElement) {
47
- selectElem.classList.add(INPUT_CLASS);
48
-
49
47
  const placeholder = selectElem.getAttribute("data-placeholder") || "Select";
50
48
  const emptyText = selectElem.getAttribute("data-emptytext") || "Empty list";
51
49
  const searchPlaceholder = selectElem.getAttribute("data-search-placeholder") || "Search";
@@ -97,12 +95,12 @@ class DropDown extends InputControl<HTMLSelectElement, DropDownEvents> {
97
95
  ]),
98
96
  ]);
99
97
 
100
- const container = DOM.tag("div", { class: [ROOT_CLASS].concat(Array.from(selectElem.classList)) }, [
98
+ const container = DOM.tag("div", { class: ROOT_CLASS }, [
101
99
  DOM.tag("button", { class: "view", command: "open-popup" }, [textElem, arrowBottomIcon]),
102
100
  popupElem,
103
101
  ]);
104
102
 
105
- container.classList.remove(INPUT_CLASS);
103
+ DropDown.prepareValueElem(selectElem, container, INPUT_CLASS);
106
104
 
107
105
  if (selectElem.nextElementSibling) {
108
106
  const nextElem = selectElem.nextElementSibling as HTMLElement;
@@ -112,7 +110,8 @@ class DropDown extends InputControl<HTMLSelectElement, DropDownEvents> {
112
110
  selectElem.insertAdjacentElement("beforebegin", container);
113
111
  container.insertAdjacentElement("beforeend", selectElem);
114
112
 
115
- super("BrandUp.DropDown", container, selectElem);
113
+ // класс вернёт базовый класс при destroy — без этого поле осталось бы скрытым
114
+ super("BrandUp.DropDown", container, selectElem, { class: INPUT_CLASS });
116
115
 
117
116
  this.placeholder = placeholder;
118
117
  this.emptyText = emptyText;
@@ -487,28 +486,21 @@ class DropDown extends InputControl<HTMLSelectElement, DropDownEvents> {
487
486
  return (selected && selected.own.firstElementChild?.textContent?.trim()) || null;
488
487
  }
489
488
 
489
+ // Правила проверяет браузер по атрибутам самого select; контрол отражает результат классом.
490
+ // Обязательность закрывает нативный required — для этого у пустого пункта value должно
491
+ // быть пустым, как и требует стандарт.
490
492
  override validate(): boolean {
491
- const value = this.getValue();
492
- let isInvalid = !this.__valueElem.validity.valid;
493
-
494
- if (this.required && !value) isInvalid = true;
493
+ const isValid = super.validate();
495
494
 
496
- const clearInvalid = () => this.element.classList.remove("invalid");
495
+ this.element.classList.toggle("invalid", !isValid);
497
496
 
498
- if (isInvalid) {
499
- this.element.classList.add("invalid");
500
- } else clearInvalid();
501
-
502
- return !isInvalid;
497
+ return isValid;
503
498
  }
504
499
 
505
500
  override destroy(): void {
506
501
  this.__closePopup();
507
502
 
508
- this.element.insertAdjacentElement("afterend", this.__valueElem);
509
- this.element.remove();
510
-
511
- super.destroy();
503
+ super.destroy(); // снимет слушатели формы и вернёт поле-носитель в исходный вид
512
504
  }
513
505
  }
514
506