allaw-ui 2.3.7 → 2.3.9
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.
|
@@ -7,6 +7,7 @@ export interface VerificationCodeInputProps {
|
|
|
7
7
|
onError?: (error: string | null) => void;
|
|
8
8
|
onComplete?: (value: string) => void;
|
|
9
9
|
testError?: boolean;
|
|
10
|
+
autoFocus?: boolean;
|
|
10
11
|
}
|
|
11
12
|
declare const VerificationCodeInput: React.FC<VerificationCodeInputProps>;
|
|
12
13
|
export default VerificationCodeInput;
|
|
@@ -11,17 +11,13 @@ import React, { useState, useEffect, useRef } from "react";
|
|
|
11
11
|
import styles from "./VerificationCodeInput.module.css";
|
|
12
12
|
import TinyInfo from "../typography/TinyInfo";
|
|
13
13
|
var VerificationCodeInput = function (_a) {
|
|
14
|
-
var numInputs = _a.numInputs, _b = _a.allowedChars, allowedChars = _b === void 0 ? "numeric" : _b, _c = _a.size, size = _c === void 0 ? "large" : _c, onChange = _a.onChange, onError = _a.onError, onComplete = _a.onComplete, _d = _a.testError, testError = _d === void 0 ? false : _d;
|
|
15
|
-
var
|
|
16
|
-
var
|
|
14
|
+
var numInputs = _a.numInputs, _b = _a.allowedChars, allowedChars = _b === void 0 ? "numeric" : _b, _c = _a.size, size = _c === void 0 ? "large" : _c, onChange = _a.onChange, onError = _a.onError, onComplete = _a.onComplete, _d = _a.testError, testError = _d === void 0 ? false : _d, _e = _a.autoFocus, autoFocus = _e === void 0 ? false : _e;
|
|
15
|
+
var _f = useState(Array(numInputs).fill("")), values = _f[0], setValues = _f[1];
|
|
16
|
+
var _g = useState(""), error = _g[0], setError = _g[1];
|
|
17
17
|
var inputRefs = useRef(Array(numInputs).fill(null));
|
|
18
18
|
useEffect(function () {
|
|
19
19
|
setValues(Array(numInputs).fill(""));
|
|
20
20
|
inputRefs.current = Array(numInputs).fill(null);
|
|
21
|
-
setTimeout(function () {
|
|
22
|
-
var _a;
|
|
23
|
-
(_a = inputRefs.current[0]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
24
|
-
}, 0);
|
|
25
21
|
}, [numInputs]);
|
|
26
22
|
useEffect(function () {
|
|
27
23
|
if (testError) {
|
|
@@ -160,7 +156,7 @@ var VerificationCodeInput = function (_a) {
|
|
|
160
156
|
? "[0-9]*"
|
|
161
157
|
: allowedChars === "alphabetic"
|
|
162
158
|
? "[a-zA-Z]*"
|
|
163
|
-
: "[a-zA-Z0-9]*", ref: function (input) { return (inputRefs.current[index] = input); } })); });
|
|
159
|
+
: "[a-zA-Z0-9]*", ref: function (input) { return (inputRefs.current[index] = input); }, autoFocus: index === 0 && autoFocus, tabIndex: index === 0 ? 0 : undefined })); });
|
|
164
160
|
};
|
|
165
161
|
return (React.createElement("div", { className: styles.container },
|
|
166
162
|
React.createElement("div", { className: styles.inputsContainer }, renderInputs()),
|