Skip to content

feat(link): add router-link-inactive #3184

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

Closed
wants to merge 1 commit into from

Conversation

mdwheele
Copy link

@mdwheele mdwheele commented Apr 30, 2020

Resolves #2648

Hello!

💁 This PR adds an inactive-class prop to <router-link>, which will add a class to all inactive links (by default, uses .router-link-inactive)

Example:

<router-link :to="link" class="all links" active-class="active only" inactive-class="inactive only">
  Click me
</router-link>

This feature would be killer for anybody using Tailwind CSS.

Please let me know if you would like me to add any additional e2e tests covering this. I don't know if there are any special behaviours around exact-match links or things like that we should cover.

@shaharmor
Copy link

Super helpful for everyone using a utility-based css framework like Tailwind.

Copy link

@iamarpitpatidar iamarpitpatidar left a comment

Choose a reason for hiding this comment

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

Looka good to me, @posva what do you think?

@tobihagemann
Copy link

Just stumbled upon this. Looks like this was already solved a long time ago and just needs to be merged?

@mdwheele
Copy link
Author

@tobihagemann At the time (more than a year ago now) that this was submitted, there was a lot of working going into vue-router@4 and @posva was very busy. Check out the related issue above for more detail, but ultimately, a solution is posted in the documentation for Vue Router 4: https://next.router.vuejs.org/guide/advanced/extending-router-link.html.

This documentation details an <AppLink> component that extends RouterLink and gives you everything needed to implement an inactive-class property. With that said, I still think a flavor of this belongs in vue-router because I've now implemented this component 10+ times in different project. It's an absolute requirement if using TailwindCSS (or TailwindUI).

I'd be happy to dig into this again and help move it forward if the maintainers are interested.

@mdwheele
Copy link
Author

I'm closing this out; clearing lines of work with no clear path forwards resolution. If there is renewed interest in this feature, I am happy to contribute but reimplementing this in every project is not too bad.

@mdwheele mdwheele closed this Apr 22, 2022
@malobre
Copy link

malobre commented Apr 23, 2022

For anyone using Tailwind CSS, if your classes are not too numerous you can emulate this feature by using the important modifier for active classes, e.g:

<router-link
  :to="{ name: 'root' }"
  active-class="!border-red-500 !text-gray-900"
  class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
>
  Home
</router-link>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow defining an inactive-class
6 participants