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

pass close fn/forwardref to promptlink #698

Conversation

John-Paul-Larkin
Copy link
Member

✨ Codu Pull Request 💻

Codu Logo

Pull Request details

The dropdown nav is a headless UI disclosure, usually handles closing. From docs >>
To close a disclosure manually when clicking a child of its panel, render that child as a Disclosure.Button. You can use the ‘as’ prop to customize which element is being rendered.

However in this case it is not working, because the as prop is passed the PromptLink component.
<Disclosure.Button
as={Link} // import Link as PromptLink
to={item.href}

{item.name}
</Disclosure.Button>

Fix
The disclosure component exposes a close render prop, which I drill down and invoke in the PromptLink component.
Nav > MobileNav > SubNav > PromptLink

Note:
Before I made modifications to the code, a forwardRef error was being displayed in the console. I resolved this issue by introducing a ref to the disclosure button, passing it as a forwardRef to PromptLink, and then applying the ref to the next/Link component.

I also added a displayName to the PromptLink component to please the linting gods.

Any Breaking changes

None

Associated Screenshots

  • IF YOU HAVE ANY SCREENSHOTS, INCLUDE THEM HERE. ( Welcome file extensions include gifs/png screenshots of your feature in action )
  • None

Copy link

vercel bot commented Jan 17, 2024

@John-Paul-Larkin is attempting to deploy a commit to the Codú Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Jan 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
codu ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2024 8:07pm

Copy link
Contributor

@NiallJoeMaher NiallJoeMaher left a comment

Choose a reason for hiding this comment

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

Nice one! This will help for sure.

@NiallJoeMaher NiallJoeMaher merged commit 433357c into codu-code:develop Jan 17, 2024
4 of 5 checks passed
@John-Paul-Larkin John-Paul-Larkin deleted the bugfix/685-Mobile-dropdown-menu-not-closing branch January 19, 2024 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants