maxence-charriere / go-app

A package to build progressive web apps with Go programming language and WebAssembly.

Home Page:https://go-app.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't make scrollbar follow new content added to overflow bottom.

RadiactoR opened this issue · comments

Since this is traditionally worked around using JavaScript, and there isn't any css property for it, there's currently no way (that I could find) to make an element's overflowing content make the scrollbar follow the newest content getting added at the bottom. For example, I have an element that is displaying live .log files, but as the div fills up, the scroll stays at the top of the list.

Is this an issue with go-app, or am I missing something?

Just use your JavaScript (call it from your go code) or write similar code using the JS interoperation (app.Window())

The second option is the only one I can work with atm, what would an "app.Window()" line manipulating elements look like?

I am very busy right now. I think I can show you some code later.

That would be great, thx.

Here some code fragment that shows similar stuff. I think you need "block" "end" with the target of the div you want to scroll. You could also set scroll top to the height (using el.Get('height') or something like that.

		if newURL.Fragment != "" {
			target := app.Window().Get("document").Call("querySelector", "a[name='"+newURL.Fragment+"']")
			if target.Truthy() {
				opts := map[string]interface{}{ /*"behavior": "smooth",*/ "block": "start"}
				target.Call("scrollIntoView", opts)
			}
		} else {
			pc := app.Window().GetElementByID("pagecontent")
			if pc.Truthy() {
				pc.Set("scrollTop", 0)
			}
		}

Thank you, but I actually solved it myself earlier today. I called "app.Script().Text()" and inside of Text() I wrote some simple JS code. Wish there would be a simpler way to interact with JS comands.

@RadiactoR I think it is pretty simple to handle JS, it is more that the interfacing code is not that great, so we end up writing JavaScript and call it from Go at times. Emitting script from the renderer would not be my way to handle stuff. I think this is prone to edge cases, because of how the DOM is compared and updated with what you "Render()". But if it works like that, it is probably good enough.