/*! Strand UI | MIT License | dillingerstaffing.com */ import type { JSX } from "preact"; import { forwardRef } from "preact/compat"; import { useLayoutEffect, useRef } from "preact/hooks"; import { cx, mergeRefs } from "../../internal/index.js"; export interface TextareaProps extends Omit, "onInput" | "value"> { /** Grow to fit the content. */ autoResize?: boolean; /** Show `length/maxLength`; needs `maxLength`. */ showCount?: boolean; /** Error styling and `aria-invalid`. */ error?: boolean; maxLength?: number; onInput?: JSX.GenericEventHandler; disabled?: boolean; value?: string; } /** Fits a textarea's height to its content; the only imperative write, and it needs the box. */ function fit(el: HTMLTextAreaElement | null): void { if (!el) return; const previous = el.style.height; el.style.height = "auto"; const content = el.scrollHeight; // A zero scrollHeight means no layout engine is running; leave the element as it was. if (content > 0) el.style.height = `${content}px`; else if (previous) el.style.height = previous; else if (el.style.length === 0 || (el.style.length === 1 && el.style.height === "auto")) el.removeAttribute("style"); } /** * Multi-line text input with autosize and a character count. * * @example *