Skip to content

Commit

Permalink
fix!: clear single-selection dropdown on character(0) and ""
Browse files Browse the repository at this point in the history
Prior to this change only multi-selection dropdown could be cleared.
This change makes `update_dropdown_input` behavior analogous to
`shiny::updateSelectInput`.

Note: this is a breaking change. Prior to this commit updating with
`character(0)` or `""` did not have any effect.
  • Loading branch information
TymekDev committed Mar 20, 2024
1 parent f330c5e commit 24ed837
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion R/dropdown.R
Expand Up @@ -149,7 +149,8 @@ selectInput <- function(inputId, label, choices, selected = NULL, multiple = FAL
#' @param input_id The id of the input object
#' @param choices All available options one can select from. If no need to update then leave as \code{NULL}
#' @param choices_value What reactive value should be used for corresponding choice.
#' @param value The initially selected value.
#' @param value A value to update dropdown to. \code{character(0)} and \code{""} clear the dropdown.
#' \code{NULL} (the default) does not change selection.
#'
#' @examples
#' if (interactive()) {
Expand Down
4 changes: 4 additions & 0 deletions inst/www/shiny-semantic-dropdown.js
Expand Up @@ -32,6 +32,10 @@ $.extend(semanticDropdownBinding, {

// Given the DOM element for the input, set the value.
setValue: function(el, value) {
if (value === '') {
$(el).dropdown('clear');
return;
}
if ($(el).hasClass('multiple')) {
$(el).dropdown('clear', true);
value.split(",").map(v => $(el).dropdown('set selected', v));
Expand Down
3 changes: 2 additions & 1 deletion man/update_dropdown_input.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24ed837

Please sign in to comment.