Skip to content

Commit

Permalink
feat: ensure parents are unfolded when defaultSelectedPath is a child (
Browse files Browse the repository at this point in the history
…#77)

@lucasconstantino thanks for PR!, will  release this this weekend together with other feature update
  • Loading branch information
lucasconstantino authored and wmira committed May 22, 2019
1 parent d4c3e6d commit c09e584
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/NavGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { Nav } from './Nav';
import { ViewMode, SideNavContext } from './';
import { ViewMode, SideNavContext, NavContext } from './';

export enum NavGroupState {
expanded = 'expanded',
Expand Down Expand Up @@ -118,7 +118,10 @@ const ToggleIndicator: React.FC<{collapsed: NavGroupState}> = (props) => {

export const NavGroup: React.FC<INavGroupProp> = (props) => {
const { children, onClick, ...others } = props
const [state, setState] = React.useState(NavGroupState.collapsed)
const { selectedPath } = React.useContext(SideNavContext)
const { pathId } = React.useContext(NavContext)
const childSelected = pathId && selectedPath.indexOf(pathId) === 0
const [state, setState] = React.useState(childSelected ? NavGroupState.expanded : NavGroupState.collapsed)
const rootRef = React.useRef<HTMLDivElement>(null)

const onHandleClick = (e?: React.MouseEvent ) => {
Expand Down

0 comments on commit c09e584

Please sign in to comment.