-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add config option to disable scroll into view for targets of boosted links and forms #1459
Add config option to disable scroll into view for targets of boosted links and forms #1459
Conversation
Hey it's me, the annoying semantic guy Though looking at the existing config, maybe a name such as Let me know your thoughts on this |
I would love to see this get merged! One great thing about hx-boost is that you can, if you choose, basically just always target the full document, and get what you might call an "automatic" SPA user experience on top of a totally traditional MPA developer experience. Although not totally in line with HTMX's primary use case of using smaller, granular html snippets, I think this is also a really valid use case for a lot of sites. This is what we're doing by default with Hwy, for example. Unfortunately, the default scroll-to-top behavior makes some form interactions a little goofy, and not being able to turn that off is odd. At risk of overthinking and delaying merging, I'd love to see this take options: scrollTopAfterBoosted: true | false | "anchor-only" | "form-only" |
I don't have a strong opinion on the name I've chosen, so I'll adapt it to your suggestion. Will do it tomorrow. |
And I'm not a native speaker so let me invoke @alexpetros or @1cg as my choices of naming have already proven not to be the best ones in the past 😆 |
should we allow for more than just a global override, or is global good enough? (Thank you for your work on this @xhaggi ) |
I think global override is a good start. But yes, I think it would be great to also be able to override on a per-form / per-anchor basis. The main use case for me, just for the sake of being explicit, is to be able to return form validation results in what might be a long form, without scroll state being lost. |
I think we should use We also probably will want a granular way to enable/disable that (and add it to OOB swaps), but that's no reason to hold up the global config. |
Based on some background discussions I read earlier (sorry don't have the links handy), the limitation to boosted forms and anchors is to mimic default browser behavior (though the default smooth scroll violates this). Personally I just want a way to set it to no scrolling at all, to avoid the UI slingshotting effect when you submit a form (but still be able to do simple progressive enhancement), so other than that have no strong opinion :) |
Unrelated, but isn't this just a regular link? |
Yep, regular anchor tag with hx-boost on for automatic client routing. Astro just recently released their client routing solution to get this same effect. |
ok, so https://htmx.org/attributes/hx-swap/ is where you can specify scrolling behavior by default it does nothing, unless we are taking about a boosted link or form, so this global really only applies to those and the name should probably reflect that you can override the behavior of a boosted form w/ something like this: <body hx-boost="true">
...
<form hx-swap="innerHTML scroll:none" ... />
...
</form>
...
</body> (not tested) |
Unless I'm missing something, I think it's really important to inherit the global If you've set hx-boost at a parent level, you can just use traditional form attributes.
Having to repeat something like |
You can just modify the scrolling behavior: <form hx-swap="scroll:none" ... /> I'm not saying we don't need this global config, I'm just thinking out loud about how widely it matters with respect to the name. Maybe |
I understand now, and agree—forgot that boost has special scrolling behavior. I think |
There may be a bug because I've never been able to get that syntax to work. It still scrolls to top for me on a boosted form, with hx-boost set on the body. |
OK, that's a bug for sure. Do you mind debugging it?
The "scroll" should be determined by the swap spec.
Cheers,
Carson
/// big sky software ///
…On Thursday, November 2nd, 2023 at 1:19 PM, Sam Cook ***@***.***> wrote:
> You can just modify the scrolling behavior:
>
> <form hx-swap="scroll:none" ... />
>
> I'm not saying we don't need this global config, I'm just thinking out loud about how widely it matters with respect to the name.
>
> Maybe htmx.config.scrollTopIntoViewOnBoost?
There may be a bug because I've never been able to get that syntax to work. It still scrolls to top for me on a boosted form, with hx-boost set on the body.
—
Reply to this email directly, [view it on GitHub](#1459 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AADSRP3NOXKUHAK4SMZRWHDYCPW5TAVCNFSM6AAAAAAYQCMK2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJRGQYDSNRYGM).
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Yep, happy to. Thanks for hanging in there with me :) |
First of all,
@1cg to change the default behavior, you have to use @alexpetros I don't really like |
64fb23f
to
6b827a0
Compare
I have now decided to use |
The reason to use @1cg we just need a final decision on |
@alexpetros after a second thought the name |
6b827a0
to
609ac0f
Compare
609ac0f
to
e2294fc
Compare
e2294fc
to
8c8f8b8
Compare
Force pushed. @alexpetros let me know if the documentation is clear enough. |
@1cg beat me to punch and merged it, but the documentation is great :) |
This adds a configuration option to enable/disable scrolling up after swapping a boosted link or form.
Related discussion #407
@David-Guillot you have requested something like that in #407 (comment)