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

Update hover / active behavior for side navigation links #3511

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}

Comment on lines +45 to +54
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The styles here can be removed if it'd be preferable to keep with the current behavior, 410654d is the main change needed to allow targeting the (active sidenav) element.

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