Skip to content

Commit

Permalink
fix(v2): remove hashbang when click on collapsed item
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 committed Nov 15, 2019
1 parent a65a57b commit 8d5f64d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/docusaurus-theme-classic/src/theme/DocSidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import React, {useState} from 'react';
import React, {useState, useCallback} from 'react';
import classnames from 'classnames';

import Link from '@docusaurus/Link';
Expand All @@ -27,6 +27,11 @@ function DocSidebarItem({item, onItemClick, collapsible}) {
setCollapsed(item.collapsed);
}

const handleClickItem = useCallback(e => {
e.preventDefault();
setCollapsed(state => !state);
});

switch (type) {
case 'category':
return (
Expand All @@ -42,9 +47,7 @@ function DocSidebarItem({item, onItemClick, collapsible}) {
'menu__link--active': collapsible && !item.collapsed,
})}
href="#!"
onClick={
collapsible ? () => setCollapsed(!collapsed) : undefined
}>
onClick={collapsible ? handleClickItem : undefined}>
{label}
</a>
<ul className="menu__list">
Expand Down

0 comments on commit 8d5f64d

Please sign in to comment.