Skip to content

Commit 4deb699

Browse files
authored
Bootstrap 5 support (#3410)
* Bootstrap 5 support for modals & showcase mode * selectizeInput() BS5 compatibility * Both BS4 and 5 define window.bootstrap * Document (GitHub Actions) Co-authored-by: cpsievert <[email protected]>
1 parent ccc8e05 commit 4deb699

File tree

13 files changed

+154
-121
lines changed

13 files changed

+154
-121
lines changed

R/input-select.R

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,9 @@ selectizeDependencyFunc <- function(theme) {
249249
}
250250

251251
selectizeDir <- system.file(package = "shiny", "www/shared/selectize/")
252+
bs_version <- bslib::theme_version(theme)
252253
stylesheet <- file.path(
253-
selectizeDir, "scss",
254-
if ("3" %in% bslib::theme_version(theme)) {
255-
"selectize.bootstrap3.scss"
256-
} else {
257-
"selectize.bootstrap4.scss"
258-
}
254+
selectizeDir, "scss", paste0("selectize.bootstrap", bs_version, ".scss")
259255
)
260256
# It'd be cleaner to ship the JS in a separate, href-based,
261257
# HTML dependency (which we currently do for other themable widgets),

R/modal.R

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,25 @@ removeModal <- function(session = getDefaultReactiveDomain()) {
151151
#' }
152152
#' @export
153153
modalDialog <- function(..., title = NULL, footer = modalButton("Dismiss"),
154-
size = c("m", "s", "l"), easyClose = FALSE, fade = TRUE) {
154+
size = c("m", "s", "l", "xl"), easyClose = FALSE, fade = TRUE) {
155155

156156
size <- match.arg(size)
157157

158-
cls <- if (fade) "modal fade" else "modal"
159-
div(id = "shiny-modal", class = cls, tabindex = "-1",
160-
`data-backdrop` = if (!easyClose) "static",
161-
`data-keyboard` = if (!easyClose) "false",
158+
backdrop <- if (!easyClose) "static"
159+
keyboard <- if (!easyClose) "false"
160+
div(
161+
id = "shiny-modal",
162+
class = "modal",
163+
class = if (fade) "fade",
164+
tabindex = "-1",
165+
`data-backdrop` = backdrop,
166+
`data-bs-backdrop` = backdrop,
167+
`data-keyboard` = keyboard,
168+
`data-bs-keyboard` = keyboard,
162169

163170
div(
164171
class = "modal-dialog",
165-
class = switch(size, s = "modal-sm", m = NULL, l = "modal-lg"),
172+
class = switch(size, s = "modal-sm", m = NULL, l = "modal-lg", xl = "modal-xl"),
166173
div(class = "modal-content",
167174
if (!is.null(title)) div(class = "modal-header",
168175
tags$h4(class = "modal-title", title)
@@ -171,14 +178,25 @@ modalDialog <- function(..., title = NULL, footer = modalButton("Dismiss"),
171178
if (!is.null(footer)) div(class = "modal-footer", footer)
172179
)
173180
),
174-
tags$script("$('#shiny-modal').modal().focus();")
181+
tags$script(
182+
"if (window.bootstrap) {
183+
var modal = new bootstrap.Modal(document.getElementById('shiny-modal'));
184+
modal.show();
185+
} else {
186+
$('#shiny-modal').modal().focus();
187+
}"
188+
)
175189
)
176190
}
177191

178192
#' @export
179193
#' @rdname modalDialog
180194
modalButton <- function(label, icon = NULL) {
181-
tags$button(type = "button", class = "btn btn-default",
182-
`data-dismiss` = "modal", validateIcon(icon), label
195+
tags$button(
196+
type = "button",
197+
class = "btn btn-default",
198+
`data-dismiss` = "modal",
199+
`data-bs-dismiss` = "modal",
200+
validateIcon(icon), label
183201
)
184202
}

R/showcase.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ navTabsHelper <- function(files, prefix = "") {
8383
with(tags,
8484
li(class=if (tolower(file) %in% c("app.r", "server.r")) "active" else "",
8585
a(href=paste("#", gsub(".", "_", file, fixed=TRUE), "_code", sep=""),
86-
"data-toggle"="tab", paste0(prefix, file)))
86+
"data-toggle"="tab", "data-bs-toggle"="tab", paste0(prefix, file)))
8787
)
8888
})
8989
}
@@ -92,7 +92,7 @@ navTabsDropdown <- function(files) {
9292
if (length(files) > 0) {
9393
with(tags,
9494
li(role="presentation", class="dropdown",
95-
a(class="dropdown-toggle", `data-toggle`="dropdown", href="#",
95+
a(class="dropdown-toggle", `data-toggle`="dropdown", `data-bs-toggle`="dropdown", href="#",
9696
role="button", `aria-haspopup`="true", `aria-expanded`="false",
9797
"www", span(class="caret")
9898
),

inst/www/shared/selectize/scss/selectize.bootstrap4.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $selectize-color-text: $input-color !default;
1313
$selectize-color-highlight: rgba(255,237,40,0.4) !default;
1414
$selectize-color-input: $input-bg !default;
1515
$selectize-color-input-full: $input-bg !default;
16-
$selectize-color-input-error: theme-color("danger") !default;
16+
$selectize-color-input-error: $danger !default;
1717
$selectize-color-input-error-focus: darken($selectize-color-input-error, 10%) !default;
1818
$selectize-color-disabled: $input-bg !default;
1919
$selectize-color-item: mix($selectize-color-input, $selectize-color-text, 90%) !default;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$input-line-height-sm: $form-select-line-height !default;
2+
@import 'selectize.bootstrap4';
3+
.selectize-control{padding:0;}

0 commit comments

Comments
 (0)