Setting the scroll position is just done through using the normal DOM functionality, targeting the rendered node.
To do this, you'll need to add a ref
property in the HTML DSL to the node you want to scroll:
containerRef ∷ H.RefLabel
containerRef = H.RefLabel "container"
render =
HH.div
[ HP.ref containerRef ]
[ someContent ]
And then in the eval
for the component you can get hold of the actual DOM element created, using getHTMLElementRef
, and then update the scroll position on that:
eval (ScrollToBottom next) = do
ref ← H.getHTMLElementRef containerRef
for_ ref \el → H.liftEff do
scrollHeight ← DOM.scrollHeight el
offsetHeight ← DOM.offsetHeight el
let maxScroll ← scrollHeight - offsetHeight
DOM.setScrollTop maxScroll el
pure next
The snippets here are modified from some real world code that does something similar, so should do the trick!