diff options
author | Sam Bigelow <sbigelow@gitlab.com> | 2018-11-27 18:05:16 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-11-27 18:05:16 +0000 |
commit | 153dddefed226e3716a41f177d8722a5a6fd48b8 (patch) | |
tree | ab2eec7193de8345e2ff9d0acfa485fb72216c86 /app/assets/javascripts/merge_request_tabs.js | |
parent | a99f342b4231659d39b9a145acc3652f3de3bce8 (diff) | |
download | gitlab-ce-153dddefed226e3716a41f177d8722a5a6fd48b8.tar.gz |
Resolve "Jump to top in merge request"
Diffstat (limited to 'app/assets/javascripts/merge_request_tabs.js')
-rw-r--r-- | app/assets/javascripts/merge_request_tabs.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/assets/javascripts/merge_request_tabs.js b/app/assets/javascripts/merge_request_tabs.js index 28148319c41..b0dc5697018 100644 --- a/app/assets/javascripts/merge_request_tabs.js +++ b/app/assets/javascripts/merge_request_tabs.js @@ -217,6 +217,28 @@ export default class MergeRequestTabs { } this.eventHub.$emit('MergeRequestTabChange', this.getCurrentAction()); + } else if (action === this.currentAction) { + // ContentTop is used to handle anything at the top of the page before the main content + const mainContentContainer = document.querySelector('.content-wrapper'); + const tabContentContainer = document.querySelector('.tab-content'); + + if (mainContentContainer && tabContentContainer) { + const mainContentTop = mainContentContainer.getBoundingClientRect().top; + const tabContentTop = tabContentContainer.getBoundingClientRect().top; + + // 51px is the height of the navbar buttons, e.g. `Discussion | Commits | Changes` + const scrollDestination = tabContentTop - mainContentTop - 51; + + // scrollBehavior is only available in browsers that support scrollToOptions + if ('scrollBehavior' in document.documentElement.style) { + window.scrollTo({ + top: scrollDestination, + behavior: 'smooth', + }); + } else { + window.scrollTo(0, scrollDestination); + } + } } } |