Code Monkey home page Code Monkey logo

Comments (11)

mdgriffith avatar mdgriffith commented on August 15, 2024 3

Ok, yeah this is something on the elm/html level. If I switch to an Input.text, then I don't see them getting out of sync:

https://ellie-app.com/3cLXQcSYMcqa1

I know the virtualdom library special-cases input elements and input, so it might not be special-casing textarea.

from elm-ui.

bburdette avatar bburdette commented on August 15, 2024 2

I added a PR. It seems to fix the examples here, like this one: https://ellie-app.com/52FxBzLnVFDa1

from elm-ui.

bburdette avatar bburdette commented on August 15, 2024 1

mdgriffith suggested trying the value attrib on Slack, so I gave it a try. So far this is working well, and no key counters to keep track of:

import Html.Attributes as HA
import Json.Encode as JE

workAroundMultiLine :
    List (Attribute msg)
    ->
        { onChange : String -> msg
        , text : String
        , placeholder : Maybe (Input.Placeholder msg)
        , label : Input.Label msg
        , spellcheck : Bool
        }
    -> Element msg
workAroundMultiLine attribs mlspec =
    Input.multiline (htmlAttribute (HA.property "value" (JE.string mlspec.text)) :: attribs)
        mlspec

from elm-ui.

perty avatar perty commented on August 15, 2024 1

Thank you @bburdette . My solution was to use Html.textarea instead.

            Element.html
                (Html.textarea
                    [ Html.Attributes.value model.currentMessage
                    , Html.Events.onInput MessageUpdate
                    , Html.Attributes.rows (rowCount model.currentMessage)
                    ]
                    []
                )

Where rowCount is a function that estimates the needed number of rows.

from elm-ui.

andys8 avatar andys8 commented on August 15, 2024 1

@mdgriffith I can confirm the fix by @bburdette

from elm-ui.

mdgriffith avatar mdgriffith commented on August 15, 2024

Interesting!

I'm wondering if this is really behavior due to Elm itself versus this library.

I've put your code into an ellie.

The super weird part, is if you open up the inspector and take a look at the textarea elements when they get out of sync...they're actually showing the same internal text, it's just not rendering. 🤔 At least in firefox.

from elm-ui.

tomstejskal avatar tomstejskal commented on August 15, 2024

I've found this issue in elm/html:
elm/html#55

There is also mentioned a workaround in a comment in another issue:
evancz/elm-html#81 (comment)

from elm-ui.

ymtszw avatar ymtszw commented on August 15, 2024

Just logging that this still is an issue with recent elm/[email protected].
Also, Keyed workaround suggested in evancz/elm-html#81 (comment) has a flaw that newly generated textarea DOM will lose focus (since it is a different DOM than the previous one?), makes it almost unusable.
Edit: Actually, I misread the workaround which introduces "sequence counter" that will be incremented on reset/submit and uses that number as a key for Keyed. That should work.
On the other hand, naively using text stored in your model as a key will cause new DOMs to be generated every keystroke, which doesn't work (loses focus on every keystroke).

from elm-ui.

perty avatar perty commented on August 15, 2024

Here is an ellie where I compare the behaviour of elm-ui and elm/html. https://ellie-app.com/52FxBzLnVFDa1

The fields are Html.input, Html.textarea, Input.text and Input.multiline. All except the last behaves as expected. When the model changes, so do they. The last one, multiline, does also change unless you have typed anything. Then what you have typed, gets stuck.

I expected the multiline to behave more like the others.

from elm-ui.

perty avatar perty commented on August 15, 2024

Looking into this with developer tools, I can see a difference between Html.textarea and Input.multiline. When I change the text, Html.textarea still is <textarea></textarea> while Input.multiline becomes <textarea>Entered text</textarea>.

It is beyond me how the textarea element works in the browser. I thought what elm-ui does was correct.

from elm-ui.

perty avatar perty commented on August 15, 2024

Ok, some more digging. When I change the model, Html.textarea changes the value attribute of the <textarea>. Input.multiline does not, it changes what is between the tags, instead.

I found this by setting id on the textareas and looking in the console.

from elm-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.