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

NavbarBurger hamburger icon not toggling the navbar menu #38

Open
luisDVA opened this issue Jun 11, 2021 · 3 comments
Open

NavbarBurger hamburger icon not toggling the navbar menu #38

luisDVA opened this issue Jun 11, 2021 · 3 comments

Comments

@luisDVA
Copy link

luisDVA commented Jun 11, 2021

Hi all,

I'm building an app and when I shrink down the window and the hamburger icon appears, nothing happens when I click it and the menu items don't show up.

This happens in the RStudio viewer and when I open the app in the browser. I've seen the hamburger work in the echarts4r shiny demo by @JohnCoene and when I try the same approach the button doesn't open up a menu.

Here's some example code that reproduces my problem:

library(shiny)
library(shinybulma)

shinyApp(
  ui = bulmaPage(
    bulmaNavbar(
      color = "primary",
      bulmaNavbarBrand(
        bulmaNavbarItem(
          "home",
          href = "Item 1"
        ),
        bulmaNavbarBurger()
      ),
      bulmaNavbarMenu(
        bulmaNavbarItem(
          "Item 1"
        ),
        bulmaNavbarItem(
          "Item 2"
        ),
      )
    ),
    bulmaNav(
      "Item 1",
      bulmaContainer(
        bulmaTitle("Item 1")
      )
    ),
    bulmaNav(
      "Item 2",
      bulmaContainer(
        bulmaTitle("Item 2")
      )
    )
  ),
  server = function(input, output) {
  }
)

Am I missing something?
Thanks for all the work

@thesixmax
Copy link

Late answer, but I was wondering the same and found the culprit. The bulmaNavbarBurger function is defined as:

bulmaNavbarBurger <- function(color = "primary"){
  shiny::tags$button(
    class = paste0("button navbar-burger is-", color),
    `data-target` = "navMenu",
    shiny::tags$span(),
    shiny::tags$span(),
    shiny::tags$span()
  )
}

You have to point data-target to navbar-menu instead of navMenu and it behaves as intended. Hopefully this will be fixed in an upcoming version.

@luisDVA
Copy link
Author

luisDVA commented Dec 2, 2021

thanks @thesixmax !
Looking forward to building new apps with shinybulma now!

@thesixmax
Copy link

thanks @thesixmax ! Looking forward to building new apps with shinybulma now!

I revisited this, and found that my original solution is wrong. Changing data-target = "navMenu" is incorrect. If anything else than "navMenu" is selected as target, the burger will show, but it meeses with is-active class of navbar-burger. Instead we should add a parameter for on-click (found the solution here):

bulmaNavbarBurger <- function(color = "primary") {
  shiny::tags$button(
    class = paste0("button navbar-burger is-", color),
    `data-target` = "navMenu",
    onclick = "document.querySelector('.navbar-menu').classList.toggle('is-active');",
    shiny::tags$span(),
    shiny::tags$span(),
    shiny::tags$span()
  )
}

This works as intended, so both navbar-menu and navbar-burger gets the is-active class on click.

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

No branches or pull requests

2 participants