Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Bug fixes

* `card()` and `value_box()` no longer register `input$<id>_full_screen` for cards that don't have `full_screen = TRUE`, avoiding unexpected inputs in bookmarking workflows. (#1305)

* Fixed label-to-options spacing on `shiny::radioButtons()` and `shiny::checkboxGroupInput()` in Bootstrap 5, where a Shiny rule was overriding the bslib fix. (#1308)

# bslib 0.11.0
Expand Down
13 changes: 8 additions & 5 deletions R/card.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
#' together into one `wrapper` call (e.g. given `card("a", "b",
#' card_body("c"), "d")`, `wrapper` would be called twice, once with `"a"` and
#' `"b"` and once with `"d"`).
#' @param id Provide a unique identifier for the `card()` or `value_box()` to
#' report its full screen state to Shiny. For example, using `id = "my_card"`,
#' you can observe the card's full screen state with
#' `input$my_card_full_screen`.
#' @param id A unique identifier for the card. Note that full-screen
#' capability cannot be added after card creation; `full_screen` must be set
#' at creation time.
#'
#' @return A [htmltools::div()] tag.
#'
Expand Down Expand Up @@ -90,7 +89,11 @@ card <- function(
children <- as_card_items(args[!nzchar(argnames)], wrapper = wrapper)
children <- card_image_add_classes(children)

is_shiny_input <- !is.null(id)
# When full_screen=TRUE and id is provided, the card registers
# input$<id>_full_screen to report its full screen state to Shiny.
# The bslib-card-input class is what triggers this JS-side registration,
# so it must only be added when the card actually has full screen capability.
is_shiny_input <- !is.null(id) && full_screen

if (full_screen && is.null(id)) {
# a11y: full screen cards need an ID for aria-controls on the toggle button
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
7 changes: 3 additions & 4 deletions man/card.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/value_box.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tests/testthat/test-card.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ test_that("card_image()", {
)
})

test_that("card() only registers as Shiny input when full_screen=TRUE", {
card_no_fs <- card(id = "my_card", "content")
card_with_fs <- card(id = "my_card", full_screen = TRUE, "content")
card_fs_no_id <- card(full_screen = TRUE, "content")

classes_no_fs <- htmltools::tagGetAttribute(card_no_fs, "class")
classes_with_fs <- htmltools::tagGetAttribute(card_with_fs, "class")
classes_fs_no_id <- htmltools::tagGetAttribute(card_fs_no_id, "class")

expect_no_match(classes_no_fs, "bslib-card-input")
expect_match(classes_with_fs, "bslib-card-input")
expect_no_match(classes_fs_no_id, "bslib-card-input")
})

test_that("card_image() input validation", {
expect_snapshot(
error = TRUE,
Expand Down