Skip to content
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions R/module_picks.R
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ picks_srv.picks <- function(id, picks, data) {
.pick_ui_fixed <- function(id, selected) {
htmltools::tags$div(
class = "form-group shiny-input-container",
style = "visibility: hidden; position: absolute;",
htmltools::tags$input(
id = id,
disabled = "disabled",
Expand Down
8 changes: 5 additions & 3 deletions R/ui_containers.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ badge_dropdown <- function(id, label, content) {
htmltools::includeScript(system.file("badge-dropdown", "script.js", package = "teal.picks"))
)),
htmltools::tags$div(
class = "badge-dropdown-wrapper",
class = "badge-wrapper",
htmltools::tags$span(
id = ns("summary_badge"),
class = "badge bg-primary rounded-pill badge-dropdown",
Expand All @@ -32,7 +32,7 @@ badge_dropdown <- function(id, label, content) {
style = htmltools::css(
visibility = "hidden",
width = "0",
position = "absolute",
position = "fixed",
background = "white",
border = "1px solid #ccc",
`border-radius` = "4px",
Expand Down Expand Up @@ -61,6 +61,7 @@ badge_fixed <- function(id, label, content) {
htmltools::includeCSS(system.file("badge-dropdown", "style.css", package = "teal.picks"))
)),
htmltools::tags$div(
class = "badge-wrapper",
htmltools::tags$span(
id = ns("fixed_badge"),
class = "fixed-picks badge-dropdown",
Expand All @@ -69,8 +70,9 @@ badge_fixed <- function(id, label, content) {
),
htmltools::tags$div(
id = ns("inputs_container"),
class = "zero-width-inputs",
content,
style = "visibility: hidden; width: 0; height: 0;"
style = "visibility: hidden; width: 0; height: 0; position: fixed;"
)
)
)
Expand Down
6 changes: 6 additions & 0 deletions inst/badge-dropdown/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function toggleBadgeDropdown(summaryId, containerId) {
container.removeEventListener('transitionend', onHidden);
container.style.visibility = 'hidden';
container.style.width = "0";
container.style.position = "fixed";
$(container).trigger('hidden');
if (container._originalParent) {
container._originalParent.appendChild(container);
Expand All @@ -21,6 +22,10 @@ function toggleBadgeDropdown(summaryId, containerId) {
container._originalParent = container.parentNode;
}

if (container.querySelectorAll('.shiny-input-validation-error').length > 0) {
container._originalParent.classList.add("has-validation-error");
}

// Position relative to the badge
var rect = summary.getBoundingClientRect();
container.style.position = 'absolute';
Expand All @@ -44,6 +49,7 @@ function toggleBadgeDropdown(summaryId, containerId) {
setTimeout(function() {
function handleClickOutside(event) {
if (!container.contains(event.target) && !summary.contains(event.target)) {
container._originalParent.classList.remove("has-validation-error");
hideContainer();
document.removeEventListener('click', handleClickOutside);
}
Expand Down
14 changes: 11 additions & 3 deletions inst/badge-dropdown/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
.badge-dropdown {
overflow-x: auto;
padding-right: 0.5rem;
border: 2px solid transparent;
}

.badge-dropdown:has(~ * .shiny-validation-message),
.badge-dropdown:has(~ * .shiny-output-error) {
border: 2px solid red;
.badge-dropdown:has(~ * .shiny-output-error),
.badge-wrapper.has-validation-error .badge-dropdown {
border: 2px solid var(--bs-danger);
}

.badge-dropdown-label,
Expand Down Expand Up @@ -83,4 +85,10 @@

.fixed-picks i {
flex-shrink: 0;
}
}

.zero-width-inputs .form-group.shiny-input-container {
width: 0;
padding: 0;
border: none;
}
Loading