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

chat-input

Form-associated chat input with auto-growing textarea, Enter-to-send, and keyboard shortcuts.

Overview

A form-associated web component (static formAssociated = true) that wraps a textarea[data-grow] with send controls. Light DOM, participates in native form submission, validation, reset and <fieldset disabled> via ElementInternals. The textarea auto-resizes using VB's existing textarea-grow-init utility.

It has two send paths. Inside a <form>, sending submits the form. Standalone, it dispatches chat-input:send. <chat-window> uses the standalone path.

Attributes

Attribute Type Default Description
name string - Form field name. Required for the value to appear in FormData
maxlength number 4000 Character limit. Over the limit the element is invalid (tooLong) and sending is blocked
minlength number 1 Minimum trimmed length to send. Prevents empty sends
disabled boolean - Disables the textarea and send button. An ancestor <fieldset disabled> does the same
autofocus boolean - Focus textarea on connect

Keyboard

Key Action
Enter Send the message (submits the form when inside one). Ignored while an IME composition is active, so composing CJK text never sends mid-word
Shift+Enter Insert newline
Escape Clear input

Basic Usage

The child <textarea data-grow> auto-resizes. The [data-send] button triggers submission.

Accessible Name

A placeholder is not a label. Give the textarea an accessible name with aria-label, aria-labelledby or a <label for>. If the textarea has none, chat-input adds aria-label="Message" as a fallback. The fallback is generic, so write a label that fits the context ("Reply to Sarah", "Ask the assistant").

The textarea drops its own border, so chat-input draws the focus ring while the textarea has focus. The ring uses the --focus-ring-* tokens and is inset so a clipping parent cannot hide it.

Inside a Form

As a form-associated element, chat-input takes part in native FormData, form submit, constraint validation and reset(). Inside a form, Enter and the [data-send] button submit the form. Enter calls requestSubmit(), so validation and the submit event run as they would for a button click. No chat-input:send event fires in this mode.

The input clears after the submit event, unless a listener calls preventDefault(). A prevented submit means the page handles the outcome, for example by sending with fetch(). Call form.reset() when it succeeds.

Disabled State

Set disabled to prevent input. This disables the textarea and the send button and reduces opacity. It works whether the attribute is in the markup, set later, or comes from an ancestor <fieldset disabled>.

Events

Event Detail When
chat-input:send { message } Enter key or send button click when the input is not inside a form. message is trimmed. The input clears afterwards
chat-input:input { value, length } Keystroke (debounced 100ms)
chat-input:change { value, source: 'api' } The value property was set to a new value (no event when the value is unchanged)

Public API

Member Type Description
value string (get/set) Current textarea content
form HTMLFormElement | null (get) The associated form
name string (get) The name attribute
validity / validationMessage ValidityState / string (get) Constraint validation state (tooLong over maxlength)
checkValidity() / reportValidity() method Native constraint validation
focus() method Focus the textarea
reset() method Clear value and resize
disabled boolean (get/set) Disable/enable state

CSS Variables

Variable Default Description
--chat-input-bg var(--color-surface) Input area background
--chat-input-border var(--border-width-thin) solid var(--color-border) Top border
--chat-input-padding var(--size-s) Internal padding
--chat-input-max-height 12lh Maximum textarea height

Related

↑