@ecohouse/ui 0.1.62 → 0.1.63
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/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/VerificationCodeInput/VerificationCodeInput.test.ts +14 -0
- package/src/components/VerificationCodeInput/VerificationCodeInput.utils.ts +6 -1
package/package.json
CHANGED
|
@@ -32,6 +32,20 @@ describe("updateVerificationCells", () => {
|
|
|
32
32
|
});
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
+
it("lays a whole pasted code out from the start when a later cell has focus", () => {
|
|
36
|
+
expect(updateVerificationCells(toVerificationCells("", 6), 4, "123456", 6)).toEqual({
|
|
37
|
+
cells: ["1", "2", "3", "4", "5", "6"],
|
|
38
|
+
nextFocus: 5,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("still fills forward when the pasted digits fit from the focused cell", () => {
|
|
43
|
+
expect(updateVerificationCells(toVerificationCells("12", 6), 2, "3456", 6)).toEqual({
|
|
44
|
+
cells: ["1", "2", "3", "4", "5", "6"],
|
|
45
|
+
nextFocus: 5,
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
35
49
|
it("replaces a selected digit without growing the code", () => {
|
|
36
50
|
expect(updateVerificationCells(toVerificationCells("123456", 6), 2, "9", 6)).toEqual({
|
|
37
51
|
cells: ["1", "2", "9", "4", "5", "6"],
|
|
@@ -51,11 +51,16 @@ export function updateVerificationCells(
|
|
|
51
51
|
length: number,
|
|
52
52
|
): VerificationCellsUpdate {
|
|
53
53
|
const safeLength = Math.max(1, length);
|
|
54
|
-
const
|
|
54
|
+
const focusedIndex = Math.min(Math.max(0, index), safeLength - 1);
|
|
55
55
|
const cells = Array.from({ length: safeLength }, (_, cellIndex) => {
|
|
56
56
|
const cell = currentCells[cellIndex] ?? "";
|
|
57
57
|
return /^\d$/.test(cell) ? cell : "";
|
|
58
58
|
});
|
|
59
|
+
// A paste that does not fit from the focused cell (typically a whole code pasted while a
|
|
60
|
+
// later cell has focus) is laid out from the first cell instead of being cut to the tail.
|
|
61
|
+
const pastedDigits = input.replace(/\D/g, "");
|
|
62
|
+
const safeIndex =
|
|
63
|
+
pastedDigits.length > 1 && pastedDigits.length > safeLength - focusedIndex ? 0 : focusedIndex;
|
|
59
64
|
const insertedDigits = normalizeVerificationCode(input, safeLength - safeIndex);
|
|
60
65
|
|
|
61
66
|
if (!insertedDigits) {
|