Skip to content

Conversation

kasperdun
Copy link

@kasperdun kasperdun commented Mar 7, 2024

Describe the issue/change

When I use react-hook-form with react-number-format
And I'm trying to implement a dynamic calculated field
I have one field that depends on a second field
When I type something in the second field, the cursor jumps from my field in which I write to the field in which I dynamically change the value

I fixed this by checking the currently active element with a focusedElm element to only do setPatchedCaretPosition on the field I'm interacting with

Please check which browsers were used for testing

  • Chrome
  • Chrome (Android)
  • Safari (OSX)
  • Safari (iOS)
  • Firefox
  • Firefox (Android)

@kasperdun kasperdun marked this pull request as draft March 12, 2024 00:06
@kasperdun kasperdun marked this pull request as ready for review March 26, 2024 23:29
if (formattedValue !== lastUpdatedValue.current.formattedValue && input) {
const activeElement = document.activeElement;

if (input === activeElement && formattedValue !== lastUpdatedValue.current.formattedValue && input) {
Copy link
Owner

Choose a reason for hiding this comment

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

Humm, @kasperdun can you share an example where this is breaking? Basically focusedElm.current is set only when that input is focused. As we set the focusedElm.current to undefined when a blur is called.

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

Successfully merging this pull request may close these issues.

2 participants