@westpac/ui 1.13.0 → 1.14.0
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.
|
@@ -21,25 +21,38 @@ export const PassCode = forwardRef(({ length, value, onChange, onComplete, onPas
|
|
|
21
21
|
}
|
|
22
22
|
}));
|
|
23
23
|
const handleChange = useCallback((index, event)=>{
|
|
24
|
-
const inputValue = event.target.value
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
24
|
+
const inputValue = event.target.value;
|
|
25
|
+
const validData = inputValue.split('').filter((char)=>{
|
|
26
|
+
if (type === 'numbers') return /^\d$/.test(char);
|
|
27
|
+
if (type === 'letters') return /^[a-zA-Z]$/.test(char);
|
|
28
|
+
return /^[a-zA-Z0-9]$/.test(char);
|
|
29
|
+
}).slice(0, length - index);
|
|
30
|
+
if (validData.length === 0) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const previousSlice = passcode.slice(0, index);
|
|
34
|
+
const afterSlice = passcode.slice(index);
|
|
35
|
+
const newPasscode = [
|
|
36
|
+
...previousSlice,
|
|
37
|
+
...[
|
|
38
|
+
...validData,
|
|
39
|
+
...afterSlice.slice(validData.length)
|
|
40
|
+
]
|
|
41
|
+
].slice(0, length);
|
|
42
|
+
if (onChange) {
|
|
43
|
+
onChange(newPasscode);
|
|
44
|
+
} else {
|
|
45
|
+
setInternalPasscode(newPasscode);
|
|
46
|
+
}
|
|
47
|
+
if (index + validData.length < length) {
|
|
48
|
+
var _inputRefs_current_;
|
|
49
|
+
(_inputRefs_current_ = inputRefs.current[index + validData.length]) === null || _inputRefs_current_ === void 0 ? void 0 : _inputRefs_current_.focus();
|
|
50
|
+
} else {
|
|
51
|
+
var _inputRefs_current_1;
|
|
52
|
+
(_inputRefs_current_1 = inputRefs.current[index + validData.length - 1]) === null || _inputRefs_current_1 === void 0 ? void 0 : _inputRefs_current_1.focus();
|
|
53
|
+
}
|
|
54
|
+
if (newPasscode.filter((passcode)=>!passcode).length === 0 && onComplete) {
|
|
55
|
+
onComplete(newPasscode.join(''));
|
|
43
56
|
}
|
|
44
57
|
}, [
|
|
45
58
|
passcode,
|
|
@@ -51,11 +64,11 @@ export const PassCode = forwardRef(({ length, value, onChange, onComplete, onPas
|
|
|
51
64
|
const handlePaste = useCallback((index, event)=>{
|
|
52
65
|
event.preventDefault();
|
|
53
66
|
const pastedData = event.clipboardData.getData('text');
|
|
54
|
-
const validData = pastedData.
|
|
67
|
+
const validData = pastedData.split('').filter((char)=>{
|
|
55
68
|
if (type === 'numbers') return /^\d$/.test(char);
|
|
56
69
|
if (type === 'letters') return /^[a-zA-Z]$/.test(char);
|
|
57
70
|
return /^[a-zA-Z0-9]$/.test(char);
|
|
58
|
-
});
|
|
71
|
+
}).slice(0, length - index);
|
|
59
72
|
const previousSlice = passcode.slice(0, index);
|
|
60
73
|
const afterSlice = passcode.slice(index);
|
|
61
74
|
const newPasscode = [
|
|
@@ -70,6 +83,13 @@ export const PassCode = forwardRef(({ length, value, onChange, onComplete, onPas
|
|
|
70
83
|
} else {
|
|
71
84
|
setInternalPasscode(newPasscode);
|
|
72
85
|
}
|
|
86
|
+
if (index + validData.length < length) {
|
|
87
|
+
var _inputRefs_current_;
|
|
88
|
+
(_inputRefs_current_ = inputRefs.current[index + validData.length]) === null || _inputRefs_current_ === void 0 ? void 0 : _inputRefs_current_.focus();
|
|
89
|
+
} else {
|
|
90
|
+
var _inputRefs_current_1;
|
|
91
|
+
(_inputRefs_current_1 = inputRefs.current[index + validData.length - 1]) === null || _inputRefs_current_1 === void 0 ? void 0 : _inputRefs_current_1.focus();
|
|
92
|
+
}
|
|
73
93
|
if (newPasscode.filter((passcode)=>!passcode).length === 0) {
|
|
74
94
|
if (onPasteComplete) {
|
|
75
95
|
onPasteComplete(newPasscode.join(''));
|
package/package.json
CHANGED
|
@@ -51,26 +51,41 @@ export const PassCode = forwardRef<PassCodeRef, PassCodeProps>(
|
|
|
51
51
|
|
|
52
52
|
const handleChange = useCallback(
|
|
53
53
|
(index: number, event: ChangeEvent<HTMLInputElement>) => {
|
|
54
|
-
const inputValue = event.target.value
|
|
55
|
-
|
|
56
|
-
(
|
|
57
|
-
(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
} else {
|
|
64
|
-
setInternalPasscode(newPasscode);
|
|
65
|
-
}
|
|
54
|
+
const inputValue = event.target.value;
|
|
55
|
+
const validData = inputValue
|
|
56
|
+
.split('')
|
|
57
|
+
.filter(char => {
|
|
58
|
+
if (type === 'numbers') return /^\d$/.test(char);
|
|
59
|
+
if (type === 'letters') return /^[a-zA-Z]$/.test(char);
|
|
60
|
+
return /^[a-zA-Z0-9]$/.test(char);
|
|
61
|
+
})
|
|
62
|
+
.slice(0, length - index);
|
|
66
63
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
if (validData.length === 0) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const previousSlice = passcode.slice(0, index);
|
|
69
|
+
const afterSlice = passcode.slice(index);
|
|
70
|
+
const newPasscode = [...previousSlice, ...[...validData, ...afterSlice.slice(validData.length)]].slice(
|
|
71
|
+
0,
|
|
72
|
+
length,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
if (onChange) {
|
|
76
|
+
onChange(newPasscode);
|
|
77
|
+
} else {
|
|
78
|
+
setInternalPasscode(newPasscode);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Move to the next input if available
|
|
82
|
+
if (index + validData.length < length) {
|
|
83
|
+
inputRefs.current[index + validData.length]?.focus();
|
|
84
|
+
} else {
|
|
85
|
+
inputRefs.current[index + validData.length - 1]?.focus();
|
|
86
|
+
}
|
|
87
|
+
if (newPasscode.filter(passcode => !passcode).length === 0 && onComplete) {
|
|
88
|
+
onComplete(newPasscode.join(''));
|
|
74
89
|
}
|
|
75
90
|
},
|
|
76
91
|
[passcode, length, onChange, onComplete, type],
|
|
@@ -81,13 +96,13 @@ export const PassCode = forwardRef<PassCodeRef, PassCodeProps>(
|
|
|
81
96
|
event.preventDefault();
|
|
82
97
|
const pastedData = event.clipboardData.getData('text');
|
|
83
98
|
const validData = pastedData
|
|
84
|
-
.slice(0, length - index)
|
|
85
99
|
.split('')
|
|
86
100
|
.filter(char => {
|
|
87
101
|
if (type === 'numbers') return /^\d$/.test(char);
|
|
88
102
|
if (type === 'letters') return /^[a-zA-Z]$/.test(char);
|
|
89
103
|
return /^[a-zA-Z0-9]$/.test(char);
|
|
90
|
-
})
|
|
104
|
+
})
|
|
105
|
+
.slice(0, length - index);
|
|
91
106
|
const previousSlice = passcode.slice(0, index);
|
|
92
107
|
const afterSlice = passcode.slice(index);
|
|
93
108
|
const newPasscode = [...previousSlice, ...[...validData, ...afterSlice.slice(validData.length)]].slice(
|
|
@@ -99,6 +114,14 @@ export const PassCode = forwardRef<PassCodeRef, PassCodeProps>(
|
|
|
99
114
|
} else {
|
|
100
115
|
setInternalPasscode(newPasscode);
|
|
101
116
|
}
|
|
117
|
+
|
|
118
|
+
// Move to the next input if available
|
|
119
|
+
if (index + validData.length < length) {
|
|
120
|
+
inputRefs.current[index + validData.length]?.focus();
|
|
121
|
+
} else {
|
|
122
|
+
inputRefs.current[index + validData.length - 1]?.focus();
|
|
123
|
+
}
|
|
124
|
+
|
|
102
125
|
if (newPasscode.filter(passcode => !passcode).length === 0) {
|
|
103
126
|
if (onPasteComplete) {
|
|
104
127
|
onPasteComplete(newPasscode.join(''));
|