Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAlways set data-value attribute for .sidebarMenuSelectedTabItem #216
Conversation
…uSelectedTabItem` is always set in the body of the `ensureActivatedTab()` function
|
I'm having a bit of a hard time following the logic in the code... I could be missing something, but can all that code be reduced to this? var $startTab = $tablinks.filter("[data-start-selected='1']");
if ($startTab.length === 0) {
// If no tab starts selected, use the first one, if present
$startTab = $tablinks.first();
}
// If there are no tabs, $startTab.length will be 0.
if ($startTab.length !== 0) {
$startTab.tab("show");
$(".sidebarMenuSelectedTabItem").attr("data-value",
$startTab.attr("data-value"));
}The things I'm not sure about are:
|
I've pushed your code, after some testing. I think we're good to go..? |
|
Now that I look at it some more, I think that I think this behaves the same as before, but there's some weird behavior with the tab1 menuItem. It doesn't start expanded, and also, when it is expanded and you click on tab1_1, the little arrow on the right changes from pointing down to pointing left. But that's sort of a separate issue, and fixing those things could be a separate PR if you prefer. library(shinydashboard)
library(shiny)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(id = "tabs",
menuItem("tab1",
menuSubItem("tab1_1", tabName = "tab1_1")
),
menuItem("tab2", tabName = "tab2")
)),
dashboardBody(
tabItems(
tabItem("tab1", "This is tab 1"),
tabItem("tab1_1", "This is tab 1_1"),
tabItem("tab2", "This is tab 2")
)
)
)
server <- function(input, output, session){
observe({ print(input$tabs) })
}
shinyApp(ui, server) |
Fixes #214: make sure that the
data-valueattribute of.sidebarMenuSelectedTabItemis always set in the body of theensureActivatedTab()function.Repro
See #214 or here is a more concise one (bug:
input$tabsshould start out with the value"tab1", but it starts out withNULLand stays that way until you click on the other tab):Postemortem
This bug was hard to spot for a few reasons:
selected = TRUEon any tab (the default). I.e. this has the right behavior:It disappears as soon as you move on to another tab.
It's orthogonal to the matching up of
menuItems andtabItems. I.e. this works works as expected, even thoughinput$tabsstarts out NULL as well: