Skip to content

Commit

Permalink
bg(mobile-nav): fix mobile not displaying properly (#20)
Browse files Browse the repository at this point in the history
- switch over to using reactjs to implement mobile nav toggling

[Fixes #163724488]
  • Loading branch information
akhilome committed Feb 5, 2019
1 parent 0658982 commit 511e47e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
51 changes: 32 additions & 19 deletions src/components/Nav.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React, { Fragment } from 'react';
import React, { Fragment, Component } from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import { connect } from 'react-redux';
import LogoutLink from './Logout';

export const Nav = ({ isLoggedIn, role, cartItemsCount }) => {
const navContent = () => {
export class Nav extends Component {
state = { showMobileMenu: false };

toggleMobileMenu = () => this.setState(prev => ({ showMobileMenu: !prev.showMobileMenu }));

navContent = () => {
const { isLoggedIn, role, cartItemsCount } = this.props;
if (isLoggedIn && role === 'customer') {
return (
<Fragment>
Expand Down Expand Up @@ -56,22 +61,30 @@ Cart [
</Fragment>
);
};
return (
<header>
<div className="site-title">
<h2>
<Link to="/">Kiakia Food</Link>
</h2>
</div>
<nav>
<button type="button" className="nav-mobile small transparent">
☰ menu
</button>
<ul>{navContent()}</ul>
</nav>
</header>
);
};

render() {
const { showMobileMenu } = this.state;
return (
<header>
<div className="site-title">
<h2>
<Link to="/">Kiakia Food</Link>
</h2>
</div>
<nav>
<button
type="button"
onClick={this.toggleMobileMenu}
className="nav-mobile small transparent"
>
☰ menu
</button>
<ul className={showMobileMenu ? 'open' : null}>{this.navContent()}</ul>
</nav>
</header>
);
}
}

Nav.propTypes = {
isLoggedIn: PropTypes.bool,
Expand Down
6 changes: 0 additions & 6 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,5 @@
</head>
<body>
<div id="app"></div>
<script>
setTimeout(() => {
document.querySelector('.nav-mobile').onclick = () =>
document.querySelector('nav ul').classList.toggle('open');
}, 500);
</script>
</body>
</html>
10 changes: 8 additions & 2 deletions src/tests/components/__snapshots__/App.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ exports[`App component should render app correctly 1`] = `
<nav>
<button
className="nav-mobile small transparent"
onClick={[Function]}
type="button"
>
☰ menu
</button>
<ul>
<ul
className={null}
>
<li>
<Link
replace={false}
Expand Down Expand Up @@ -295,11 +298,14 @@ exports[`App component should render app correctly for authenticated customers 1
<nav>
<button
className="nav-mobile small transparent"
onClick={[Function]}
type="button"
>
☰ menu
</button>
<ul>
<ul
className={null}
>
<li>
<Link
replace={false}
Expand Down

0 comments on commit 511e47e

Please sign in to comment.