codeplant/simple-navigation

Only first level rendered

nicolasconnault opened this issue · 3 comments

I'm running Rails 5 with simple-navigation. I've only slightly adapted the basic configuration file (in config/dashboard_navigation.erb), with one primary item and a secondary item, no conditions. Only the primary item gets rendered.

    SimpleNavigation::Configuration.run do |navigation|
      navigation.items do |primary|
        primary.item :reports, 'Reports', nil do |sub_nav| 
          sub_nav.item :reports_cms, 'CMS Report', reports_stores_path
        end
      end
    end

The code in the view:

<%= render_navigation( context: :dashboard ) %>

And here's the final output:

<ul><li id="reports"><span>Reports</span></li></ul>

Any reason why this is happening?

andi commented

If you set the path of :reports to nil as you do in your config file, the primary item will never know if it is active... you need a path there.

Weird I thought I'd tried that. So does this mean that it's not possible to have nav items that are just grouping, and don't represent a real URL? For example, I have a bunch of links under "Administration", but there's no main administration page.

andi commented

Well, the default behaviour is to only expose the subnavigation if the parent is active. If there is not chance to determine if the parent is active based on either URL or Regex, simple-navigation can't know if the parent is active. Then your only chance is to use the :expand_all option to always open all levels independent from the active status of parents...