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

Active links #2

Closed
kevinrenskers opened this issue Apr 24, 2020 · 6 comments
Closed

Active links #2

kevinrenskers opened this issue Apr 24, 2020 · 6 comments

Comments

@kevinrenskers
Copy link

Very cool tiny router! Especially love the fallback handling that bubbles up to parent routes.

One thing that seems to be missing though is support for detecting / styling active links. Have you thought about adding that to tinro?

@AlexxNB
Copy link
Owner

AlexxNB commented Apr 24, 2020

Thanks!
Yes, I found that miss this feature and it should be implemented. As we have no special component like Links, I think the best way is take action for this feature.

My proposal is something like this:

<script>
import {active} from 'tinro';
</script>

<a href="/some/internal/path" use:active>Link</a>

The problems that we should solve here:

  • Ability to set which CSS-class should be added to the anchor when link is active.
  • Ability to mark will the link be active when exact or relative matched path.

By default, class will be active and href will match with page and all subpages(relative).

Variant1:

<a href="/some/path" use:active>Link</a>
<a href="/some/path" use:active={{exact:true}}>Link</a>
<a href="/some/path" use:active={{class:'customclass',exact:true}}>Link</a>

Variant2:

<a href="/some/path" use:active>Link</a>
<a href="/some/path" use:active data-exact>Link</a>
<a href="/some/path" use:active data-exact data-class="customclass">Link</a>

Variant3:

<script>
   import {active,activeExact} from 'tinro';
</script>

<a href="/some/path" use:active>Link</a>
<a href="/some/path" use:activeExact>Link</a>
<a href="/some/path" use:activeExact={'customclass'}>Link</a>

I like Variant3 Variant2, but we may have some discuss other variants before I start implementing this feature.

@kevinrenskers
Copy link
Author

I kinda like variant 3 the least haha, 2 different things to import, seems a bit inconsistent. But any of these variants are better than nothing :D

@AlexxNB
Copy link
Owner

AlexxNB commented Apr 24, 2020

Nothing of three is ideal, as for me. Will wait some time. Maybe somebody will suggest a better way for this feature implementation.

@AlexxNB
Copy link
Owner

AlexxNB commented Apr 24, 2020

Just seen - I mean my prefered Variant is 2, not 3 =) It is most declarative.

@AlexxNB
Copy link
Owner

AlexxNB commented Apr 25, 2020

Just released active action. Please check v0.2.2 on NPM, and see Readme for more info

@Fractal-Tess
Copy link

Fractal-Tess commented Dec 21, 2022

What is the solution for the active class in 2022.
I'm using tailwind for styling and it isn't exactly working.
If I use the data-active-class it completely breaks if there is a space character.

Also, would you mind letting me know if I'm doing something wrong here, this code does not work

 <a use:active exact href="/example">Example link</a>
 
<style lang="postcss">
  .active {
    @apply border-primary border-b-2;
  }
</style>

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

No branches or pull requests

3 participants