import { forwardRef, useEffect, useId, useRef, useState, } from "react"; import { CloseIcon, SearchIcon } from "../icons/semantic-icons.js"; import { Field, IconButton } from "./core.js"; import type { TextFieldProps } from "./core.js"; import { useLocale } from "../../i18n/index.js"; type FieldCopy = Readonly<{ id?: string; label: string; description?: string; error?: string; }>; export type TextAreaProps = Omit< React.TextareaHTMLAttributes, "id" > & FieldCopy & Readonly<{ maxLengthMessage?: (remaining: number) => string }>; export const TextArea = forwardRef( function TextArea( { id, label, description, error, required, className = "", maxLength, maxLengthMessage, value, defaultValue, ...props }, ref, ) { const { message } = useLocale(); const [uncontrolledValue, setUncontrolledValue] = useState( String(defaultValue ?? ""), ); const currentValue = value === undefined ? uncontrolledValue : String(value ?? ""); const remaining = typeof maxLength === "number" ? maxLength - currentValue.length : null; return ( {({ controlId, describedBy, invalid }) => ( <>