mirror of
https://github.com/rstudio/shiny.git
synced 2026-04-29 03:00:45 -04:00
Abandon nearest neighbor tab-showing logic. Just grab the first tab.
This commit is contained in:
committed by
Barbara Borges Ribeiro
parent
c090efd562
commit
c1c5873912
@@ -916,41 +916,30 @@ var ShinyApp = function() {
|
||||
}
|
||||
});
|
||||
|
||||
function getNearestTabSibling($liTag) {
|
||||
var siblingTabValue = null;
|
||||
|
||||
// possibilities, in order of desirability
|
||||
var $tabRight = $liTag.nextAll("li:visible").children("a" +
|
||||
"[data-toggle='tab']").first();
|
||||
|
||||
var $tabLeft = $liTag.prevAll("li:visible").children("a" +
|
||||
"[data-toggle='tab']").first();
|
||||
|
||||
var $tabDropRight = $liTag.nextAll("li:visible").children("a" +
|
||||
"[data-toggle='dropdown']").next("ul" +
|
||||
".dropdown-menu").next("li").next("a[data-toggle='tab']").first();
|
||||
|
||||
var $tabDropLeft = $liTag.prevAll("li:visible").children("a" +
|
||||
"[data-toggle='dropdown']").next("ul" +
|
||||
".dropdown-menu").next("li").next("a[data-toggle='tab']").first();
|
||||
|
||||
var possibilities = [$tabRight, $tabLeft, $tabDropRight, $tabDropLeft];
|
||||
|
||||
$.each(possibilities, function(i, $tab) {
|
||||
siblingTabValue = getValueIfExistsAndVisible($tab);
|
||||
if (siblingTabValue !== null) return false; // break out of each()
|
||||
else return true;
|
||||
});
|
||||
|
||||
return siblingTabValue;
|
||||
|
||||
function getValueIfExistsAndVisible($el) {
|
||||
if ($el.length === 1) {
|
||||
return $el.attr("data-value");
|
||||
} else return null;
|
||||
// If the given tabset has no active tabs, s
|
||||
function ensureTabsetHasVisibleTab($tabset) {
|
||||
if ($tabset.find("li.active").length === 0) {
|
||||
// Note: destTabValue may be null. We still want to proceed
|
||||
// through the below logic and setValue so that the input
|
||||
// value for the tabset gets updated (i.e. input$tabsetId
|
||||
// should be null if there are no tabs).
|
||||
let destTabValue = getFirstTab($tabset);
|
||||
let inputBinding = $tabset.data('shiny-input-binding');
|
||||
let evt = jQuery.Event('shiny:updateinput');
|
||||
evt.binding = inputBinding;
|
||||
$tabset.trigger(evt);
|
||||
inputBinding.setValue($tabset[0], destTabValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Given a tabset ul jquery object, return the value of the first tab
|
||||
// (in document order) that's visible and able to be selected.
|
||||
function getFirstTab($ul) {
|
||||
return $ul.find("li:visible a[data-toggle='tab']")
|
||||
.first()
|
||||
.attr("data-value") || null;
|
||||
}
|
||||
|
||||
function tabApplyFunction(target, func) {
|
||||
$.each(target, function(key, el) {
|
||||
if (key === "$liTag") func(el); // $liTag is always just one jQuery element
|
||||
@@ -959,22 +948,14 @@ var ShinyApp = function() {
|
||||
});
|
||||
}
|
||||
|
||||
function navigateToNearestTab($tabset, nextTabValue) {
|
||||
var inputBinding = $tabset.data('shiny-input-binding');
|
||||
var evt = jQuery.Event('shiny:updateinput');
|
||||
evt.binding = inputBinding;
|
||||
$tabset.trigger(evt);
|
||||
inputBinding.setValue($tabset[0], nextTabValue);
|
||||
}
|
||||
|
||||
addMessageHandler("shiny-remove-tab", function(message) {
|
||||
var $tabset = getTabset(message.inputId);
|
||||
var $tabContent = getTabContent($tabset);
|
||||
var target = getTargetTabs($tabset, $tabContent, message.target);
|
||||
var nextTabValue = getNearestTabSibling(target.$liTag);
|
||||
|
||||
tabApplyFunction(target, removeEl);
|
||||
navigateToNearestTab($tabset, nextTabValue);
|
||||
|
||||
ensureTabsetHasVisibleTab($tabset);
|
||||
|
||||
function removeEl($el) {
|
||||
exports.unbindAll($el, true);
|
||||
@@ -986,10 +967,10 @@ var ShinyApp = function() {
|
||||
var $tabset = getTabset(message.inputId);
|
||||
var $tabContent = getTabContent($tabset);
|
||||
var target = getTargetTabs($tabset, $tabContent, message.target);
|
||||
var nextTabValue = getNearestTabSibling(target.$liTag);
|
||||
|
||||
tabApplyFunction(target, changeVisibility);
|
||||
navigateToNearestTab($tabset, nextTabValue);
|
||||
|
||||
ensureTabsetHasVisibleTab($tabset);
|
||||
|
||||
function changeVisibility($el) {
|
||||
if (message.type === "show") $el.css("display", "");
|
||||
|
||||
Reference in New Issue
Block a user