Skip to content

Commit

Permalink
fix: make dropdown work with a singular choice
Browse files Browse the repository at this point in the history
Fixes: #60
  • Loading branch information
TymekDev committed Aug 5, 2024
1 parent 4f9dc39 commit 8b6f1a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/inputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ build_dropdown_extra_choices <- function(choices) {
if (length(choices) == 0) {
choices_js <- ""
} else {
choices_js <- paste0(", choices: ", rjson::toJSON(choices))
choices_js <- paste0(", choices: ", rjson::toJSON(as.list(choices)))
}

return(choices_js)
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-inputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ test_that("`dropdown_extra` sets choices to blank when length is 0", {
expect_equal(choices, "")
})

test_that("`dropdown_extra` serializes a single value as an array", {
choices <- build_dropdown_extra_choices("a")

expect_equal(choices, ', choices: ["a"]')
})

test_that("`dropdown_extra` sets choices correctly", {
choices <- build_dropdown_extra_choices(letters[1:3])

Expand Down

0 comments on commit 8b6f1a6

Please sign in to comment.