({
error = false,
disabled = false,
readOnly = false,
ref,
maxLength,
className,
containerClassName,
label,
helperText,
...rest
}: Omit<TextareaProps, 'avatar'> & { ref: ForwardedRef<HTMLTextAreaElement> })
| 88 | } |
| 89 | |
| 90 | const Root = ({ |
| 91 | error = false, |
| 92 | disabled = false, |
| 93 | readOnly = false, |
| 94 | ref, |
| 95 | maxLength, |
| 96 | className, |
| 97 | containerClassName, |
| 98 | label, |
| 99 | helperText, |
| 100 | ...rest |
| 101 | }: Omit<TextareaProps, 'avatar'> & { ref: ForwardedRef<HTMLTextAreaElement> }) => { |
| 102 | const inputId = useId(); |
| 103 | const helperTextId = useId(); |
| 104 | const [currentLength, setCurrentLength] = useState(0); |
| 105 | |
| 106 | const handleChange = (event: ChangeEvent<HTMLTextAreaElement>) => { |
| 107 | setCurrentLength(event.target.value.length); |
| 108 | rest.onChange?.(event); |
| 109 | }; |
| 110 | |
| 111 | return ( |
| 112 | <div className={clsxMerge(textareaContainerVariants({ error, disabled }), containerClassName)}> |
| 113 | {label && ( |
| 114 | <Label htmlFor={rest.id ?? inputId} size='small' className={clsxMerge(textareaLabelVariants({ disabled }))}> |
| 115 | {label} |
| 116 | </Label> |
| 117 | )} |
| 118 | <textarea |
| 119 | ref={ref} |
| 120 | className={clsxMerge(textareaVariants({ error }), className)} |
| 121 | disabled={disabled} |
| 122 | aria-disabled={disabled} |
| 123 | readOnly={readOnly} |
| 124 | maxLength={maxLength} |
| 125 | onChange={handleChange} |
| 126 | id={rest.id ?? inputId} |
| 127 | aria-describedby={helperText ? helperTextId : undefined} |
| 128 | {...rest} |
| 129 | /> |
| 130 | <p className='flex w-full items-center justify-between text-xs'> |
| 131 | {helperText && ( |
| 132 | <span id={helperTextId} className={clsxMerge('font-medium', textareaHelperTextVariants({ error }))}> |
| 133 | {helperText} |
| 134 | </span> |
| 135 | )} |
| 136 | {maxLength !== undefined && maxLength >= 0 ? ( |
| 137 | <span |
| 138 | id={`${rest.id ?? inputId}-character-count`} |
| 139 | className={clsxMerge(textareaHelperTextVariants({ error }))} |
| 140 | > |
| 141 | {currentLength}/{maxLength} |
| 142 | </span> |
| 143 | ) : null} |
| 144 | </p> |
| 145 | </div> |
| 146 | ); |
| 147 | }; |
nothing calls this directly
no test coverage detected