import { Field, FieldDescription, FieldError, Textarea } from "@repo/shadcn-ui/components"; import { cn } from "@repo/shadcn-ui/lib/utils"; import * as React from "react"; import { type FieldPath, type FieldValues, useFormContext } from "react-hook-form"; import { FormFieldLabel } from "./form-field-label.tsx"; import type { NativeTextareaProps } from "./types.ts"; type TextAreaFieldProps = NativeTextareaProps & { name: FieldPath; label?: string; description?: string; orientation?: "vertical" | "horizontal" | "responsive"; inputClassName?: string; }; export function TextAreaField({ name, label, description, required = false, readOnly = false, orientation = "vertical", className, inputClassName, ...inputRest }: TextAreaFieldProps) { const { register, formState, getFieldState } = useFormContext(); const inputId = React.useId(); const disabled = formState.isSubmitting || inputRest.disabled; // Obtener error del campo (tipado seguro) const fieldError = getFieldState(name, formState).error; const handleKeyDown = (e: React.KeyboardEvent) => { inputRest.onKeyDown?.(e); if (e.defaultPrevented) return; // Cmd/Ctrl + Enter para submit if ((e.metaKey || e.ctrlKey) && e.key === "Enter" && !e.nativeEvent.isComposing) { e.preventDefault(); e.currentTarget.form?.requestSubmit(); } }; return ( {label ? ( {label} ) : null}