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

feat(NavigationMenu): conditionally-rendered links #3169

Open
wants to merge 4 commits into
base: v3
Choose a base branch
from

Conversation

GalacticHypernova
Copy link

@GalacticHypernova GalacticHypernova commented Jan 24, 2025

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR introduces the possibility of conditionally rendered items in UNavigationMenu.

This improves the overall support UNavigationMenu will have to all kinds of navigations, including providing links to items that only need to exist under certain conditions.

For example, only an authorized user should see a link to their profile page.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Copy link

pkg-pr-new bot commented Jan 24, 2025

npm i https://pkg.pr.new/@nuxt/ui@3169

commit: 0890729

@GalacticHypernova GalacticHypernova marked this pull request as ready for review January 24, 2025 09:01
@benjamincanac
Copy link
Member

Not sure about this honestly, it's as easy to filter the items you provide in a computed.

@GalacticHypernova
Copy link
Author

Well, true, but I don't see the harm in having it supported natively. You can argue that a lot of features nuxt ui provides can easily be made manually.

Do you foresee any issue with this?

Copy link
Member

Not particularly but I mostly value consistency across components, this means this change would have to be made on all components having an items prop (as described in #1803 for example).

@GalacticHypernova
Copy link
Author

Well, yea, this can be added to all such components including dropdown.

I see a major benefit in it for clickable lists with varying conditions.

Example:

Imagine a comment action drop-down. It might contain an edit action that should only be visible if it's either the original commenter or if the user is a staff member of higher prrmission than the commenter, a report action that would only be visible if the user is not the original commenter, and a delete action that would be visible if it's a staff member or if it's the original commenter.

Using it with computed would be cumbersome:

const commentActions = computed(()=>{
const actions = []
if (editCondition){
actions.push(editAction)
}
if (reportCondition){
actions.push(reportAction)
}
if (deleteCondition){
actions.push(deleteAction)
}
return actions
})

And using it directly in the template with buttons for each condition would be just recreating a drop-down without a drop-down.

In such a case, the condition would be really beneficial in my opinion, as it removes boilerplate in the template and in a computed

@benjamincanac benjamincanac added the v3 #1289 label Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v3 #1289
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants