Skip to content

Commit 4290e2e

Browse files
committed
Merge pull request rstudio#702 from wch/select-width
Allow control over selectize width
2 parents 4e8632d + ab6df9f commit 4290e2e

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

R/bootstrap.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -800,13 +800,14 @@ selectInput <- function(inputId, label, choices, selected = NULL,
800800
# return label and select tag
801801
res <- div(
802802
class = "form-group shiny-input-container",
803+
style = if (!is.null(width)) paste0("width: ", validateCssUnit(width)),
803804
controlLabel(inputId, label),
804805
div(selectTag)
805806
)
806807

807808
if (!selectize) return(res)
808809

809-
selectizeIt(inputId, res, NULL, width, nonempty = !multiple && !("" %in% choices))
810+
selectizeIt(inputId, res, NULL, nonempty = !multiple && !("" %in% choices))
810811
}
811812

812813
firstChoice <- function(choices) {
@@ -865,11 +866,15 @@ needOptgroup <- function(choices) {
865866
#' \code{selectInput(..., selectize = FALSE)}.
866867
#' @export
867868
selectizeInput <- function(inputId, ..., options = NULL, width = NULL) {
868-
selectizeIt(inputId, selectInput(inputId, ..., selectize = FALSE), options, width)
869+
selectizeIt(
870+
inputId,
871+
selectInput(inputId, ..., selectize = FALSE, width = width),
872+
options
873+
)
869874
}
870875

871876
# given a select input and its id, selectize it
872-
selectizeIt <- function(inputId, select, options, width = NULL, nonempty = FALSE) {
877+
selectizeIt <- function(inputId, select, options, nonempty = FALSE) {
873878
res <- checkAsIs(options)
874879

875880
selectizeDep <- htmlDependency(
@@ -890,7 +895,6 @@ selectizeIt <- function(inputId, select, options, width = NULL, nonempty = FALSE
890895
type = 'application/json',
891896
`data-for` = inputId, `data-nonempty` = if (nonempty) '',
892897
`data-eval` = if (length(res$eval)) HTML(toJSON(res$eval)),
893-
`data-width` = validateCssUnit(width),
894898
if (length(res$options)) HTML(toJSON(res$options)) else '{}'
895899
)
896900
)

inst/www/shared/shiny.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,8 @@ table.data td[align=right] {
181181
.well .shiny-input-container {
182182
width: auto;
183183
}
184+
185+
/* Width of non-selectize select inputs */
186+
.shiny-input-container > div > select:not(.selectized) {
187+
width: 100%;
188+
}

inst/www/shared/shiny.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2378,7 +2378,6 @@
23782378
control.destroy();
23792379
control = $el.selectize(settings)[0].selectize;
23802380
}
2381-
$el.next('div.selectize-control').css('width', config.data('width'));
23822381
return control;
23832382
}
23842383
});

0 commit comments

Comments
 (0)