Closed daun closed 1 year ago
Great idea! And should be easily achievable. Another name for the rule option could preserveScroll
with a default of true
, to keep defaults to positive values.
What about allowing a fragment id #list
as a value of the scroll option? Some fragment visits might require scrolling to a specific element, e.g. the result list of a filter UI.
Interesting idea! But I feel like we should leave this to the implementors. With the simplification of the fragmentVisit
object it would now be very simple to implement custom logic:
swup.hooks.on('content:replace', async (visit) => {
if (visit.fragmentVisit?.name === 'my-fragment-visit') {
visit.scroll.reset = true;
}
});
or
swup.hooks.on('content:replace', async (visit) => {
if (visit.fragmentVisit?.name === 'my-fragment-visit') {
visit.scroll.target = '#list';
}
});
Do you think we still need this as a rule option then?
If we go with a new rule option, is this what you were imagining?
{
scroll: boolean | string
}
Where scroll
would be false
for each rule if not customized. Options would be
{
scroll: true
}
{
scroll: '#list'
}
I actually like this a lot, will create a PR.
Describe the problem
Describe the proposed solution
scroll
option to fragment rulesAlternatives considered
visit.scroll.reset = true;
How important is this feature to you?