0

I have the following code using lit-html.

const textarea = (note) => {
  return html`<textarea>
    ${note}
  </textarea>`
}

let array = [1, 2, 3]


const rendered = () => {
  return render(html`
    ${array.map((item) => {
      return html`${textarea(item)}`
    })}
  `)
}

Executing the function rendered should be fine as is. However when I add live to the textarea here. I get the error in the title.

const textarea = (note) => {
  return html`<textarea>
    ${live(note)}
  </textarea>`
}

Without live if I were to add a filter functionality to the list of text areas. A change in a textarea would stay even when html is re-rendered.

In other words.

  • All textareas are visible.
  • I make a change in the top textarea, adding "hello"
  • I filter the textareas and do a re-render so that only the third textarea is visible.
  • Even if I do a re-render, the word "hello" is there in the only visible textarea, even though it shouldn't be there since that textarea hasn't been edited.
Jonathan
  • 8,453
  • 9
  • 51
  • 74

1 Answers1

2

The issue turned out to be.

That you need to use

html`<textarea .value="${live(note)}"></textarea>`

instead of

html`<textarea>${live(note)}</textarea>`
Jonathan
  • 8,453
  • 9
  • 51
  • 74