Skip to content

Commit

Permalink
Make components on mobile to only toggle the content
Browse files Browse the repository at this point in the history
  • Loading branch information
cdedreuille committed Sep 21, 2023
1 parent 636ee68 commit 2a74241
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion code/ui/manager/src/components/sidebar/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ import {
getLink,
} from '../../utils/tree';
import { statusMapping, getHighestStatus, getGroupStatus } from '../../utils/status';
import { useMediaQuery } from '../hooks/useMedia';
import { BREAKPOINT_MIN_600 } from '../../constants';
import { useMobileLayoutContext } from '../mobile/MobileLayoutProvider';

export const Action = styled.button<{ height?: number; width?: number }>(
({ theme, height, width }) => ({
Expand Down Expand Up @@ -201,6 +204,9 @@ const Node = React.memo<NodeProps>(function Node({
onSelectStoryId,
api,
}) {
const isDesktop = useMediaQuery(BREAKPOINT_MIN_600);
const { setMobileMenuOpen } = useMobileLayoutContext();

if (!isDisplayed) {
return null;
}
Expand Down Expand Up @@ -231,6 +237,7 @@ const Node = React.memo<NodeProps>(function Node({
onClick={(event) => {
event.preventDefault();
onSelectStoryId(item.id);
if (!isDesktop) setMobileMenuOpen(false);
}}
{...(item.type === 'docs' && { docsMode })}
>
Expand Down Expand Up @@ -329,7 +336,7 @@ const Node = React.memo<NodeProps>(function Node({
onClick={(event) => {
event.preventDefault();
setExpanded({ ids: [item.id], value: !isExpanded });
if (item.type === 'component' && !isExpanded) onSelectStoryId(item.id);
if (item.type === 'component' && !isExpanded && isDesktop) onSelectStoryId(item.id);
}}
onMouseEnter={() => {
if (item.isComponent) {
Expand Down

0 comments on commit 2a74241

Please sign in to comment.