fix: Sidebar links unexpand

closes #1044
This commit is contained in:
Tom Moor
2019-10-13 16:15:42 -07:00
parent 766a52f10e
commit 21af0bd8be
2 changed files with 4 additions and 6 deletions

View File

@ -72,7 +72,7 @@ class DocumentLink extends React.Component<Props> {
pathname: node.url, pathname: node.url,
state: { title: node.title }, state: { title: node.title },
}} }}
expanded={showChildren} expanded={showChildren ? true : undefined}
label={node.title} label={node.title}
depth={depth} depth={depth}
exact={false} exact={false}

View File

@ -26,16 +26,12 @@ type Props = {
@observer @observer
class SidebarLink extends React.Component<Props> { class SidebarLink extends React.Component<Props> {
@observable expanded: boolean; @observable expanded: ?boolean = this.props.expanded;
style = { style = {
paddingLeft: `${(this.props.depth || 0) * 16 + 16}px`, paddingLeft: `${(this.props.depth || 0) * 16 + 16}px`,
}; };
componentDidMount() {
if (this.props.expanded) this.handleExpand();
}
componentWillReceiveProps(nextProps: Props) { componentWillReceiveProps(nextProps: Props) {
if (nextProps.expanded !== undefined) { if (nextProps.expanded !== undefined) {
this.expanded = nextProps.expanded; this.expanded = nextProps.expanded;
@ -45,6 +41,8 @@ class SidebarLink extends React.Component<Props> {
@action @action
handleClick = (ev: SyntheticEvent<>) => { handleClick = (ev: SyntheticEvent<>) => {
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation();
this.expanded = !this.expanded; this.expanded = !this.expanded;
}; };