swup / fragment-plugin

A swup plugin for dynamically replacing containers based on rules 🧩
https://swup-fragment-plugin.netlify.app
MIT License
15 stars 1 forks source link

Allow customizing the focus element per fragment rule #42

Closed daun closed 1 year ago

daun commented 1 year ago

Describe the problem

Describe the proposed solution

How important is this feature to you?

hirasso commented 1 year ago

Since a11y plugin is optional, the focus flag should be optional, as well. So a default value of false sounds good to me!

daun commented 1 year ago

@hirasso If I'm correct, the current behavior of a11y + fragment plugins is to move the focus to the main element, even after fragment visits. A default value of false would mean not moving focus, so a breaking change.

hirasso commented 1 year ago

Ah! Right. What would you prefer?

daun commented 1 year ago

An optional focus key with a default of null sounds good. The current behaviour seems to me like a good default solution, i.e. focus the main element as configured by the a11y plugin. That's already a better experience for keyboard users than traditional MPAs that return focus to the top of the document on each navigation — here we're already skipping the header and jumping right to the content.

Depending on the markup of your fragments, this could well be enough, assuming the new fragment is a main tag and comes first in the document. For other cases like filter UIs, specifically setting or disabling a new focus option on the fragment rules would be a great way for fine-tuning this.

hirasso commented 1 year ago

Great, let's go with a default of undefined then, just like with the rule option for name!