Skip to content

Commit

Permalink
Update hover / active behavior for side navigation links (#3511)
Browse files Browse the repository at this point in the history
* Reorg CSS clases for sidenav links

* Include 'active' for current sidenav context

This will allow targeted styling of the active element in the side nav

* Update side navigation active / hover contexts

This aligns closer to RailsAdmin 2.x.x, where the background of an element in the side nav changes when it's either active or hovered over - making the navigation itself easier to follow in the UI

Co-authored-by: Mitsuhiro Shibuya <[email protected]>
  • Loading branch information
codealchemy and mshibuya authored May 4, 2022
1 parent a3daea9 commit 4a6524a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/helpers/rails_admin/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ def navigation(parent_groups, nodes, level = 0)
abstract_model = node.abstract_model
model_param = abstract_model.to_param
url = rails_admin.url_for(action: :index, controller: 'rails_admin/main', model_name: model_param)
level_class = " nav-level-#{level}" if level > 0
nav_icon = node.navigation_icon ? %(<i class="#{node.navigation_icon}"></i> ).html_safe : ''
nav_icon = node.navigation_icon ? %(<i class="#{node.navigation_icon}"></i>).html_safe : ''
css_classes = ['nav-link']
css_classes.push("nav-level-#{level}") if level > 0
css_classes.push('active') if defined?(@action) && current_action?(@action, model_param)
li = content_tag :li, data: {model: model_param} do
link_to nav_icon + node.label_plural, url, class: "nav-link#{level_class}"
link_to nav_icon + " " + node.label_plural, url, class: css_classes.join(' ')
end
child_nodes = parent_groups[abstract_model.model_name]
child_nodes ? li + navigation(parent_groups, child_nodes, level + 1) : li
Expand Down
10 changes: 10 additions & 0 deletions src/rails_admin/styles/base/theming.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ body.rails_admin {
> li > a {
padding: ($navbar-padding-y / 2) ($grid-gutter-width / 2);

&.active {
background-color: map-get($theme-colors, primary);
color: color-contrast(map-get($theme-colors, primary));
}

&:hover {
background-color: map-get($theme-colors, primary);
color: color-contrast(map-get($theme-colors, primary));
}

&.nav-level-1 {
padding-left: $grid-gutter-width;
}
Expand Down

0 comments on commit 4a6524a

Please sign in to comment.