import { Input as Primitive } from "@base-ui/react/input"; import * as React from "react"; import { cn } from "../cn.ts"; /** Below this width a textarea wraps almost every word, so `scrollHeight` jumps straight to * the cap and the field opens to full height for one word. Under it, let CSS decide. */ const TEXTAREA_MIN_AUTO_WIDTH = 180; /** Past this the textarea stops growing and starts scrolling, so a long paste cannot push * the submit button off the screen. */ const TEXTAREA_MAX_HEIGHT = 160; /** * The inline height an autosizing textarea should carry, or `""` for "leave it to CSS". * * ponytail: this whole observer is here only until `field-sizing: content` is baseline. One CSS * line does the same job. Ceiling: it does not exist in every browser we support yet. */ export function textareaHeight(clientWidth: number, scrollHeight: number): string { if (clientWidth < TEXTAREA_MIN_AUTO_WIDTH) return ""; return `${Math.min(scrollHeight, TEXTAREA_MAX_HEIGHT)}px`; } type FieldChrome = { label?: React.ReactNode; /** * The message under the field. Its presence is what wires `aria-invalid` and * `aria-describedby`, so a field that looks wrong also announces that it is. */ error?: React.ReactNode; /** * Classes for the control. A plain string here, not Base UI's state-callback form: this * component renders a native `