Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

data-grow

Auto-expand a textarea as the user types, from its rows up to an optional data-max-rows cap. CSS field-sizing where supported, a JavaScript measuring fallback elsewhere.

Overview

data-grow on a <textarea> makes it grow with its content and shrink back when text is removed. It starts at rows lines and, with data-max-rows, stops growing at that many lines and scrolls. Browsers with field-sizing: content do the sizing in CSS; elsewhere a script measures scrollHeight.

Usage

With field-sizing (CSS path)

  1. CSS sets field-sizing: content and resize: none on textarea[data-grow], so the textarea grows even before the script runs.
  2. The minimum height is rows lines plus padding and border (field-sizing itself ignores rows, and VB's usual 8rem textarea minimum does not apply).
  3. With data-max-rows, max-block-size is that many lines plus padding and border; past it the textarea scrolls.
  4. The script only writes --grow-rows and --grow-max-rows and marks the textarea data-grow-init="". Programmatic values resize on their own.

Without field-sizing (JavaScript fallback)

  1. The textarea is marked data-grow-init="fallback"; only this path hides overflow and the resize handle.
  2. On input, change and after a form reset, the height is set to auto and then to scrollHeight plus the border, so it shrinks as well as grows.
  3. With data-max-rows the height is capped at that many lines plus padding and border, and overflow-y switches to auto past the cap.

Options

AttributeValuesDefaultEffect
data-grow boolean — Turns auto-grow on.
rows number 2 Native attribute. The starting and minimum height in lines; the textarea never shrinks below it.
data-max-rows positive number no cap Lines after which the textarea stops growing and scrolls. 0 or an invalid value means no cap.
data-grow-init set by the script — "" on the CSS path, "fallback" on the JavaScript path. Do not set it yourself. It is not the double-binding guard, so a cloned textarea (which copies it) is still wired.

Events

No custom events. The fallback listens for input and change. Setting .value from script fires neither: with field-sizing the height follows anyway, but for the fallback (and for a data-count counter on the same textarea) dispatch an input event afterwards. Form resets are handled for you.

Styling

No public custom properties: --grow-rows and --grow-max-rows are written by the script from rows and data-max-rows; set those attributes instead. The shipped rules:

Without JavaScript

  • With field-sizing support the textarea still grows. Its minimum is two lines (the script is what reads rows).
  • data-max-rows still caps it in browsers that support typed attr(), which read the attribute directly; in others the textarea grows without a cap.
  • Without field-sizing support it keeps its rows height and the native resize handle.

Accessibility

  • The native <textarea> is untouched, so labels, keyboard use and screen-reader support are unchanged.
  • Growing shows all text without an inner scrollbar, which helps users who zoom or have trouble with nested scrolling. Past data-max-rows the textarea scrolls like any other.
  • The resize handle is removed while the textarea sizes itself; set a generous data-max-rows (or none) so long text stays readable.

Examples

Max rows

Minimum and maximum rows

rows sets where it starts, data-max-rows where it stops.

With data-count

Added later

Textareas added after load are enhanced automatically.

Related

  • <textarea> — the element this attribute goes on.
  • data-count — a live character or word counter; combines with data-grow.
  • <chat-input> — a message composer built on a data-grow textarea with send controls. Choose it for chat-style input; use plain data-grow in ordinary forms.
  • <form-field> — the label and message wrapper used in the examples.
  • data-autosave — restored drafts re-measure the textarea.
↑