fix: patch cursor overflow

This commit is contained in:
cpacker
2025-10-25 14:30:14 -07:00
parent 99f81d8da1
commit a8dff2d86e

View File

@@ -93,12 +93,7 @@ function TextInput({ value: originalValue, placeholder = '', focus = true, mask,
nextCursorWidth = input.length; nextCursorWidth = input.length;
} }
} }
if (cursorOffset < 0) { nextCursorOffset = Math.max(0, Math.min(nextCursorOffset, nextValue.length));
nextCursorOffset = 0;
}
if (cursorOffset > originalValue.length) {
nextCursorOffset = originalValue.length;
}
setState({ cursorOffset: nextCursorOffset, cursorWidth: nextCursorWidth }); setState({ cursorOffset: nextCursorOffset, cursorWidth: nextCursorWidth });
if (typeof onCursorOffsetChange === 'function') onCursorOffsetChange(nextCursorOffset); if (typeof onCursorOffsetChange === 'function') onCursorOffsetChange(nextCursorOffset);
if (nextValue !== originalValue) { if (nextValue !== originalValue) {
@@ -112,4 +107,3 @@ export function UncontrolledTextInput({ initialValue = '', ...props }) {
const [value, setValue] = useState(initialValue); const [value, setValue] = useState(initialValue);
return React.createElement(TextInput, { ...props, value: value, onChange: setValue }); return React.createElement(TextInput, { ...props, value: value, onChange: setValue });
} }