Skip to content

Commit 8b6f1a6

Browse files
committed
fix: make dropdown work with a singular choice
Fixes: #60
1 parent 4f9dc39 commit 8b6f1a6

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

R/inputs.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ build_dropdown_extra_choices <- function(choices) {
129129
if (length(choices) == 0) {
130130
choices_js <- ""
131131
} else {
132-
choices_js <- paste0(", choices: ", rjson::toJSON(choices))
132+
choices_js <- paste0(", choices: ", rjson::toJSON(as.list(choices)))
133133
}
134134

135135
return(choices_js)

tests/testthat/test-inputs.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ test_that("`dropdown_extra` sets choices to blank when length is 0", {
3434
expect_equal(choices, "")
3535
})
3636

37+
test_that("`dropdown_extra` serializes a single value as an array", {
38+
choices <- build_dropdown_extra_choices("a")
39+
40+
expect_equal(choices, ', choices: ["a"]')
41+
})
42+
3743
test_that("`dropdown_extra` sets choices correctly", {
3844
choices <- build_dropdown_extra_choices(letters[1:3])
3945

0 commit comments

Comments
 (0)