@westpac/ui 1.13.0 → 1.13.1
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,35 @@ 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
|
+
}
|
|
51
|
+
if (newPasscode.filter((passcode)=>!passcode).length === 0 && onComplete) {
|
|
52
|
+
onComplete(newPasscode.join(''));
|
|
43
53
|
}
|
|
44
54
|
}, [
|
|
45
55
|
passcode,
|
|
@@ -51,11 +61,11 @@ export const PassCode = forwardRef(({ length, value, onChange, onComplete, onPas
|
|
|
51
61
|
const handlePaste = useCallback((index, event)=>{
|
|
52
62
|
event.preventDefault();
|
|
53
63
|
const pastedData = event.clipboardData.getData('text');
|
|
54
|
-
const validData = pastedData.
|
|
64
|
+
const validData = pastedData.split('').filter((char)=>{
|
|
55
65
|
if (type === 'numbers') return /^\d$/.test(char);
|
|
56
66
|
if (type === 'letters') return /^[a-zA-Z]$/.test(char);
|
|
57
67
|
return /^[a-zA-Z0-9]$/.test(char);
|
|
58
|
-
});
|
|
68
|
+
}).slice(0, length - index);
|
|
59
69
|
const previousSlice = passcode.slice(0, index);
|
|
60
70
|
const afterSlice = passcode.slice(index);
|
|
61
71
|
const newPasscode = [
|
package/package.json
CHANGED
|
@@ -51,26 +51,39 @@ 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
|
+
}
|
|
85
|
+
if (newPasscode.filter(passcode => !passcode).length === 0 && onComplete) {
|
|
86
|
+
onComplete(newPasscode.join(''));
|
|
74
87
|
}
|
|
75
88
|
},
|
|
76
89
|
[passcode, length, onChange, onComplete, type],
|
|
@@ -81,13 +94,13 @@ export const PassCode = forwardRef<PassCodeRef, PassCodeProps>(
|
|
|
81
94
|
event.preventDefault();
|
|
82
95
|
const pastedData = event.clipboardData.getData('text');
|
|
83
96
|
const validData = pastedData
|
|
84
|
-
.slice(0, length - index)
|
|
85
97
|
.split('')
|
|
86
98
|
.filter(char => {
|
|
87
99
|
if (type === 'numbers') return /^\d$/.test(char);
|
|
88
100
|
if (type === 'letters') return /^[a-zA-Z]$/.test(char);
|
|
89
101
|
return /^[a-zA-Z0-9]$/.test(char);
|
|
90
|
-
})
|
|
102
|
+
})
|
|
103
|
+
.slice(0, length - index);
|
|
91
104
|
const previousSlice = passcode.slice(0, index);
|
|
92
105
|
const afterSlice = passcode.slice(index);
|
|
93
106
|
const newPasscode = [...previousSlice, ...[...validData, ...afterSlice.slice(validData.length)]].slice(
|