-
-
Notifications
You must be signed in to change notification settings - Fork 113
[Bugfix]Fix autoscroll to methods issue #321
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
[Bugfix]Fix autoscroll to methods issue #321
Conversation
Fixes #318 |
actions: { | ||
didTransition() { | ||
this._super(); | ||
if ((typeof FastBoot === 'undefined') && isEmpty(this.get('controller.anchor'))) { |
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.
I think I've mentioned it before somewhere. isEmpty(this.get('controller.anchor'))
this will probably result in scroll jump unless there is anchor specifically set up. Which is probably not a good behavior.
@sivakumar-kailasam @locks
Do we need to have backward compatibility on this? Or could we come up with a more specific anchor for scrolling to methods?
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.
Unfortunately we do. There's just so many old links out there outside our website that refer to the old doc urls. We can probably do an analysis of google analytics metrics to see the trends few months down the line and make changes but until then we have to keep at this.
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.
@akashdsouza
Oh okay. Then I think we need to specifically check for null
or ""
(or both?) so it only detects just ?anchor=
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.
Hopefully, that will work and there won't be a need to look into location
.
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.
Alright. I will update the check.
Should I use a data-attribute instead of id for scrolling to the tab?
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.
I think ID is fine.
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.
Updated
c7dd461
to
3daf6e6
Compare
This might have to wait until #322 is merged |
3daf6e6
to
d418399
Compare
app/mixins/scroll-page.js
Outdated
$(config.APP.scrollContainerSelector).scrollTop(offset - navMenuHeight - 10); | ||
} | ||
} else { | ||
this.get('scrollPositionReset').doReset(); |
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.
Why is the reset needed if there's no anchor?
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.
To retain the behavior available here:
this.get('scrollPositionReset').doReset();
Earlier, as there was no didTransition in /methods
, didTransition above would have been called.
@@ -1,5 +1,6 @@ | |||
import Route from '@ember/routing/route'; |
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.
I think the correct place to put the Mixin would be project-version/classes/class.js
and project-version/modules/module.js
and project-version/namespaces/namespace.js
. That should cover all cases.
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.
There is already a scroll-tracker mixin in these routes to reset scrolling. How would this need to be handled? Remove the scroll reset altogether as it is present in scroll-page mixin?
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.
I think we could actually add this logic to the Scroll Tracker mixin itself. It is already at the right places - maybe it will just need to be added to namespaces/namespace.js
.
Works well, but the Mixin should be put in different places as I've suggested above, otherwise, the scroll jump may not happen in various places. I think we should also consider updating these query params
There is a query-param reset like this |
d418399
to
e4f1924
Compare
e4f1924
to
24391cf
Compare
app/mixins/scroll-tracker.js
Outdated
this.get('scrollPositionReset').doReset(); | ||
this._super(); | ||
let isAnchorEmpty = window && window.location && window.location.search === '?anchor=' | ||
if ((typeof FastBoot === 'undefined') && isAnchorEmpty ) { |
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.
Does this seem hacky?
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.
Getting anchor from the controller cannot be done from these places?
If we are not in FastBoot, it is safe to reach into window.location.search
right away. (typeof FastBoot === 'undefined') && window.location.search === '?anchor=')
should be fine.
This will also break if we have more than 1 queryParam, but this is probably fine. So far there no plans for adding more.
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.
Yes. anchor is only available in child route's(methods
) controller.
I will update the check
app/mixins/scroll-tracker.js
Outdated
let offset = (elem && elem.offset && elem.offset()) ? elem.offset().top : null; | ||
if (offset) { | ||
const navMenuHeight = $('header').outerHeight(); | ||
$(config.APP.scrollContainerSelector).scrollTop(offset - navMenuHeight - 10); |
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.
Since header is no longer a fixed element on the page, do we still need to take navMenuHeight into consideration? Having a little space above the method doesn't look all bad
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.
Having a little space above the method doesn't look all bad
There will be less space if we remove it :). But let's do it, I think the anchor is gonna be more clear.
Updated |
app/mixins/scroll-tracker.js
Outdated
this._super(); | ||
if ((typeof FastBoot === 'undefined') && window.location.search === '?anchor=' ) { | ||
let elem = $('#methods'); | ||
let offset = (elem && elem.offset && elem.offset()) ? elem.offset().top : null; |
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 also overly defensive. If it's JQuery object, it is safe to assume that elem.offset
will be a function even if the element is not found.
let offset = elem.offset() ? olem.offset().top : 0
should be fine.
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.
Updated. Sorry about the delay
Works well 💯 The offset check could be simplified but it's also fine as is. |
d7815d6
to
43d462f
Compare
looks good, thanks @akashdsouza !!! |
* [Bugfix]Fix autoscroll to methods issue * Do not include header height while calculating scroll offset
If this looks ok, I can add the same to /methods under classes and modules(perhaps in a mixin?).