import { useEffect, useRef } from 'react'; import DSCharacterCount from '@scottish-government/design-system/dist/scripts/components/character-count/character-count'; import ConditionalWrapper from '../../common/ConditionalWrapper'; import ErrorMessage from '../ErrorMessage'; import HintText from '../../common/HintText'; import { TextInputBase } from '../../shared-types'; import clsx from 'clsx'; const Textarea = ({ className, countThreshold, errorMessage, hasError, hintText, id, label, maxlength, name, onBlur, onChange, placeholder, rows = 4, value, ...props }: TextInputBase) => { const errorMessageId = `error-message-${id}`; const hintTextId = `hint-text-${id}`; const ref = useRef(null); const describedbys: string[] = []; if (hintText) { describedbys.push(hintTextId) }; if (errorMessage) { describedbys.push(errorMessageId) }; useEffect(() => { /* istanbul ignore else */ if (ref.current) { new DSCharacterCount(ref.current).init(); } }, [ref]); function handleBlur(event: React.FocusEvent) { if (typeof onBlur === 'function') { onBlur(event); } } function handleChange(event: React.ChangeEvent) { if (typeof onChange === 'function') { onChange(event); } } return ( 0} wrapper={(children: React.JSX.Element) =>
{children}
} > {hintText && {hintText}} {errorMessage && {errorMessage}}