Skip to content

Commit

Permalink
Fix JUMP TO (linode#1713)
Browse files Browse the repository at this point in the history
* Fix JUMP TO

* use var

* Account for header in scroll and scroll to section not header

* remove uneeded function

* Call without timeout

* Use scrollTop and offsetHeight instead
  • Loading branch information
Matthew Parke committed May 16, 2017
1 parent 110e1c6 commit 1e428a2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
6 changes: 3 additions & 3 deletions docs/scss/docs/Layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ $sidebar-width: 250px;
.Layout {
background-color: $gray;

&-container,
&-navigationContainer,
&-content {
height: 100%;
min-height: 100%;
}

&-container {
padding-top: $nav-height;
min-height: calc(100% - #{$nav-height});
margin-top: $nav-height;
}

&-navigationContainer {
Expand Down
2 changes: 1 addition & 1 deletion docs/scss/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ html,
body,
#root,
[data-reactroot] {
height: 100%;
min-height: 100%;
}
26 changes: 25 additions & 1 deletion docs/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,35 @@ function logPageView() {
ReactGA.pageview(window.location.pathname);
}

// https://github.com/ReactTraining/react-router/issues/394#issuecomment-220221604
function hashLinkScroll() {
const { hash } = window.location;
if (hash !== '') {
// Push onto callback queue so it runs after the DOM is updated,
// this is required when navigating from a different page so that
// the element is rendered on the page before trying to getElementById.
setTimeout(() => {
const id = hash.replace('#', '');
const element = document.getElementById(id);
if (element) {
element.scrollTop = element.offsetHeight;
}
}, 0);
}
}

function onRouterUpdate() {
logPageView();
hashLinkScroll();
}

export function init() {
hashLinkScroll();

render(
<Router
history={browserHistory}
onUpdate={logPageView}
onUpdate={onRouterUpdate}
>
<Route path="/" component={Layout} endpoints={api.endpoints}>
<Route component={IndexLayout}>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/Endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function Endpoint(props) {
{methods.map(function(method, index) {
return (
<li key={index}>
<Link to={`#${method.name}`}>{method.name}</Link>
<a href={`#${method.name}`}>{method.name}</a>
</li>
);
})}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/Method.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default function Method(props) {
}

return (
<div className="Method">
<div id={name} className="Method">
<h2>{name}</h2>
<div className="Method-section">
<p className="Method-description">{description}</p>
Expand Down

0 comments on commit 1e428a2

Please sign in to comment.