Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@mantine/core] fix: NumberInput cursor position #6004

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef } from 'react';
import React, { useEffect, useRef } from 'react';
import cx from 'clsx';
import { NumberFormatValues, NumericFormat, OnValueChange } from 'react-number-format';
import { assignRef, clamp, useMergedRef, useUncontrolled } from '@mantine/hooks';
Expand Down Expand Up @@ -358,6 +358,13 @@ export const NumberInput = factory<NumberInputFactory>((_props, ref) => {
stepCountRef.current = 0;
};

useEffect(() => {
if (inputRef.current) {
const { length } = inputRef.current.value;
inputRef.current.setSelectionRange(length, length);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if user wants to edit value in the middle, for example 251{cursor}213, when anything is entered the selection range is moved to the end – this is unexpected behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I've fixed this issue at f49af28. by this change, the position of cusor only changes when decrement/increment. I'll be happy if you check this change is Ok :)

}, [_value]);

const controls = (
<div {...getStyles('controls')}>
<UnstyledButton
Expand Down
Loading