-
Notifications
You must be signed in to change notification settings - Fork 27
Optionally update :target styles #162
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
Comments
This would still allow the It would make the behaviour of I realise It is not directly related to the API, but it's one of those things that costs several hours to analyse, test and fix after you first discover your assumptions are wrong, and I would like to make future front-end's lives easier. |
So in spec terms, the problem is that the document's target element is only ever set when scrolling to a fragment. It is not updated if you do, e.g., I can see two ways app history could help with this problem:
The difference is that (2) would affect all single-page app navs in an app history-using application, including ones that use This is related to other discussions of how, when using
My current thinking is that some of these (e.g. the focus or scroll restoration behaviors) will have an opt-out, but do the nice magic thing by default. I think synchronizing |
Will this be controllable? This would seem to be at odds with patterns like calendar views that keep /year/month in sync as you use the arrow keys or other controls. This behavior would make sense for transitions to "new page" views in an MPA sense, but not all transitions are. (I appreciate that currently there's a problem where folks don't know to blur when they should, but I can think of a few other places in the app I work on now where this behavior would break the keyboard/AT experience rather than improve it, so I hope it can be overridden where needed if enabled by default.) Edit I just caught that this was already answered at the end, oops:
(Hopefully a useful data point anyway re: the opt-out having value.) |
I'm unsure what to do with this issue in terms of defaults. As seen in #197, we're using app history to introduce a number of new defaults for things like accessibility, focus management, and scroll restoration when you opt in using It'd be easy to add something in the future like I'd love to hear more from web developers as to whether they've run into this problem. Or, alternately, whether they have use cases for keeping |
@domenic Thanks. I have put a call out on Twitter https://twitter.com/stephband/status/1480677513626013700. |
Here is a test page that demonstrates problems with |
After thinking about this issue more I think tying this to app history is the wrong approach. Fundamentally @stephband's model (and it's a reasonable one) is that But that's not what We could try to hack things closer to @stephband's preferred model when app history is involved, by essentially updating that element pointer more often. But that will still leave gaps, and it would shut out people who want to use As such, I'll close this issue and momentarily post a new feature suggestion on w3c/csswg-drafts, linking here. |
Just want to bump this — this issue is the one that constantly comes up in my practice, in sometimes it doesn't have any solution or workaround. Worst case: when a page has an anchor, and its content is dynamic in any way where the element won't exist initially. This would mean that we would be unable to share a link to this page where the The scrolling to the element can be worked around in various ways (most straightforward way — to have a mutation observer that waits for the element with the id matching the anchor to appear), but there is just no way to update the And the workarounds to have when navigating via pushState are far from convenient (replace the content, navigate to the anchor, so the I don't care much if the solution would be adding a new pseudo-class (though I agree that But this is a real issue that comes up constantly, and I really hope we would have a solution for this one day. |
Currently the target element is set as part of scrolling https://html.spec.whatwg.org/multipage/browsing-the-web.html#scroll-to-fragid:target-element-3, so it doesn't happen as part of
pushState
.stephband suggested on Twitter that they'd like the target styles to update.
Perhaps the easiest way to handle this is to allow the target element to be get/set via something like
document.targetElement
.The text was updated successfully, but these errors were encountered: