Skip to content

Commit

Permalink
Fix pricing page scrolling
Browse files Browse the repository at this point in the history
A scrolling/focus issue was noted in #167. The error was unconditionally
scrolling to the pricing plan blocks. The logic that we want is to only
scroll to the plans if they are not on the page currently, and only when
some action has selected one of the tabs (there is a URL hash).
  • Loading branch information
agjohnson committed Nov 16, 2022
1 parent 997a173 commit fe69902
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion readthedocs_theme/static/js/site.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,13 @@ jquery.fn.plausible = function () {
jquery.fn.tabmenu = function (settings) {
return this.each((index, elem) => {
settings.onLoad = () => {
$(elem).get(0).scrollIntoView();
// Only scroll to the plan block when it is not on screen. We also inspect
// the URL hash to ensure we're not scrolling on navigating to the page.
// If there is a page hash, something was clicked to select the plans tab.
const is_on_screen = $(elem).visibility("is on screen");
if (!is_on_screen && window.location.hash) {
$(elem).get(0).scrollIntoView();
}
};
$(elem).find(".item").tab(settings);
});
Expand Down

0 comments on commit fe69902

Please sign in to comment.