Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOP-4883: Menu not closing after selection on Mobile #1254

Merged
merged 16 commits into from
Oct 1, 2024
17 changes: 7 additions & 10 deletions src/components/Sidenav/TOCNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ const TOCNode = ({ activeSection, handleClick, level = BASE_NODE_LEVEL, node, pa
setIsOpen(!isOpen);
};

const clickSideNav = (handleClick) => {
setIsOpen(!isOpen);
Copy link
Collaborator

@mayaraman19 mayaraman19 Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh no, now the carets/"twisties" are being treated like text in mobile sidenav in that if you click them they open the page and hide the sidenav, instead of just opening the caret to see the children dropdown. I think setting the state here is probably interfering with onCaretClick. Lmk if you want to discuss this more!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed! i think we can leave the behaviors as is, and actually add a listener on location change that closes the mobile menu. ie something like this pattern

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seungpark , Im a little confused on how the link you sent is suppose to fix my issue. Sould I not be using the handleclick() anymore that I passed in from sidenav.js ? And rewrite that function in the tocnode.js file.

Copy link
Collaborator

@seungpark seungpark Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is more of a set state to close menu on location change than on sidenav button click (which would trigger a location change). lmk if that makes sense!

we can leave the behaviors as is

I meant as to leave the current click handlers, and add a new effect in the component to listen for location changes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seungpark and @mayaraman19 . Thanks for the advice I made a change that I think changes this problem. Please let me know if you see anything else.

handleClick();
};

const NodeLink = () => {
// If title is a plaintext string, render as-is. Otherwise, iterate over the text nodes to properly format titles.
const formatTextOptions = {
Expand All @@ -98,13 +103,7 @@ const TOCNode = ({ activeSection, handleClick, level = BASE_NODE_LEVEL, node, pa

if (isDrawer && hasChildren) {
return (
<SideNavItem
className={cx(sideNavItemTOCStyling({ level }))}
as="a"
onClick={() => {
setIsOpen(!isOpen);
}}
>
<SideNavItem className={cx(sideNavItemTOCStyling({ level }))} as="a" onClick={() => clickSideNav(handleClick)}>
<Icon className={cx(caretStyle)} glyph={iconType} fill={palette.gray.base} onClick={onCaretClick} />
{formattedTitle}
{hasVersions && activeVersions[options.project] && (
Expand All @@ -120,9 +119,7 @@ const TOCNode = ({ activeSection, handleClick, level = BASE_NODE_LEVEL, node, pa
to={target}
active={isSelected}
className={cx(sideNavItemTOCStyling({ level }), overwriteLinkStyle)}
onClick={(e) => {
setIsOpen(!isOpen);
}}
onClick={() => clickSideNav(handleClick)}
hideExternalIcon={true}
>
{hasChildren && (
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Toctree.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import mockData from './data/Toctree.test.json';
// /sdk/ios

const mountToctree = (slug) => {
return render(<Toctree slug={slug} toctree={mockData?.toctree} />);
return render(<Toctree slug={slug} toctree={mockData?.toctree} handleClick={() => {}} />);
};

beforeAll(() => {
Expand Down
Loading