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

[Bug]: as_is parameter in modal-related functions is not functional #436

Closed
1 task done
federiva opened this issue Apr 27, 2023 · 1 comment
Closed
1 task done
Labels

Comments

@federiva
Copy link
Contributor

Guidelines

  • I agree to follow this project's Contributing Guidelines.

Project Version

No response

Platform and OS Version

No response

Existing Issues

No response

What happened?

An already closed #348 introduced the as_is parameter to be passed to the hide_modal, show_modal and remove_modal functions.
This parameter, a logical, is not being handled in the body of the function itself causing this functions to always work as if they were passing the as_is = FALSE which is confusing because the default for this parameter is TRUE

Steps to reproduce

library(shiny)
library(shiny.semantic)

mod_ui <- function(id) {
  ns <- NS(id)
  tagList(
    shiny.semantic::modal(
      div("Inspect the server code"),
      id = ns("modal")
    ),
    # The following should not work but it's working because asis is always as FALSE
    shiny.semantic::action_button(
      input_id = ns("open_as_is_true"),
      class = "red",
      "Open modal with as_is TRUE passing the non-namespaced id"
    ),
    # The following should work but it's not
    shiny.semantic::action_button(
      input_id = ns("open_as_is_true_namespaced"),
      class = "red",
      "Open modal with as_is TRUE passing the namespaced id"
    ),
    # The following is working as expected because asis is always as FALSE
    shiny.semantic::action_button(
      input_id = ns("open_as_is_false"),
      class = "yellow",
      "Open modal with as_is FALSE passing the non-namespaced id"
    ),
    hr(),
    h3("shiny.semantic::show_modal Source code:"),
    div(
      div(style = "font-family: monospace; background-color: #f4f4f4; color: #c7254e; padding: 5px; border: 1px solid #ccc;",
        HTML(
        '&emsp;function (id, session = shiny::getDefaultReactiveDomain(), asis = TRUE) {<br>
            &emsp;&emsp;id <- ifelse(inherits(session, "session_proxy"), session$ns(id), id)<br>
            &emsp;&emsp;session$sendCustomMessage("showSemanticModal", list(id = id, action = "show"))<br>
          &emsp;}'
        )
      )
    )
  )
}


mod_server <- function(id) {
  moduleServer(id, function(input, output, session) {
    observeEvent(input$open_as_is_true, {
      shiny.semantic::show_modal(
        id = "modal",
        asis = TRUE
      )
    })
    
    observeEvent(input$open_as_is_true_namespaced, {
      shiny.semantic::show_modal(
        id = session$ns("modal"),
        asis = TRUE
      )
    })
    
    observeEvent(input$open_as_is_false, {
      shiny.semantic::show_modal(
        id = "modal",
        asis = FALSE
      )
    })
  })
}

ui <- shiny.semantic::semanticPage(
  mod_ui("modal")
)

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

shinyApp(ui, server)

Expected behavior

As declared in the UI function

Attachments

No response

Screenshots or Videos

No response

Additional Information

No response

@federiva
Copy link
Contributor Author

federiva commented May 4, 2023

Closed by #437

@federiva federiva closed this as completed May 4, 2023
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

1 participant