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

selectionStart / selectionEnd are always 0 #62

Closed
urakozz opened this issue Dec 29, 2023 · 6 comments
Closed

selectionStart / selectionEnd are always 0 #62

urakozz opened this issue Dec 29, 2023 · 6 comments

Comments

@urakozz
Copy link

urakozz commented Dec 29, 2023

After this change (most likely) #54, which came into effect with antd 5.12.3, onchange event from the input always has selectionStart / selectionEnd properties set to 0 instead of the actual numbers

We have custom input processing (related to the currency formatting), which worked perfectly for the past 6 years until this change.

Would it be possible to have a look into this issue?

@SleepWalker
Copy link

Faced the same issue with custom phone number input. Event handler need the actual DOM node to handle cursor position.

rc-input creates a copy or original DOM node here https://github.com/react-component/input/blob/master/src/utils/commonUtils.ts#L60-L75. If you'll try to manipulate with that node it won't be reflected on the original node because it's just a copy that even wasn't inserted in DOM and of course it has zero cursor position.

As a temporary solution I using ref and patch the event back:

const inputRef = React.useRef<InputRef>(null);

return (
  <Input onChange={(event) => {
    const currentTarget = inputRef.current!.input;

    event = Object.create(event, {
      target: { value: currentTarget },
      currentTarget: { value: currentTarget },
    });

   handleChange(event);
  }} />
);

@afc163
Copy link
Member

afc163 commented Dec 30, 2023

@yyz945947732 Look at this issue.

@0307kwon
Copy link

0307kwon commented Jan 3, 2024

I have same issue... 😢

@afc163
Copy link
Member

afc163 commented Jan 3, 2024

@yyz945947732 ping~

@afc163
Copy link
Member

afc163 commented Mar 11, 2024

@yyz945947732

@afc163
Copy link
Member

afc163 commented Mar 11, 2024

Fixed in #65

@afc163 afc163 closed this as completed Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants