@@ -7,21 +7,19 @@ import Menu from "react-feather/dist/icons/menu"
77import ChevronRight from "react-feather/dist/icons/chevron-right"
88import { Accordions } from "undernet"
99
10- import Button from "app/components/Button"
1110import "./styles.scss"
1211
13- const pkg = require ( "../../.. /package.json" )
14- const MENU_COLLAPSE_BREAKPOINT = 1199
12+ const pkg = require ( "projectRoot /package.json" )
13+ const MENU_COLLAPSE_WIDTH = 1199
1514
1615export default class SideNav extends React . Component {
1716 constructor ( props ) {
1817 super ( props )
19- this . handleCurrentWidth = throttle ( this . handleCurrentWidth . bind ( this ) , 50 )
18+ this . handleMenuVisibility = throttle ( this . handleMenuVisibility , 50 )
2019 }
2120
2221 state = {
23- menuIsOpen : window . innerWidth > MENU_COLLAPSE_BREAKPOINT ? true : false ,
24- currentWindowWidth : window . innerWidth ,
22+ menuIsOpen : window . innerWidth > MENU_COLLAPSE_WIDTH ,
2523 }
2624
2725 static propTypes = {
@@ -40,56 +38,43 @@ export default class SideNav extends React.Component {
4038 }
4139
4240 componentDidMount ( ) {
43- window . addEventListener ( "resize" , this . handleCurrentWidth )
4441 window . addEventListener ( "resize" , this . handleMenuVisibility )
4542
46- const menuIsOpen = this . state . currentWindowWidth > MENU_COLLAPSE_BREAKPOINT
43+ const menuIsOpen = window . innerWidth > MENU_COLLAPSE_WIDTH
4744 this . setState ( { menuIsOpen } )
4845
4946 Accordions . start ( )
5047 }
5148
52- componentDidUpdate ( ) {
53- Accordions . stop ( )
54- Accordions . start ( )
55- }
56-
5749 componentWillUnmount ( ) {
58- window . removeEventListener ( "resize" , this . handleCurrentWidth )
5950 window . removeEventListener ( "resize" , this . handleMenuVisibility )
6051 Accordions . stop ( )
6152 }
6253
6354 handleCollapseClick = ( ) => {
64- if ( this . state . currentWindowWidth <= MENU_COLLAPSE_BREAKPOINT ) {
55+ if ( window . innerWidth <= MENU_COLLAPSE_WIDTH ) {
6556 this . setState ( { menuIsOpen : false } )
6657 }
6758 }
6859
69- handleCurrentWidth = ( ) => {
70- this . setState ( {
71- currentWindowWidth : window . innerWidth ,
72- } )
73- }
74-
7560 handleMenuVisibility = ( ) => {
76- if ( this . state . currentWindowWidth > MENU_COLLAPSE_BREAKPOINT ) {
61+ if ( window . innerWidth > MENU_COLLAPSE_WIDTH ) {
7762 this . setState ( { menuIsOpen : true } )
7863 }
7964 }
8065
81- handleClick = event => {
66+ handleMenuToggleClick = event => {
8267 event . preventDefault ( )
8368 this . setState ( { menuIsOpen : ! this . state . menuIsOpen } )
8469 }
8570
86- getButtonClasses ( ) {
71+ get buttonClasses ( ) {
8772 return classNames ( "is-justified-center is-aligned-center is-flex is-hidden-xlarge" , {
8873 "rotate-180" : ! this . state . menuIsOpen ,
8974 } )
9075 }
9176
92- getMenuClasses ( ) {
77+ get menuClasses ( ) {
9378 return classNames ( "row side-nav-menu accordion has-padding-3" , {
9479 "is-hidden" : ! this . state . menuIsOpen ,
9580 } )
@@ -107,7 +92,7 @@ export default class SideNav extends React.Component {
10792 return isActive
10893 }
10994
110- renderAccordionChildLink ( item ) {
95+ renderAccordionChildLink = item => {
11196 return (
11297 < li key = { item . name } role = "none" >
11398 < NavLink
@@ -123,19 +108,20 @@ export default class SideNav extends React.Component {
123108 )
124109 }
125110
126- renderAccordionRow ( section , index , listItems ) {
111+ renderAccordionRow ( section , index ) {
112+ const listItems = section . links . map ( this . renderAccordionChildLink )
113+
127114 return (
128115 < Fragment key = { section . header } >
129116 < h4 className = "paragraph" >
130- < Button
117+ < button
131118 id = { `nav-acc-button${ index } ` }
132- dataParent = "side-nav-accordion"
119+ data-parent = "side-nav-accordion"
133120 className = "accordion-button"
134- dataTarget = { `nav-acc-content${ index } ` }
135- role = "listitem"
121+ data-target = { `nav-acc-content${ index } ` }
136122 >
137123 { section . header }
138- </ Button >
124+ </ button >
139125 </ h4 >
140126 < ul className = "accordion-content" id = { `nav-acc-content${ index } ` } >
141127 { listItems }
@@ -146,18 +132,14 @@ export default class SideNav extends React.Component {
146132
147133 renderNavAccordion ( ) {
148134 return this . props . navItems . map ( ( section , i ) => {
149- const listItems = section . links . map ( ( item , j ) => {
150- return this . renderAccordionChildLink ( item , j )
151- } )
152-
153135 return (
154136 < div
155137 data-visible = { this . accordionIsActive ( section . links ) ? "true" : "false" }
156138 data-accordion-row = { `nav-acc-content${ i } ` }
157139 className = { classNames ( "accordion-row" , this . props . navListClasses ) }
158140 key = { section . links [ 0 ] . url }
159141 >
160- { this . renderAccordionRow ( section , i , listItems ) }
142+ { this . renderAccordionRow ( section , i ) }
161143 </ div >
162144 )
163145 } )
@@ -168,13 +150,22 @@ export default class SideNav extends React.Component {
168150 < div className = "xsmall-12 xlarge-2 columns has-no-padding" id = "side-nav" >
169151 < div className = "fluid grid side-nav-wrapper" >
170152 < div className = "row is-flex is-hidden-xlarge side-nav-expand" >
171- < Button onClick = { this . handleClick } href = "#" className = { this . getButtonClasses ( ) } >
153+ < button
154+ onClick = { this . handleMenuToggleClick }
155+ className = { this . buttonClasses }
156+ aria-controls = "side-nav-wrapper"
157+ aria-expanded = { this . state . menuIsOpen }
158+ >
172159 < Menu size = { 20 } role = "presentation" focusable = "false" /> { " " }
173160 < span className = "has-black-text" > Explore</ span >
174- </ Button >
161+ </ button >
175162 </ div >
176163
177- < nav data-accordion = "side-nav-accordion" className = { this . getMenuClasses ( ) } >
164+ < nav
165+ data-accordion = "side-nav-accordion"
166+ className = { this . menuClasses }
167+ id = "side-nav-wrapper"
168+ >
178169 < p className = "version-text has-no-padding has-gray800-text xsmall-12 columns" >
179170 Version { pkg . version }
180171 </ p >
0 commit comments