Search code examples
cssrshinyselectize.js

SelectizeInput options show as active after removing and re-adding them


When you remove a choice with the remove_button plugin and then add it again, it shows up in blue, as if it were selected, while the rest stay grey. I'd like to force them all to be grey.

Example:

library(shiny)

ui <- fluidPage(
  selectizeInput("my_selectize", "Select one",
              choices = c("One", "Two", "Three"),
              multiple = T,
              options = list('plugins' = list('remove_button'))
  )
)

server <- function(input, output, session) {
  
}

shinyApp(ui, server)

Try adding, removing, and re-adding an option.

I've tried adding custom CSS relating to .item and .item.active classes, but the default bootstrap css overwrites them. I'd be fine with making changes either directly in R or over CSS.


Solution

  • With this CSS class it worked for me.

    library(shiny)
    
    ui <- fluidPage(
      tags$head(
        tags$style(HTML("
          .selectize-control.multi .selectize-input > div.active {
          background: #efefef;
          color: #333333;
          border: 0 solid rgba(0, 0, 0, 0);
          }"))
      ),
      selectizeInput("my_selectize", "Select one",
                     choices = c("One", "Two", "Three"),
                     multiple = T,
                     options = list('plugins' = list('remove_button'))
      )
    )
    
    server <- function(input, output, session) {
    }
    
    shinyApp(ui, server)