Skip to content

Commit 4b656c8

Browse files
Merge pull request #207 from shayan919293/hotfix/better-state-handling-manual-date
Fixing jumping to the end on textinput
2 parents bc91441 + cb9679b commit 4b656c8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/TextInputMask.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,23 @@ function TextInputWithMask(
7272
value,
7373
mask,
7474
...rest
75-
}: React.ComponentProps<typeof TextInput> & { mask: string },
75+
}: React.ComponentProps<typeof TextInput> & { mask: string; value: string },
7676
ref: any
7777
) {
7878
const [controlledValue, setControlledValue] = React.useState<string>(
7979
value || ''
8080
)
8181

8282
const onInnerChange = (text: string) => {
83-
const enhancedText = enhanceTextWithMask(text, mask, controlledValue)
84-
setControlledValue(enhancedText)
85-
8683
if (text.length === mask.length) {
8784
onChangeText && onChangeText(text)
8885
}
86+
setControlledValue(text)
87+
}
88+
89+
const onInnerBlur = () => {
90+
const enhancedText = enhanceTextWithMask(value, mask, controlledValue)
91+
setControlledValue(enhancedText)
8992
}
9093

9194
React.useEffect(() => {
@@ -98,6 +101,7 @@ function TextInputWithMask(
98101
{...rest}
99102
value={controlledValue}
100103
onChangeText={onInnerChange}
104+
onBlur={onInnerBlur}
101105
/>
102106
)
103107
}

0 commit comments

Comments
 (0)