diff --git a/www/attributes/hx-swap.md b/www/attributes/hx-swap.md index 039abcf4..14bc6e00 100644 --- a/www/attributes/hx-swap.md +++ b/www/attributes/hx-swap.md @@ -103,11 +103,19 @@ You may also use `window:top` and `window:bottom` to scroll to the top and botto ``` -Finally, htmx attempts to preserve focus between requests. This will cause the focused element to scroll into view -which can be unwanted behavior in some cases. To disable this, you can use `focus-scroll:false`: +#### Focus scroll + +htmx preserves focus between requests for inputs that have a defined id attribute. By default htmx prevents auto-scrolling to focused inputs between requests which can be unwanted behavior on longer requests when the user has already scrolled away. To enable focus scroll you can use `focus-scroll:true`. ```html - +``` + +Alternatively, if you want the page to automatically scroll to the focused element after each request you can change the htmx global configuration value `htxm.config.defaultFocusScroll` to true. Then disable it for specific requests using `focus-scroll:false`. + +```html + ``` diff --git a/www/docs.md b/www/docs.md index 9bbd65b8..776bb853 100644 --- a/www/docs.md +++ b/www/docs.md @@ -1304,7 +1304,7 @@ listed below: | `htmx.config.wsReconnectDelay` | defaults to `full-jitter` | `htmx.config.disableSelector` | defaults to `[disable-htmx], [data-disable-htmx]`, htmx will not process elements with this attribute on it or a parent | `htmx.config.timeout` | defaults to 0 in milliseconds -| `htmx.config.defaultFocusScroll` | if the focused element should be scrolled into view, defaults to false +| `htmx.config.defaultFocusScroll` | if the focused element should be scrolled into view, defaults to false and can be overriden using the [focus-scroll](/attributes/hx-swap/#focus-scroll) swap modifier.