diff --git a/client/src/components/layouts/GuideLayout.js b/client/src/components/layouts/GuideLayout.js index 8beadd6450..9b15e451c8 100644 --- a/client/src/components/layouts/GuideLayout.js +++ b/client/src/components/layouts/GuideLayout.js @@ -29,70 +29,86 @@ const propTypes = { location: PropTypes.object }; -const Layout = ({ children }) => ( - (this.contentRef = ref); + + handleNavigation = () => { + this.contentRef.scrollTop = 0; + this.contentRef.focus(); + }; + + render() { + return ( + { - const { edges } = data.allNavigationNode; - const pages = edges.map(edge => edge.node); - return ( - - {({ - toggleDisplaySideNav, - displaySideNav, - expandedState, - toggleExpandedState - }) => ( - - - - - - - - -
- {children} -
- -
-
-
- )} -
- ); - }} - /> -); + `} + render={data => { + const { edges } = data.allNavigationNode; + const pages = edges.map(edge => edge.node); + return ( + + {({ + toggleDisplaySideNav, + displaySideNav, + expandedState, + toggleExpandedState + }) => ( + + + + + + + + +
+ {this.props.children} +
+ +
+
+
+ )} +
+ ); + }} + /> + ); + } +} Layout.displayName = 'Layout'; Layout.propTypes = propTypes; diff --git a/client/src/components/layouts/components/guide/NavItem.js b/client/src/components/layouts/components/guide/NavItem.js index 395e698028..6a9654f927 100644 --- a/client/src/components/layouts/components/guide/NavItem.js +++ b/client/src/components/layouts/components/guide/NavItem.js @@ -4,23 +4,30 @@ import Link from 'gatsby-link'; const propTypes = { isStubbed: PropTypes.bool, + onNavigate: PropTypes.func.isRequired, path: PropTypes.string, router: PropTypes.object, title: PropTypes.string, toggleDisplaySideNav: PropTypes.func.isRequired }; -function NavItem(props) { - const { isStubbed, path, title } = props; - return ( -
  • - - - {title} - - -
  • - ); +class NavItem extends React.Component { + handleClick = () => { + this.props.toggleDisplaySideNav(); + this.props.onNavigate(); + }; + render() { + const { isStubbed, path, title } = this.props; + return ( +
  • + + + {title} + + +
  • + ); + } } NavItem.displayName = 'NavItem'; diff --git a/client/src/components/layouts/components/guide/NavPanel.js b/client/src/components/layouts/components/guide/NavPanel.js index f2e271fbd8..28a8d25071 100644 --- a/client/src/components/layouts/components/guide/NavPanel.js +++ b/client/src/components/layouts/components/guide/NavPanel.js @@ -9,6 +9,7 @@ const propTypes = { handleClick: PropTypes.func.isRequired, hasChildren: PropTypes.bool, isExpanded: PropTypes.bool, + onNavigate: PropTypes.func.isRequired, path: PropTypes.string, title: PropTypes.string, toggleDisplaySideNav: PropTypes.func.isRequired @@ -52,9 +53,10 @@ class NavPanel extends Component { } handleTitleClick() { - const { path, toggleDisplaySideNav } = this.props; + const { path, toggleDisplaySideNav, onNavigate } = this.props; toggleDisplaySideNav(); navigate(path); + onNavigate(); } renderHeader() { @@ -94,8 +96,6 @@ class NavPanel extends Component { return ( diff --git a/client/src/components/layouts/components/guide/SideNav.js b/client/src/components/layouts/components/guide/SideNav.js index 60d37c92d8..349aa996f5 100644 --- a/client/src/components/layouts/components/guide/SideNav.js +++ b/client/src/components/layouts/components/guide/SideNav.js @@ -7,6 +7,7 @@ import NavItem from './NavItem'; const propTypes = { expandedState: PropTypes.object, + onNavigate: PropTypes.func.isRequired, pages: PropTypes.arrayOf(PropTypes.object), parents: PropTypes.arrayOf(PropTypes.object), toggleDisplaySideNav: PropTypes.func.isRequired, @@ -42,7 +43,9 @@ class SideNav extends Component { const [category] = pages.filter(page => page.path === path); const { title, hasChildren, dashedName } = category; - const children = this.renderChildren(childrenForParent, pages); + const children = isExpanded + ? this.renderChildren(childrenForParent, pages) + : null; return ( - {isExpanded ? children : null} + {children} ); } @@ -68,6 +72,7 @@ class SideNav extends Component { - - {`${title} | freeCodeCamp Guide`} - - - - - - - - -
    { - this.article = article; - }} - tabIndex='-1' +const GuideArticle = props => { + const { + location: { pathname }, + data: { + markdownRemark: { + html, + fields: { slug }, + frontmatter: { title } + } + }, + pageContext: { meta } + } = props; + return ( + + + {`${title} | freeCodeCamp Guide`} + + - - ); - } -} + + + + + + +
    + + ); +}; GuideArticle.displayName = 'GuideArticle'; GuideArticle.propTypes = propTypes;