hx-swap="scroll:none" not working on a progressively enhanced form
Prior discussion here: https://github.com/bigskysoftware/htmx/pull/1459#issuecomment-1791420162
Goal: Prevent scroll-to-top behavior after hx-boosted form submissions.
Code that should achieve this per the linked discussion above:
<body hx-swap="innerHTML" hx-boost="true">
<form method="POST" action="/whatever" hx-swap="scroll:none">
Result: Still scrolls to top.
I believe this is a bug in HTMX and will do some digging in / debugging to find out.
Thanks much
Ok, I see what the issue is.
Syntax that works:
<form hx-swap="show:none>
Syntax that doesn't work:
<form hx-swap="scroll:none>
Under the hood, show calls element.scrollIntoView, and scroll calls element.scrollTop.
Boosted elements get show: top by default. So you don't want to override scroll, you want to override show.
I think this just needs a documentation PR to (1) explain what show and scroll actually mean in terms of the real DOM APIs, and (2) explain that if you want to override it for a boosted element, you need to use show, not scroll.
If you agree happy to pull a PR.
You are right. I added a note in the hx-swap documentation on how to disable the default behavior on a per-element basis in #1459.
Addressed in #1459