htmx icon indicating copy to clipboard operation
htmx copied to clipboard

Preserve scroll on swap content

Open gerbil opened this issue 1 year ago • 2 comments

I've tried both hx-swap="focus-scroll:true" and <meta name="htmx-config" content='{"defaultFocusScroll": true}'>, but still got scroll back to top on every table body triggered refresh event.

Is there any way to preserve scroll for specific content part after swap?

gerbil avatar Oct 08 '24 13:10 gerbil

Some things to check is that the element you want to retain its focus and scroll is one of the supported elements like an input and that you have it in focus and also it must have a id attached for the feature to work.

MichaelWest22 avatar Oct 08 '24 20:10 MichaelWest22

It's a TR in TABLE; So generally hx-swap="show:#id:top" is working for static elements; But for dynamic lists now i need:

  • To get current 'infocus' element somehow (dynamically)
  • To add this element ID into hx-swap somehow

gerbil avatar Oct 09 '24 07:10 gerbil

So the only possible option is `idiomorph' extension usage. Will try to stick with it.

gerbil avatar Oct 30 '24 14:10 gerbil