Skip to content

Commit 35802c1

Browse files
committed
selectInput: add control for size (height)
1 parent f5fd308 commit 35802c1

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

R/bootstrap.R

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -745,22 +745,27 @@ choicesWithNames <- function(choices) {
745745

746746
#' Create a select list input control
747747
#'
748-
#' Create a select list that can be used to choose a single or
749-
#' multiple items from a list of values.
748+
#' Create a select list that can be used to choose a single or multiple items
749+
#' from a list of values.
750750
#'
751751
#' By default, \code{selectInput()} and \code{selectizeInput()} use the
752-
#' JavaScript library \pkg{selectize.js} (\url{https://github.com/brianreavis/selectize.js})
753-
#' to instead of the basic select input element. To use the standard HTML select
754-
#' input element, use \code{selectInput()} with \code{selectize=FALSE}.
752+
#' JavaScript library \pkg{selectize.js}
753+
#' (\url{https://github.com/brianreavis/selectize.js}) to instead of the basic
754+
#' select input element. To use the standard HTML select input element, use
755+
#' \code{selectInput()} with \code{selectize=FALSE}.
755756
#'
756757
#' @inheritParams textInput
757758
#' @param choices List of values to select from. If elements of the list are
758-
#' named then that name rather than the value is displayed to the user.
759+
#' named then that name rather than the value is displayed to the user.
759760
#' @param selected The initially selected value (or multiple values if
760-
#' \code{multiple = TRUE}). If not specified then defaults to the first value
761-
#' for single-select lists and no values for multiple select lists.
761+
#' \code{multiple = TRUE}). If not specified then defaults to the first value
762+
#' for single-select lists and no values for multiple select lists.
762763
#' @param multiple Is selection of multiple items allowed?
763764
#' @param selectize Whether to use \pkg{selectize.js} or not.
765+
#' @param size Number of items to show in the selection box; a larger number
766+
#' will result in a taller box. Not compatible with \code{selectize=TRUE}.
767+
#' Normally, when \code{multiple=FALSE}, a select input will be a drop-down
768+
#' list, but when \code{size} is set, it will be a box instead.
764769
#' @return A select list control that can be added to a UI definition.
765770
#'
766771
#' @family input elements
@@ -773,7 +778,8 @@ choicesWithNames <- function(choices) {
773778
#' "Gears" = "gear"))
774779
#' @export
775780
selectInput <- function(inputId, label, choices, selected = NULL,
776-
multiple = FALSE, selectize = TRUE, width = NULL) {
781+
multiple = FALSE, selectize = TRUE, width = NULL,
782+
size = NULL) {
777783
# resolve names
778784
choices <- choicesWithNames(choices)
779785

@@ -782,10 +788,15 @@ selectInput <- function(inputId, label, choices, selected = NULL,
782788
if (!multiple) selected <- firstChoice(choices)
783789
} else selected <- validateSelected(selected, choices, inputId)
784790

791+
if (!is.null(size) && selectize) {
792+
stop("'size' argument is incompatible with 'selectize=TRUE'.")
793+
}
794+
785795
# create select tag and add options
786796
selectTag <- tags$select(
787797
id = inputId,
788798
class = if (!selectize) "form-control",
799+
size = size,
789800
selectOptions(choices, selected)
790801
)
791802
if (multiple)

man/selectInput.Rd

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
\title{Create a select list input control}
77
\usage{
88
selectInput(inputId, label, choices, selected = NULL, multiple = FALSE,
9-
selectize = TRUE, width = NULL)
9+
selectize = TRUE, width = NULL, size = NULL)
1010

1111
selectizeInput(inputId, ..., options = NULL, width = NULL)
1212
}
@@ -29,6 +29,11 @@ for single-select lists and no values for multiple select lists.}
2929
\item{width}{The width of the input, e.g. \code{'400px'}, or \code{'100\%'};
3030
see \code{\link{validateCssUnit}}.}
3131

32+
\item{size}{Number of items to show in the selection box; a larger number
33+
will result in a taller box. Not compatible with \code{selectize=TRUE}.
34+
Normally, when \code{multiple=FALSE}, a select input will be a drop-down
35+
list, but when \code{size} is set, it will be a box instead.}
36+
3237
\item{...}{Arguments passed to \code{selectInput()}.}
3338

3439
\item{options}{A list of options. See the documentation of \pkg{selectize.js}
@@ -40,14 +45,15 @@ for details).}
4045
A select list control that can be added to a UI definition.
4146
}
4247
\description{
43-
Create a select list that can be used to choose a single or
44-
multiple items from a list of values.
48+
Create a select list that can be used to choose a single or multiple items
49+
from a list of values.
4550
}
4651
\details{
4752
By default, \code{selectInput()} and \code{selectizeInput()} use the
48-
JavaScript library \pkg{selectize.js} (\url{https://github.com/brianreavis/selectize.js})
49-
to instead of the basic select input element. To use the standard HTML select
50-
input element, use \code{selectInput()} with \code{selectize=FALSE}.
53+
JavaScript library \pkg{selectize.js}
54+
(\url{https://github.com/brianreavis/selectize.js}) to instead of the basic
55+
select input element. To use the standard HTML select input element, use
56+
\code{selectInput()} with \code{selectize=FALSE}.
5157
}
5258
\note{
5359
The selectize input created from \code{selectizeInput()} allows

0 commit comments

Comments
 (0)