ar-design 0.3.69 → 0.3.70

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.
@@ -4,16 +4,23 @@ import Input from "..";
4
4
  const Otp = ({ character, onChange, ...attributes }) => {
5
5
  // refs
6
6
  const _inputs = useRef([]);
7
+ const _isPasteCombo = useRef(false);
7
8
  const _value = useRef({});
8
9
  // methods
9
10
  const handleInput = useCallback((index) => (event) => {
10
11
  if (attributes.disabled)
11
12
  return;
13
+ if (_isPasteCombo.current)
14
+ return;
12
15
  let { value } = event.currentTarget;
13
16
  _value.current = { ..._value.current, [index]: value };
14
17
  if (value.length >= 1) {
18
+ if (!_inputs.current[index + 1]) {
19
+ _inputs.current[character - 1]?.focus();
20
+ _inputs.current[character - 1]?.select();
21
+ return;
22
+ }
15
23
  _inputs.current[index + 1]?.focus();
16
- _inputs.current[index + 1]?.select();
17
24
  }
18
25
  onChange?.({
19
26
  ...event,
@@ -30,14 +37,34 @@ const Otp = ({ character, onChange, ...attributes }) => {
30
37
  const handleKeyUp = useCallback((index) => (event) => {
31
38
  const input = event.currentTarget;
32
39
  const { value } = input;
40
+ const beforeInput = _inputs.current[index];
41
+ // referans
42
+ const beforeInputValue = beforeInput.value;
43
+ if (beforeInputValue.length > 1) {
44
+ let i = 0;
45
+ const chars = beforeInputValue.split("");
46
+ const interval = setInterval(() => {
47
+ const input = _inputs.current[i];
48
+ if (input) {
49
+ input.value = chars[i];
50
+ input.focus();
51
+ }
52
+ i++;
53
+ if (i >= chars.length)
54
+ clearInterval(interval);
55
+ }, 50);
56
+ return;
57
+ }
33
58
  const lastChar = value.slice(-1);
34
59
  event.currentTarget.value = lastChar;
35
60
  if (event.key === "Backspace" && value.length === 0) {
36
61
  _inputs.current[index - 1]?.focus();
37
- _inputs.current[index - 1]?.select();
38
62
  }
39
63
  }, []);
40
- const handleKeyDown = (index) => (event) => {
64
+ const handleKeyDown = useCallback((index) => (event) => {
65
+ _isPasteCombo.current = (event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "v";
66
+ if (_isPasteCombo.current)
67
+ return;
41
68
  if (index === 0 && (event.key === "ArrowDown" || event.key === "ArrowLeft"))
42
69
  event.preventDefault();
43
70
  if (index + 1 >= character && (event.key === "ArrowUp" || event.key === "ArrowRight"))
@@ -52,7 +79,7 @@ const Otp = ({ character, onChange, ...attributes }) => {
52
79
  _inputs.current[index + 1]?.focus();
53
80
  setTimeout(() => _inputs.current[index + 1]?.select(), 0);
54
81
  }
55
- };
82
+ }, [character]);
56
83
  const handleClick = useCallback((event) => {
57
84
  const input = event.currentTarget;
58
85
  if (document.activeElement === input)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ar-design",
3
- "version": "0.3.69",
3
+ "version": "0.3.70",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",