@verifiedinc-public/shared-ui-elements 0.12.0 → 0.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.
- package/dist/shared-ui-elements.mjs +2359 -2356
- package/package.json +1 -1
- package/src/components/form/OTPInput.tsx +18 -13
package/package.json
CHANGED
@@ -16,7 +16,8 @@ import {
|
|
16
16
|
type StackProps,
|
17
17
|
type SxProps,
|
18
18
|
TextField,
|
19
|
-
|
19
|
+
InputBase,
|
20
|
+
type InputBaseProps,
|
20
21
|
Typography,
|
21
22
|
useTheme,
|
22
23
|
} from '@mui/material';
|
@@ -106,7 +107,7 @@ function OTPInputComponent(
|
|
106
107
|
},
|
107
108
|
},
|
108
109
|
};
|
109
|
-
const inputProps:
|
110
|
+
const inputProps: InputBaseProps = useMemo(
|
110
111
|
() => ({
|
111
112
|
inputProps: {
|
112
113
|
inputMode: 'numeric',
|
@@ -115,14 +116,19 @@ function OTPInputComponent(
|
|
115
116
|
autoCapitalize: 'off',
|
116
117
|
},
|
117
118
|
sx: {
|
118
|
-
|
119
|
+
'& input': {
|
120
|
+
borderRadius: 1,
|
121
|
+
borderStyle: 'solid',
|
122
|
+
borderColor: 'rgba(0, 0, 0, 0.23)',
|
123
|
+
borderWidth: 1,
|
124
|
+
},
|
119
125
|
...(isFocused && {
|
120
|
-
'
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
borderWidth: 2,
|
126
|
+
'& input': {
|
127
|
+
borderRadius: 1,
|
128
|
+
borderStyle: 'solid',
|
129
|
+
borderWidth: 1,
|
125
130
|
borderColor: theme.palette.primary.main,
|
131
|
+
boxShadow: `inset 0 0 0 1px ${theme.palette.primary.main}`,
|
126
132
|
},
|
127
133
|
}),
|
128
134
|
},
|
@@ -155,6 +161,7 @@ function OTPInputComponent(
|
|
155
161
|
|
156
162
|
// Calls onChange when all OTP fields are filled.
|
157
163
|
if (newValueString.length === 6) {
|
164
|
+
inputsRef.current.forEach((input) => input?.blur());
|
158
165
|
props.onChange?.({ target: { value: newValueString } });
|
159
166
|
}
|
160
167
|
|
@@ -164,7 +171,7 @@ function OTPInputComponent(
|
|
164
171
|
[props],
|
165
172
|
);
|
166
173
|
|
167
|
-
const handleKeyUp = useCallback((event: KeyboardEvent<
|
174
|
+
const handleKeyUp = useCallback((event: KeyboardEvent<HTMLInputElement>) => {
|
168
175
|
if (event.key === 'Backspace') {
|
169
176
|
setValues((prev) => {
|
170
177
|
const newValue = [...prev.slice(0, -1)];
|
@@ -185,7 +192,7 @@ function OTPInputComponent(
|
|
185
192
|
(startIndex: number) => {
|
186
193
|
return new Array(3).fill(undefined).map((_, index) => {
|
187
194
|
return (
|
188
|
-
<
|
195
|
+
<InputBase
|
189
196
|
key={ids.current[index + startIndex]}
|
190
197
|
inputRef={(input) =>
|
191
198
|
((inputsRef.current[index + startIndex] as any) = input)
|
@@ -197,9 +204,7 @@ function OTPInputComponent(
|
|
197
204
|
onChange={handleChange}
|
198
205
|
onKeyUp={handleKeyUp}
|
199
206
|
onFocus={handleFocus}
|
200
|
-
onBlur={() =>
|
201
|
-
setIsFocused(false);
|
202
|
-
}}
|
207
|
+
onBlur={() => setIsFocused(false)}
|
203
208
|
{...inputProps}
|
204
209
|
data-testid={`otp-input-${index + startIndex}`}
|
205
210
|
/>
|