Skip to content

Commit 316c3c8

Browse files
authored
feat(textAreaInput): Add an autoresize option (#4210)
* feat(textAreaInput): Add an autoresize option * `devtools::document()` (GitHub Actions) * `yarn build` (GitHub Actions) * Update NEWS.md * Fix broken CSS selector. Rules aren't being applied correctly in PyShiny either... * Put shiny input class on container (to mirror what PyShiny does) * Refactor autoresize logic * Reduce diff size --------- Co-authored-by: cpsievert <[email protected]>
1 parent f79a22b commit 316c3c8

File tree

11 files changed

+160
-42
lines changed

11 files changed

+160
-42
lines changed

NEWS.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# shiny (development version)
22

3-
## New features and improvements
3+
## New features
4+
5+
* `textInput()`, `textAreaInput()`, `numericInput()` and `passwordInput()` all gain an `updateOn` option. `updateOn = "change"` is the default and previous behavior, where the input value updates immediately whenever the value changes. With `updateOn = "blur"`, the input value will update only when the text input loses focus or when the user presses Enter (or Cmd/Ctrl + Enter for `textAreaInput()`). (#4183)
6+
7+
* `textAreaInput()` gains a `autoresize` option, which automatically resizes the text area to fit its content. (#4210)
8+
9+
## Improvements
10+
11+
* When auto-reload is enabled, Shiny now reloads the entire app when support files, like Shiny modules, additional script files, or web assets, change. To enable auto-reload, call `devmode(TRUE)` to enable Shiny's developer mode, or set `options(shiny.autoreload = TRUE)` to specifically enable auto-reload. You can choose which files are watched for changes with the `shiny.autoreload.pattern` option. (#4184)
412

513
* When busy indicators are enabled (i.e., `useBusyIndicators()`), Shiny now:
614
* Shows a spinner on recalculating htmlwidgets that have previously rendered an error (including `req()` and `validate()`). (#4172)
@@ -11,10 +19,6 @@
1119

1220
* Shiny's Typescript assets are now compiled to ES2021 instead of ES5. (#4066)
1321

14-
* `textInput()`, `textAreaInput()`, `numericInput()` and `passwordInput()` all gain an `updateOn` option. `updateOn = "change"` is the default and previous behavior, where the input value updates immediately whenever the value changes. With `updateOn = "blur"`, the input value will update only when the text input loses focus or when the user presses Enter (or Cmd/Ctrl + Enter for `textAreaInput()`). (#4183)
15-
16-
* When auto-reload is enabled, Shiny now reloads the entire app when support files, like Shiny modules, additional script files, or web assets, change. To enable auto-reload, call `devmode(TRUE)` to enable Shiny's developer mode, or set `options(shiny.autoreload = TRUE)` to specifically enable auto-reload. You can choose which files are watched for changes with the `shiny.autoreload.pattern` option. (#4184)
17-
1822
## Bug fixes
1923

2024
* Fixed a bug with modals where calling `removeModal()` too quickly after `showModal()` would fail to remove the modal if the remove modal message was received while the modal was in the process of being revealed. (#4173)

R/input-textarea.R

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#' @param resize Which directions the textarea box can be resized. Can be one of
1717
#' `"both"`, `"none"`, `"vertical"`, and `"horizontal"`. The default, `NULL`,
1818
#' will use the client browser's default setting for resizing textareas.
19+
#' @param autoresize If `TRUE`, the textarea will automatically resize to fit
20+
#' the input text.
1921
#' @return A textarea input control that can be added to a UI definition.
2022
#'
2123
#' @family input elements
@@ -52,6 +54,7 @@ textAreaInput <- function(
5254
placeholder = NULL,
5355
resize = NULL,
5456
...,
57+
autoresize = FALSE,
5558
updateOn = c("change", "blur")
5659
) {
5760
rlang::check_dots_empty()
@@ -63,22 +66,27 @@ textAreaInput <- function(
6366
resize <- match.arg(resize, c("both", "none", "vertical", "horizontal"))
6467
}
6568

66-
style <- css(
67-
# The width is specified on the parent div.
68-
width = if (!is.null(width)) "100%",
69-
height = validateCssUnit(height),
70-
resize = resize
71-
)
69+
classes <- "form-control"
70+
if (autoresize) {
71+
classes <- c(classes, "textarea-autoresize")
72+
if (is.null(rows)) {
73+
rows <- 1
74+
}
75+
}
7276

7377
div(
74-
class = "form-group shiny-input-container",
78+
class = "shiny-input-textarea form-group shiny-input-container",
79+
style = css(width = validateCssUnit(width)),
7580
shinyInputLabel(inputId, label),
76-
style = if (!is.null(width)) paste0("width: ", validateCssUnit(width), ";"),
7781
tags$textarea(
7882
id = inputId,
79-
class = "shiny-input-textarea form-control",
83+
class = classes,
8084
placeholder = placeholder,
81-
style = style,
85+
style = css(
86+
width = if (!is.null(width)) "100%",
87+
height = validateCssUnit(height),
88+
resize = resize
89+
),
8290
rows = rows,
8391
cols = cols,
8492
`data-update-on` = updateOn,

inst/www/shared/shiny.js

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/shared/shiny.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/shared/shiny.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)