@main12/auth-login 0.4.1 → 0.4.2
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/components/ui/index.js +37 -8
- package/package.json +1 -1
|
@@ -94,32 +94,61 @@ export const OtpInput = ({ length = 6, value, onChange, onValueChange, isDisable
|
|
|
94
94
|
const inputs = Array.from({
|
|
95
95
|
length
|
|
96
96
|
}, (_, i)=>i);
|
|
97
|
+
const inputRefs = React.useRef([]);
|
|
98
|
+
const focusInput = (index)=>{
|
|
99
|
+
inputRefs.current[index]?.focus();
|
|
100
|
+
inputRefs.current[index]?.select();
|
|
101
|
+
};
|
|
97
102
|
return /*#__PURE__*/ _jsx("div", {
|
|
98
103
|
className: "flex justify-center gap-2",
|
|
99
104
|
children: inputs.map((i)=>/*#__PURE__*/ _jsx("input", {
|
|
105
|
+
ref: (el)=>{
|
|
106
|
+
inputRefs.current[i] = el;
|
|
107
|
+
},
|
|
100
108
|
type: "text",
|
|
101
109
|
inputMode: "numeric",
|
|
110
|
+
autoComplete: "one-time-code",
|
|
102
111
|
maxLength: 1,
|
|
103
112
|
value: value[i] || '',
|
|
104
113
|
disabled: isDisabled,
|
|
105
114
|
autoFocus: autoFocus && i === 0,
|
|
106
115
|
onChange: (e)=>{
|
|
107
|
-
const char = e.target.value.replace(/[^0-9]/g, '').slice(
|
|
116
|
+
const char = e.target.value.replace(/[^0-9]/g, '').slice(-1);
|
|
108
117
|
const newVal = value.split('');
|
|
109
118
|
newVal[i] = char;
|
|
110
|
-
setValue(newVal.join(''));
|
|
111
|
-
// Auto-focus next
|
|
119
|
+
setValue(newVal.join('').slice(0, length));
|
|
120
|
+
// Auto-focus next input once a digit is entered
|
|
112
121
|
if (char && i < length - 1) {
|
|
113
|
-
|
|
114
|
-
next?.focus();
|
|
122
|
+
focusInput(i + 1);
|
|
115
123
|
}
|
|
116
124
|
},
|
|
117
125
|
onKeyDown: (e)=>{
|
|
118
|
-
if (e.key === 'Backspace'
|
|
119
|
-
|
|
120
|
-
|
|
126
|
+
if (e.key === 'Backspace') {
|
|
127
|
+
if (!value[i] && i > 0) {
|
|
128
|
+
// Empty box — move to previous box and clear it
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
const newVal = value.split('');
|
|
131
|
+
newVal[i - 1] = '';
|
|
132
|
+
setValue(newVal.join(''));
|
|
133
|
+
focusInput(i - 1);
|
|
134
|
+
}
|
|
135
|
+
} else if (e.key === 'ArrowLeft' && i > 0) {
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
focusInput(i - 1);
|
|
138
|
+
} else if (e.key === 'ArrowRight' && i < length - 1) {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
focusInput(i + 1);
|
|
121
141
|
}
|
|
122
142
|
},
|
|
143
|
+
onPaste: (e)=>{
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
const pasted = e.clipboardData.getData('text').replace(/[^0-9]/g, '').slice(0, length);
|
|
146
|
+
if (!pasted) return;
|
|
147
|
+
setValue(pasted);
|
|
148
|
+
const nextIndex = Math.min(pasted.length, length - 1);
|
|
149
|
+
focusInput(nextIndex);
|
|
150
|
+
},
|
|
151
|
+
onFocus: (e)=>e.target.select(),
|
|
123
152
|
className: "w-12 h-14 text-center text-2xl font-semibold text-gray-900 border-2 border-gray-300 rounded-xl focus:border-[#D5E855] focus:ring-2 focus:ring-[#D5E855]/30 outline-none transition-all bg-white"
|
|
124
153
|
}, i))
|
|
125
154
|
});
|
package/package.json
CHANGED