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]: Placeholder doesn't follow the tag it covers #32

Open
1 task done
jakubsob opened this issue Jul 11, 2023 · 2 comments
Open
1 task done

[Bug]: Placeholder doesn't follow the tag it covers #32

jakubsob opened this issue Jul 11, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@jakubsob
Copy link

Guidelines

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

Project Version

0.0.0.9002

Platform and OS Version

Windows

Existing Issues

No response

What happened?

Placeholder doesn't follow the component it's supposed to cover when programatically changing it's location.

Steps to reproduce

  1. Click Toggle panel button

Expected behavior

When #container1 is hidden #container2 slides into its place with a placeholder instead of sliding from underneath the placeholder.

Attachments

library(shiny)
library(shiny.emptystate)
library(bslib)

ui <- page(
  theme = bs_theme(version = 5),
  use_empty_state(),
  tags$button(
    "Toggle panel",
    class = "btn btn-primary",
    onClick = "$('#container1').toggle(anim = 'slide');"
  ),
  div(
    style = "width: 300px",
    class = "d-flex flex-column gap-5",
    div(
      id = "container1",
      div(
        h1("Card 1"),
        "Card content"
      )
    ),
    div(
      id = "container2",
      div(
        h1("Card 2"),
        "Card content"
      )
    )
  )
)

server <- function(input, output, session) {
  empty_state_content <- div(
    "This is example empty state content"
  )
  empty_state_manager <- EmptyStateManager$new(
    id = "container2",
    html_content = empty_state_content
  )
  empty_state_manager$show()
}

shinyApp(ui, server)

Screenshots or Videos

Screenshare.-.2023-07-11.12_56_21.PM.mp4

Additional Information

No response

@jakubsob jakubsob added the bug Something isn't working label Jul 11, 2023
@rszymanski
Copy link
Collaborator

Notes:

  1. The ResizeObserver we are using does not report changes to the element's position. Potentially using the IntersectionObserver might allow us to catch changes of the position
  2. Another option could be providing a JS function that users could call on their events to reposition the empty state e.g. extract this part of the code into a function

@Eduardodudu Eduardodudu mentioned this issue Aug 1, 2023
@rszymanski
Copy link
Collaborator

rszymanski commented Aug 28, 2023

Given the fix attempt in #42 this might be a bit of an edge case.

We figured out how to reposition an item, but if we want to things behave exactly as if there were actually in place of a given component (e.g. the sliding effect in the example in this issue), then I don't have an idea for a different way of handling it besides using renderUI.

What we could do is:

Example Fix
library(shiny)
library(shiny.emptystate)
library(bslib)

ui <- page(
  theme = bs_theme(version = 5),
  use_empty_state(),
  tags$button(
    "Toggle panel",
    class = "btn btn-primary",
    onClick = "$('#container1').toggle(anim = 'slide');"
  ),
  div(
    style = "width: 300px",
    class = "d-flex flex-column gap-5",
    div(
      id = "container1",
      div(
        h1("Card 1"),
        "Card content"
      )
    ),
    div(
      id = "container2",
      div(
        h1("Card 2"),
        uiOutput("card_content")
      )
    )
  )
)

server <- function(input, output, session) {
  empty_state_content <- div(
    "This is example empty state content"
  )
  
  output$card_content <- renderUI({
    empty_state_content
  })
}

shinyApp(ui, server)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants