Skip to content
This repository was archived by the owner on Jul 22, 2022. It is now read-only.

Passed in block should know if the link is selected or not. #3

Open
hadees opened this issue Jun 29, 2013 · 2 comments
Open

Passed in block should know if the link is selected or not. #3

hadees opened this issue Jun 29, 2013 · 2 comments

Comments

@hadees
Copy link

hadees commented Jun 29, 2013

I'm using a bootstrap theme I purchased that has posed a problem working with your helper.

The html it uses is as follows.

Selected:

<li class="start active">
  <a href="index.html">
    <i class="icon-home"></i>
    <span class="title">Dashboard</span>
    <span class="selected"></span>
  </a>
</li>

Not Selected:

<li class="start">
  <a href="index.html">
    <i class="icon-home"></i>
    <span class="title">Dashboard</span>
  </a>
</li>

As you can see above not only is active added to the surrounding li but the html <span class="selected"></span> is added in when a nav link is selected.

I thought this would be a simple change by just passing in a boolean value into the block provided so I could do something like...

<%= nav_link_to "index.html" do |active| %>
  <i class="icon-home"></i>
  <span class="title">Dashboard</span>
  <% if active %>
     <span class="selected"></span>
  <% end %>
<% end %>

However you generate the link html before knowing if the link is selected or not so I couldn't just do that.

@greypants
Copy link
Contributor

That's a good idea. In the meantime, could you replace the <span class="selected"></span> with a pseudo-element instead?

.start.active:after {
  content: '';
  /* put whatever your span styles were here. */
}

Or if you want to leave the markup in there, just display none it unless the li's got an active class.

@greypants
Copy link
Contributor

@hadees did you end up coming up with a solution for this? Feel free to open a Pull Request. If not, I'll probably close this out.

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

No branches or pull requests

2 participants