diff options
Diffstat (limited to 'app/assets/javascripts/merge_request_tabs.js')
-rw-r--r-- | app/assets/javascripts/merge_request_tabs.js | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/app/assets/javascripts/merge_request_tabs.js b/app/assets/javascripts/merge_request_tabs.js index d8255181574..b0dc5697018 100644 --- a/app/assets/javascripts/merge_request_tabs.js +++ b/app/assets/javascripts/merge_request_tabs.js @@ -8,7 +8,12 @@ import flash from './flash'; import BlobForkSuggestion from './blob/blob_fork_suggestion'; import initChangesDropdown from './init_changes_dropdown'; import bp from './breakpoints'; -import { parseUrlPathname, handleLocationHash, isMetaClick } from './lib/utils/common_utils'; +import { + parseUrlPathname, + handleLocationHash, + isMetaClick, + parseBoolean, +} from './lib/utils/common_utils'; import { isInVueNoteablePage } from './lib/utils/dom_utils'; import { getLocationHash } from './lib/utils/url_utility'; import Diff from './diff'; @@ -212,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); + } + } } } @@ -440,7 +467,7 @@ export default class MergeRequestTabs { // Expand the issuable sidebar unless the user explicitly collapsed it expandView() { - if (Cookies.get('collapsed_gutter') === 'true') { + if (parseBoolean(Cookies.get('collapsed_gutter'))) { return; } const $gutterIcon = $('.js-sidebar-toggle i:visible'); |