From f9dcdb0318891608e67e23757e7b04403c9fab46 Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Fri, 17 Jun 2016 15:07:32 +0200 Subject: [PATCH] Control expanded state of Navbar.Collapse Controlling the expanded state allows us to close the collapse after items are selected (as recommended by react-bootstrap maintainers). Also makes changes to the nav components to pass through props (required by react-bootstrap to correctly wire everything together). --- js/components/header.js | 33 +++++++++++++++---- js/components/header_notifications.js | 6 ++++ js/components/nav_routes_links.js | 44 ++++++++++++++------------ js/components/nav_routes_links_link.js | 26 +++++++-------- 4 files changed, 69 insertions(+), 40 deletions(-) diff --git a/js/components/header.js b/js/components/header.js index 52586901..189b57ea 100644 --- a/js/components/header.js +++ b/js/components/header.js @@ -21,6 +21,7 @@ import NavRoutesLinks from './nav_routes_links'; import { currentUserShape, whitelabelShape } from './prop_types'; import { constructHead } from '../utils/dom'; +import { safeMerge } from '../utils/general'; import { getLangText } from '../utils/lang'; @@ -35,7 +36,12 @@ let Header = React.createClass({ }, getInitialState() { - return PieceListStore.getState(); + return safeMerge( + PieceListStore.getState(), + { + expandedCollapse: false + } + ); }, componentDidMount() { @@ -52,7 +58,17 @@ let Header = React.createClass({ this.setState(state); }, - getLogo() { + collapseNav() { + if (this.state.expandedCollapse) { + this.onToggleCollapse(false); + } + }, + + onToggleCollapse(expandedCollapse) { + this.setState({ expandedCollapse }); + }, + + renderLogo() { const { whitelabel } = this.props; if (whitelabel.head) { @@ -74,7 +90,7 @@ let Header = React.createClass({ } }, - getPoweredBy() { + renderPoweredBy() { return ( {getLangText('powered by')} @@ -129,6 +145,7 @@ let Header = React.createClass({ navbar pullRight hasPieces={!!unfilteredPieceListCount} + onSelect={this.collapseNav} routes={routes} userAcl={currentUser.acl} /> ); @@ -154,20 +171,22 @@ let Header = React.createClass({ + className="hidden-print" + expanded={this.state.expandedCollapse} + onToggle={this.onToggleCollapse}> - {this.getLogo()} + {this.renderLogo()} - {this.getPoweredBy()} + {this.renderPoweredBy()} -