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

Add support for properly functioning navbar submenus #1426

Merged
merged 6 commits into from
Aug 13, 2018

Conversation

rich-iannone
Copy link
Member

This fix is for replacing the class of a submenu item (3rd level down) such that it gets the dropdown-submenu class.

Fixes #721

@rich-iannone
Copy link
Member Author

For the _site.yml of:

name: "site"
navbar:
  title: "My Website"
  left:
    - text: "Home"
      href: index.html
    - text: "About"
      href: about.html
      menu:
        - text: "Sub_1"
          href: sub1.html
        - text: "Sub_2"
          menu:
            - text: "Sub_2_below"
              href: sub2.html

this change targets the second to last item (with text Sub_2) so that the sub2.html is available and clickable. Here is a screenshot:

submenu-fix

This uses a CSS path that targets any item with this type of relationship.

This script generates files used to generate the site (and does the site render also):

index <- '---
title: "My Website"
output: html_document
---

Hello, Website!'

about <- '---
title: "About This Website"
output: html_document
---

More about this website.'

sub_part_1 <- '---
title: "About This Website"
output: html_document
---

sub_1: This is right below the About page.'

sub_part_2 <- '---
title: "About This Website"
output: html_document
---

sub_2: This is 2 levels below the About page.'

write(index, file = "index.Rmd")
write(about, file = "about.Rmd")
write(sub_part_1, file = "sub1.Rmd")
write(sub_part_2, file = "sub2.Rmd")

rmarkdown::render("index.Rmd")
rmarkdown::render("about.Rmd")
rmarkdown::render("sub1.Rmd")
rmarkdown::render("sub2.Rmd")

render_site()

@rich-iannone rich-iannone changed the title Add JQuery function to modify class of submenu items Add support for properly functioning navbar submenus Aug 10, 2018
@rich-iannone
Copy link
Member Author

The submenu now functions properly and jQuery was not used in this final solution. Here is a screenshot of the menu/submenu:

submenu

Some CSS rules had to be added to 'restore' support for the dropdown-submenu CSS class (removed in Bootstrap 3.0 RC, see https://stackoverflow.com/questions/18023493/bootstrap-dropdown-sub-menu-missing for additional context).

The R code changes occurred entirely in the navbar_links_tags() function. By checking the depth, we can distinguish between a top-level menu element or a menu element below top level. Then, we can apply the dropdown or dropdown-submenu class to the li element.

@rich-iannone
Copy link
Member Author

Forgot to mention it earlier... thanks @jcheng5 for the assistance on this!

Copy link
Member

@yihui yihui left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks!

margin-top:-6px;
margin-left:-1px;
-webkit-border-radius:0 6px 6px 6px;
-moz-border-radius:0 6px 6px 6px;
Copy link
Member

Choose a reason for hiding this comment

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

We probably don't need the -webkit and -moz prefixes: https://caniuse.com/#feat=border-radius

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice, I'll take those lines out.

@@ -215,6 +215,49 @@
padding-top: $header_padding$px;
margin-top: -$header_padding$px;
}

.dropdown-submenu {
position:relative;
Copy link
Member

Choose a reason for hiding this comment

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

Could you indent by 2 spaces and add spaces after colons (to be consistent with previous CSS code)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for missing this. Will do!

@yihui yihui added this to the v1.11 milestone Aug 13, 2018
@rich-iannone rich-iannone merged commit 0ff85d8 into rstudio:master Aug 13, 2018
@yihui
Copy link
Member

yihui commented Aug 14, 2018

We also need a NEWS entry for this feature (or perhaps bug fix).

yihui pushed a commit to RLesur/rmarkdown that referenced this pull request Apr 1, 2019
* Add JQuery function to modify class of submenu items

Fixes rstudio#721

* Add CSS rules & refine JQuery function

* Modify `navbar_links_tags()` to handle submenus

* Remove previously added jQuery function

* Remove CSS rules w.r.t. to WebKit/Mozilla

* Reformat CSS rules for consistency
@apreshill apreshill mentioned this pull request Jul 3, 2019
13 tasks
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

multiple level submenu in navbar?
2 participants