elm / virtual-dom

The foundation of HTML and SVG in Elm.
https://package.elm-lang.org/packages/elm/virtual-dom/latest
BSD 3-Clause "New" or "Revised" License
209 stars 80 forks source link

input bound value leads to cursor jumping on every keystroke #138

Closed littleStudent closed 5 years ago

littleStudent commented 6 years ago

I have a bound input element. So the state property storing the value is bound back to the dom element. On every keystroke this leads to the cursor jumping to the end of the input.

SSCCCE: https://ellie-app.com/3dWX47DKWwPa1 Browser: Safari (macOS & iOS confirmed)

input-cursor-jumping

module Main exposing (main)

import Browser
import Html exposing (Html, input)
import Html.Attributes exposing (value)
import Html.Events exposing (onInput)

type Msg
    = OnInput String

main : Program () String Msg
main =
    Browser.sandbox
        { init = ""
        , view = \str -> input [ onInput OnInput, value str ] []
        , update = \(OnInput str) _ -> str
        }
harrysarson commented 6 years ago

Note this only happens on Safari.

norpan commented 6 years ago

Also see https://github.com/whatwg/html/issues/2412

jinjor commented 6 years ago

See also https://github.com/elm/html/issues/174

decioferreira commented 5 years ago

this relates to elm/virtual-dom/issues/134 and elm/virtual-dom/pull/135

digitalsatori commented 5 years ago

same problem here, the problem found only on input element, textarea is OK. Safari only.

elm_input_problem

evancz commented 5 years ago

Some core team folks reviewed https://github.com/elm/virtual-dom/pull/135, and they tell me it should fix this. Can do a patch soon.

lucamug commented 4 years ago

To avoid confusion in case people hit this old issue:

It has been fixed in virtual-dom v.1.0.1 (https://github.com/elm/virtual-dom/releases/tag/1.0.1) released on Sep 13, 2018.

This is an Ellie for it: https://ellie-app.com/9d3gvnKDT2ra1

This issue is also mentioned in

https://github.com/elm/virtual-dom/issues/107 https://github.com/elm/html/issues/105 https://github.com/elm/html/issues/42 https://github.com/elm/html/issues/62