Skip to content

Commit

Permalink
fix(community-side-navigation): fix overlap when sidenav expands
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-K-Lam authored and fzero committed Dec 6, 2019
1 parent 6a1cd8e commit 30b8bed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/SideNavigation/SideNavigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class SideNavigation extends Component {
componentDidMount() {
this.checkOffset()
window.addEventListener('scroll', this.checkOffset)
window.addEventListener('click', this.checkOffset)
this.adjustWidth()
window.addEventListener('resize', this.adjustWidth)
this.checkActiveState()
Expand Down Expand Up @@ -119,7 +118,6 @@ class SideNavigation extends Component {

removeEventListeners() {
window.removeEventListener('scroll', this.checkOffset)
window.removeEventListener('click', this.checkOffset)
window.removeEventListener('resize', this.adjustWidth)
}

Expand All @@ -143,6 +141,7 @@ class SideNavigation extends Component {
((sideNavRect.top < 0 &&
containerRect.top < 0 &&
sideNavRect.bottom <= containerRect.bottom &&
sideNavRect.bottom > 0 &&
this.state.variant !== 'bottom') ||
(sideNavRect.top > 0 && containerRect.top <= 0)) &&
sideNavRect.height < containerRect.height
Expand Down Expand Up @@ -206,6 +205,7 @@ class SideNavigation extends Component {
handleToggleSubMenu: this.toggleSubMenu,
isOpen: this.checkAccordion(id),
id,
callback: this.checkOffset,
}
}
return <StyledLi>{React.cloneElement(child, options)}</StyledLi>
Expand Down
10 changes: 9 additions & 1 deletion packages/SideNavigation/SubMenu/SubMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class SubMenu extends React.Component {
}

render() {
const { children, label, isOpen, ...rest } = this.props
const { children, label, isOpen, callback, ...rest } = this.props

const activeChild = this.state.active
return (
Expand Down Expand Up @@ -120,6 +120,7 @@ class SubMenu extends React.Component {
duration={500}
in={isOpen}
height={this.state.subMenuHeight}
onEntered={callback}
>
{() => (
<SubMenuContainer
Expand Down Expand Up @@ -170,6 +171,12 @@ SubMenu.propTypes = {
* @ignore
*/
onClick: PropTypes.func,
/**
* Callback.
*
* @ignore
*/
callback: PropTypes.func,
}

SubMenu.defaultProps = {
Expand All @@ -178,6 +185,7 @@ SubMenu.defaultProps = {
children: undefined,
id: undefined,
onClick: undefined,
callback: undefined,
}

export default SubMenu
5 changes: 2 additions & 3 deletions packages/SideNavigation/__tests__/SideNavigation.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ describe('SideNavigation', () => {
window.removeEventListener = jest.fn()

sideNavigation.instance().removeEventListeners()
expect(window.removeEventListener).toHaveBeenCalledTimes(3)
expect(window.removeEventListener).toHaveBeenCalledTimes(2)
expect(window.removeEventListener.mock.calls[0]).toContain('scroll')
expect(window.removeEventListener.mock.calls[1]).toContain('click')
expect(window.removeEventListener.mock.calls[2]).toContain('resize')
expect(window.removeEventListener.mock.calls[1]).toContain('resize')
})
})

0 comments on commit 30b8bed

Please sign in to comment.