RinteRface / shinyMobile

shiny API for Framework7 (IOS/android)
https://shinymobile.rinterface.com
407 stars 74 forks source link

close popup upon clicking f7Button within popup #266

Closed dvera closed 4 months ago

dvera commented 4 months ago

How may I close a popup upon clicking an f7Button within the popup?

DivadNojnarg commented 4 months ago

Hi,

Just add the element the popup-close class. For instance, according to the Framework7 doc (https://framework7.io/docs/popup#control-popup-with-links):

library(shiny)
library(shinyMobile)

close_popup <- f7Link("close Popup", href = "#")
close_popup$attribs$class <- "popup-close"

shinyApp(
  ui = f7Page(
    title = "Popup",
    f7SingleLayout(
      navbar = f7Navbar(
        title = "f7Popup"
      ),
      f7Block(f7Button("toggle1", "Toggle Popup"))
    )
  ),
  server = function(input, output, session) {
    observeEvent(input$toggle1, {
      f7Popup(
        id = "popup1",
        title = "My first popup",
        f7Text(
          "text1", "Popup content",
          "This is my first popup ever, I swear!"
        ),
        close_popup
      )
    })

    observeEvent(input$popup1, {
      popupStatus <- if (input$popup1) "opened" else "closed"

      f7Toast(
        position = "top",
        text = paste("Popup1 is", popupStatus)
      )
    })
  }
)