From 0bd3ebfc8fcbc85906b9e6d29ac6b297a85520e7 Mon Sep 17 00:00:00 2001 From: Patrick Yeo Date: Fri, 17 May 2019 17:10:13 -0700 Subject: [PATCH 1/3] Sidebar Navigation move onclick to the Anchor so we don't have `#no` in the address bar --- src/components/Sidebar/Navigation.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/Sidebar/Navigation.js b/src/components/Sidebar/Navigation.js index 87c66824..8ac8f915 100644 --- a/src/components/Sidebar/Navigation.js +++ b/src/components/Sidebar/Navigation.js @@ -4,6 +4,7 @@ import { Link, withPrefix } from "gatsby" class Navigation extends React.Component { _handleOnClick(index, depth, section, event) { + event.preventDefault(); event.stopPropagation(); const elementRef = this.refs[`navItem${index}${depth}`]; @@ -35,8 +36,8 @@ class Navigation extends React.Component { }); return( -
  • - +
  • + {section.items && ( @@ -55,10 +56,10 @@ class Navigation extends React.Component { } } -const Anchor = ({page}) => { +const Anchor = ({page, onclick}) => { if (page.items) { return( - + {page.title} From fd6e3e4413f8b01c951918c8bd587d5061779dda Mon Sep 17 00:00:00 2001 From: Patrick Yeo Date: Mon, 20 May 2019 11:48:18 -0700 Subject: [PATCH 2/3] Follow Bootstrap's pattern and move `.active` class on anchor instead of `li` --- src/components/Sidebar/Navigation.js | 29 +++--- src/styles/site/_sidebar-site.scss | 132 +++++++-------------------- 2 files changed, 48 insertions(+), 113 deletions(-) diff --git a/src/components/Sidebar/Navigation.js b/src/components/Sidebar/Navigation.js index 8ac8f915..7309b8df 100644 --- a/src/components/Sidebar/Navigation.js +++ b/src/components/Sidebar/Navigation.js @@ -4,14 +4,12 @@ import { Link, withPrefix } from "gatsby" class Navigation extends React.Component { _handleOnClick(index, depth, section, event) { + const el = event.currentTarget; + event.preventDefault(); event.stopPropagation(); - const elementRef = this.refs[`navItem${index}${depth}`]; - - if (!elementRef.classList.contains('active') || !!section.items) { - elementRef.classList.toggle('active'); - } + el.classList.toggle('active'); } _isActive(section) { @@ -30,14 +28,11 @@ class Navigation extends React.Component { const { sectionList, location, depth = 0 } = this.props; return sectionList.map((section, index) => { - let style = classNames({ - 'active': this._isActive(section) === true, - 'nav-heading': section.items - }); + let style = section.items ? 'nav-heading nav-item' : 'nav-item'; return(
  • - + {section.items && ( @@ -49,19 +44,23 @@ class Navigation extends React.Component { render() { return( -