Skip to content

Commit bcb7cde

Browse files
authored
insertTab() now handles position correctly when target is NULL (#3404)
* Close #3403: insertTab() now handles position correctly when target is NULL * Have insertTab()'s target default to NULL * yarn tsc (GitHub Actions) * yarn build (GitHub Actions) Co-authored-by: cpsievert <[email protected]>
1 parent 052c945 commit bcb7cde

File tree

8 files changed

+14
-48
lines changed

8 files changed

+14
-48
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Imports:
9191
withr,
9292
commonmark (>= 1.7),
9393
glue (>= 1.3.2),
94-
bslib (>= 0.2.5.9001),
94+
bslib (>= 0.2.5.9002),
9595
cachem,
9696
ellipsis,
9797
lifecycle (>= 0.2.0)

R/insert-tab.R

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
#'
113113
#' }
114114
#' @export
115-
insertTab <- function(inputId, tab, target,
115+
insertTab <- function(inputId, tab, target = NULL,
116116
position = c("before", "after"), select = FALSE,
117117
session = getDefaultReactiveDomain()) {
118118
bslib::nav_insert(
@@ -137,48 +137,14 @@ insertTab <- function(inputId, tab, target,
137137
#' @export
138138
prependTab <- function(inputId, tab, select = FALSE, menuName = NULL,
139139
session = getDefaultReactiveDomain()) {
140-
force(select)
141-
force(menuName)
142-
inputId <- session$ns(inputId)
143-
144-
item <- buildTabItem("id", "tsid", TRUE, divTag = tab,
145-
textFilter = if (is.character(tab)) navbarMenuTextFilter else NULL)
146-
147-
callback <- function() {
148-
session$sendInsertTab(
149-
inputId = inputId,
150-
liTag = processDeps(item$liTag, session),
151-
divTag = processDeps(item$divTag, session),
152-
menuName = menuName,
153-
target = NULL,
154-
position = "after",
155-
select = select)
156-
}
157-
session$onFlush(callback, once = TRUE)
140+
bslib::tab_prepend(inputId, tab, menu_title = menuName, select = select, session = session)
158141
}
159142

160143
#' @rdname insertTab
161144
#' @export
162145
appendTab <- function(inputId, tab, select = FALSE, menuName = NULL,
163146
session = getDefaultReactiveDomain()) {
164-
force(select)
165-
force(menuName)
166-
inputId <- session$ns(inputId)
167-
168-
item <- buildTabItem("id", "tsid", TRUE, divTag = tab,
169-
textFilter = if (is.character(tab)) navbarMenuTextFilter else NULL)
170-
171-
callback <- function() {
172-
session$sendInsertTab(
173-
inputId = inputId,
174-
liTag = processDeps(item$liTag, session),
175-
divTag = processDeps(item$divTag, session),
176-
menuName = menuName,
177-
target = NULL,
178-
position = "before",
179-
select = select)
180-
}
181-
session$onFlush(callback, once = TRUE)
147+
bslib::tab_append(inputId, tab, menu_title = menuName, select = select, session = session)
182148
}
183149

184150
#' @rdname insertTab

inst/www/shared/shiny.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/shared/shiny.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/shared/shiny.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/shared/shiny.min.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/insertTab.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

srcts/src/shiny/shinyapp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,13 +1037,13 @@ class ShinyApp {
10371037
if ($targetLiTag) {
10381038
$targetLiTag.before($liTag);
10391039
} else {
1040-
$tabset.append($liTag);
1040+
$tabset.prepend($liTag);
10411041
}
10421042
} else if (message.position === "after") {
10431043
if ($targetLiTag) {
10441044
$targetLiTag.after($liTag);
10451045
} else {
1046-
$tabset.prepend($liTag);
1046+
$tabset.append($liTag);
10471047
}
10481048
}
10491049

0 commit comments

Comments
 (0)