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

Order of JS scripts causes dropdown issues #311

Open
ashbaldry opened this issue Sep 15, 2020 · 1 comment
Open

Order of JS scripts causes dropdown issues #311

ashbaldry opened this issue Sep 15, 2020 · 1 comment
Assignees
Labels

Comments

@ashbaldry
Copy link
Contributor

The current order of calling the JS files in semanticPage is causing issues for dropdown_input when you include "button" in the class. If you put the dropdown JS after the button JS script it seems to resolve the issue.

Example:

library(shiny)
library(shiny.semantic)

search_dropdown <-  shiny.semantic::dropdown_input(
  "simple_dropdown", letters, default_text = "Search Word...", type = "labeled search icon button"
)
search_dropdown$attribs$style <- "min-width: 190px;"
search_dropdown$children[[2]]$attribs$class <- "ui search icon"

ui <- function() {
  shinyUI(
    semanticPage(
      title = "Dropdown example",
      search_dropdown,
      p("Selected letter:"),
      textOutput("selected_letter"),
    )
  )
}

server <- shinyServer(function(input, output, session) {
  output$selected_letter <- renderText(input[["simple_dropdown"]])
})

shinyApp(ui = ui(), server = server)
@anirbanshaw24
Copy link

anirbanshaw24 commented May 11, 2021

Hi,
The problem lies with same CSS and JS names. In this case the class button is a CSS class. The JS shiny-semantic-button.js is also looking for ID button. According to the order of specifying the JS files, the dropdown is first built and then it is overqritten by the button JS. Putting the button JS on top resolves this as finally the dropdown JS is overwriting it. Also if button JS is removed altogether, it will work simply because there is no JS overwriting the drodown JS.

The problem can be fixed by asking JS to find a different keyword for button.

find: function(scope) {
   return $(scope).find('.shiny-semantic-button');
},

Like for dropdown, the JS actually finds semantic-select-input here:

  find: function(scope) {
    return $(scope).find('.semantic-select-input');
  },

Of course this will mean we need to update the JS binding element ID wherever shiny-semantic-button.js is actually needed.

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

No branches or pull requests

3 participants