@brandup/ui-textbox 1.0.53 → 1.0.54

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/README.md CHANGED
@@ -49,7 +49,8 @@ textbox.on(CHANGE_EVENT, (data: ChangeEventData) => {
49
49
  | Атрибут | Описание |
50
50
  | --- | --- |
51
51
  | `data-symbolcounter` | Показывает счётчик введённых символов (и максимума, если задан `maxlength`) |
52
- | `data-autofocus` | Автофокус при инициализации (игнорируется на touch-устройствах) |
52
+ | `data-autofocus` | Автофокус при инициализации; то же делает нативный `autofocus`. Отменяется, если поле выключено или только для чтения, вводят пальцем, пользователь уже прокрутил страницу либо фокус занят другим полем ввода |
53
+ | `data-caret` | Куда встаёт каретка при фокусе из кода — автофокусом или вызовом `focus()`: `end` (по умолчанию), `start`, `all` (выделить весь текст) |
53
54
  | `data-copy-button` | Добавляет кнопку копирования значения в буфер обмена |
54
55
  | `data-allow-empty-strings` | Разрешает значение из одних пробелов |
55
56
  | `data-readonly` | Альтернативный способ задать режим только для чтения |
package/package.json CHANGED
@@ -24,15 +24,15 @@
24
24
  "email": "it@brandup.online"
25
25
  },
26
26
  "license": "Apache-2.0",
27
- "version": "1.0.53",
27
+ "version": "1.0.54",
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.53",
34
- "@brandup/ui-kit": "^1.0.53",
35
- "@brandup/ui-richeditor": "^1.0.53"
33
+ "@brandup/ui-input": "^1.0.54",
34
+ "@brandup/ui-kit": "^1.0.54",
35
+ "@brandup/ui-richeditor": "^1.0.54"
36
36
  },
37
37
  "files": [
38
38
  "source",
package/source/textbox.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./textbox.less"; // стили компонента
2
2
 
3
- import { EditorInputControl } from "@brandup/ui-input";
4
- import { IS_TOUCH_DEVICE, POPUP_CLASS, SCROLLABLE_CLASS } from "@brandup/ui-kit";
3
+ import { EditorInputControl, parseFocusCaret } from "@brandup/ui-input";
4
+ import { POPUP_CLASS, SCROLLABLE_CLASS } from "@brandup/ui-kit";
5
5
  import { DOM } from "@brandup/ui";
6
6
  import { FuncHelper } from "@brandup/ui-helpers";
7
7
  import RichEditor, {
@@ -48,7 +48,6 @@ export default class TextBox extends EditorInputControl<RichEditor, ChangeEventD
48
48
  readonly maxlength: number;
49
49
  readonly inputmode: string;
50
50
  readonly symbolCounter: boolean;
51
- readonly autoFocus: boolean;
52
51
  readonly format: boolean;
53
52
  readonly formatStorage: FormatStorage;
54
53
  readonly formatTools: FormatTool[];
@@ -91,7 +90,8 @@ export default class TextBox extends EditorInputControl<RichEditor, ChangeEventD
91
90
 
92
91
  const maxlength = valueElem.maxLength;
93
92
  const symbolCounter = valueElem.hasAttribute("data-symbolcounter");
94
- const autoFocus = valueElem.hasAttribute("data-autofocus");
93
+ // куда встаёт каретка при фокусе из кода: data-caret="start|end|all", по умолчанию в конец
94
+ const caret = parseFocusCaret(valueElem.dataset.caret);
95
95
  const allowEmptyStrings = valueElem.hasAttribute("data-allow-empty-strings");
96
96
  const placeholder = valueElem.getAttribute("placeholder");
97
97
  const inputmode = valueElem.inputMode;
@@ -163,13 +163,12 @@ export default class TextBox extends EditorInputControl<RichEditor, ChangeEventD
163
163
  container,
164
164
  valueElem,
165
165
  { class: INPUT_CLASS, attrs: originalAttrs },
166
- { changeEvent: CHANGE_EVENT }
166
+ { changeEvent: CHANGE_EVENT, caret }
167
167
  );
168
168
 
169
169
  this.type = type;
170
170
  this.maxlength = maxlength;
171
171
  this.symbolCounter = symbolCounter;
172
- this.autoFocus = autoFocus;
173
172
  this.allowEmptyStrings = allowEmptyStrings;
174
173
  this.placeholder = placeholder;
175
174
  this.inputmode = inputmode;
@@ -259,7 +258,7 @@ export default class TextBox extends EditorInputControl<RichEditor, ChangeEventD
259
258
  // не дожидаясь первой синхронизации
260
259
  this.__refreshValidity();
261
260
 
262
- if (this.autoFocus && !IS_TOUCH_DEVICE && !disabled && !readonly) this.__editor.focus();
261
+ this.__applyAutoFocus(); // автофокус вместе с прокруткой к полю; условия у базового класса
263
262
  }
264
263
 
265
264
  private __initLogic() {