-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Hash routing to named element #47320
Conversation
src/Components/Components/src/Microsoft.AspNetCore.Components.csproj
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks reasonable, but I think we need E2E tests for it, and we need to address the issue with the layering, as we don't want to add a reference to JS interop directly to Microsoft.AspNetCore.Components
I think there's also a third scenario we should consider. Or at least, a variation of scenario 2 in the PR description:
The question is, how long is the async delay allowed to be? How do we know when to stop waiting? In the existing implementation in this PR, it has to be zero delay - we only support navigating to anchors that exist synchronously after the navigation. But I think in a very large number of cases, people have no choice but to load stuff asynchronously. At the same time, we don't want to wait indefinitely for the anchor tag to be added, since maybe the user has already started doing unrelated scrolling and will be inconvenienced by the scroll position changing unexpectedly later. Scenarios like this make me think that a purely client-side implementation might be simpler and more flexible. That is:
Then none of the .NET-side changes would be necessary. This is at least more general than the existing solution, at the cost that while a The one issue is extreme cases where it takes, say, 20+ seconds for the async loading process to complete. We probably don't want to wait that long. So we'd have to accept the limitation that scrolling to the hash is not guaranteed and will only happen if you render the corresponding content within, say, 5 seconds. This does get us into the realm of making subjective judgements about UX but I think that's unavoidable. What do you think? Was this sort of approach considered already? |
I will add more e2e tests soon |
suppress scrolling when Router re-renders; add more e2e tests
As was discussed, we decided to go with the previous design where scrolling happens in |
src/Components/Server/src/Circuits/RemoteScrollToLocationHash.cs
Outdated
Show resolved
Hide resolved
src/Components/Server/src/Circuits/RemoteScrollToLocationHash.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really great! Thanks so much for continuing to sort out all the details and being flexible about the overall approach.
I would have approved this now (since this is 99% done) but just noticed that auto-merge is enabled. There are just a few minor details to resolve as per the other comments, and so I don't want to cause this to merge too soon 😄
Also, superb work on the E2E tests. Those look really good. |
Co-authored-by: Steve Sanderson <SteveSandersonMS@users.noreply.github.com>
2. Prevent scrolling in focusOnNavigate 3. Removed test that checks scrolling to a named element with FocusOnNavigate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
Hash routing to named element
Description
Implemented navigation to the named element via anchor element or Navlink component with href containing '#' or using NavigationManager to navigate to url containing '#'.
There are 2 scenarios:
Scrolling to the element on the same page
For this scenario I changed
NavigationManager.ts
performInternalNavigation
which is called in the method that overrides default behavior of anchor elements to handle this scenario too.Internal navigation
For this scenario I changed
Router
OnAfterRenderAsync
to check the url and if it contains '#' then call a js script to scroll to the element.Also I had to change behavior of
FocusOnNavigate
component because the page would flicker - scroll to the named element and then scroll to theFocusOnNavigate
Selector. The ts script thatFocusOnNavigate
uses now prevents scrolling when focusing on the selector.Fixes #8393