scala-js/scala-js-dom

ScrollTop value on HTMLTextAreaElement not set

mathieuleclaire opened this issue · 3 comments

Hi,
when I (try to) change the value of the scrollTop attribute on a HTMLTextAreaElement, the value is not set.
Mathieu

import scalatags.JsDom.{ tags  tags }
import scalatags.JsDom.all._

val tARender: HTMLTextAreaElement = tags.textarea(`class` := "form-control", rows := 20).render
tARender.scrollTop = 999.0
println("TOP " + tARender.scrollTop)

A lot of behaviours in the DOM require the element to be attached to the document to take effect. I believe you're running into an issue along these lines. See https://jsfiddle.net/fz5LnLng/1/

That is, it's not an issue with scala-js-dom, it's that the DOM is rather crap :)

Try adding it to the document somewhere before you set scrollTop.

I'm not sure about scrollTop, but in some situations it's possible to add the element to the dom, perform your operation and then immediately remove it again, so it may be worth trying that if you really need it to be set before it's added to the document.

@sjrd vote to close this since it's not an issue with scala-js-dom, and has been idle for 6 months.

sjrd commented

Indeed.