Skip to content
Open
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
7 changes: 6 additions & 1 deletion R/modal.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ modalDialog <- function(..., title = NULL, footer = modalButton("Dismiss"),

size <- match.arg(size)

has_title <- !is.null(title)

backdrop <- if (!easyClose) "static"
keyboard <- if (!easyClose) "false"
div(
Expand All @@ -169,13 +171,16 @@ modalDialog <- function(..., title = NULL, footer = modalButton("Dismiss"),
`data-bs-backdrop` = backdrop,
`data-keyboard` = keyboard,
`data-bs-keyboard` = keyboard,
if (has_title) `aria-labelledby` = "shiny-modal-title",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't quite work as written, we need to assign to the argument when has_title is TRUE:

Suggested change
if (has_title) `aria-labelledby` = "shiny-modal-title",
`aria-labelledby` = if (has_title) "shiny-modal-title",

This relies on a nice htmltools behavior that it will drop NULL attributes (and if (FALSE) "foo" returns NULL in R).


div(
class = "modal-dialog",
class = switch(size, s = "modal-sm", m = NULL, l = "modal-lg", xl = "modal-xl"),
div(class = "modal-content",
if (!is.null(title)) div(class = "modal-header",
tags$h4(class = "modal-title", title)
div(class = "modal-title",
id = "shiny-modal-title",
title)
Comment on lines +181 to +183
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small style nit: Let's put this on one line

Suggested change
div(class = "modal-title",
id = "shiny-modal-title",
title)
div(class = "modal-title", id = "shiny-modal-title", title)

),
div(class = "modal-body", ...),
if (!is.null(footer)) div(class = "modal-footer", footer)
Expand Down