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

Editing content of input field moves caret position to end #81

Open
panmona opened this issue Aug 6, 2021 · 3 comments
Open

Editing content of input field moves caret position to end #81

panmona opened this issue Aug 6, 2021 · 3 comments

Comments

@panmona
Copy link

panmona commented Aug 6, 2021

I noticed that when you edit an input field the caret always jumps to the end. This can be reproduced on the Demo app: https://shmew.github.io/Feliz.MaterialUI/#samples/sign-in

Repro

  1. Type into input
  2. Move caret to start
  3. Type a character

Expected result

Caret position stays the same

Actual Result

Caret moves to the end

A short video of what happens:

caret-bug-2021-08-06_12.08.04.mp4
@Zaid-Ajaj
Copy link

Maybe because of textField.autoFocus true?

@panmona
Copy link
Author

panmona commented Aug 6, 2021

@Zaid-Ajaj The behavior is the same when autoFocus is false.

@panmona
Copy link
Author

panmona commented Sep 16, 2021

After investigating further I found references to the underlying issue (Zaid-Ajaj/Feliz#320, elmish/elmish#60) with the proposed solution of using valueOrDefault.

For Mui we would need the same but it has to be applied on inputRef instead of ref. The implementation would be:

open Fable.Core.JsInterop
    // ...

    /// Can be used instead of `textField.defaultValue` and `textField.value` props to override input box value.
    let inline valueOrDefault (value: string) =
        textField.inputRef (fun e -> if e |> isNull |> not && !!e?value <> !!value then e?value <- !!value)

Can we add this to the Feliz.MaterialUI library @Shmew? I would be very willing to make the PR but would need some guidance for it.

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

2 participants