jackmoore/autosize

Textarea is not updated after I empty it

Closed this issue · 1 comments

Hello @jackmoore,

Thank you for your plugin! It helps a lot. I still don't understand why the autoresize is not natively supported by the browsers, but, anyway, that's not the subject here.

I have this tchat system i'm building with Vanilla. When I keydown the "Enter" (keycode 13) after typing in the textarea, I empty the textarea and then I try to update it like this:

import autosize from 'autosize/dist/autosize'; // "autosize": "4.0.2",

textarea.value = ""
autosize.update(textarea)

I made you a very reduced code on this codepen
My problems here are :

  • when I hit the "Enter" button, the textarea is empty as wanted but it's not updated with autosize. When I start to write again inside it, it's updated ;
  • the codepen scenario is working absolutely great I'm not able to reproduce 😢

Do you have, with your experience, any clue on what could go wrong?

Thank you for your answers.

Cheers!

Edit:

        textarea.value = '';
        const eventAutosize = new Event("autosize:update");
        textarea.dispatchEvent(eventAutosize)

seems to do the trick. I don't exactly understand why, but as long as it's working it's fine for me. 🤷‍♂️

Good job with the workaround. My guess is that your original attempt triggered some race condition because both your action and autosize's actions are being triggered on the same keydown event. I never considered that situation.