Skip to content

Commit 84977a6

Browse files
Fix React warning "Use the defaultValue or value props instead of setting children on <textarea>"
1 parent 424bfbe commit 84977a6

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/components/form-elements/textarea/Textarea.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import SingleInputFormGroup from '@components/utils/SingleInputFormGroup';
66
type TextareaProps = HTMLProps<HTMLTextAreaElement> &
77
FormElementProps & { textareaRef?: MutableRefObject<HTMLTextAreaElement | null> };
88

9-
const TextareaComponent: FC<TextareaProps> = ({ children, ...props }) => (
10-
<SingleInputFormGroup<TextareaProps> inputType="textarea" {...props}>
11-
{({ className, error, textareaRef, ...rest }) => (
12-
<textarea
13-
className={classNames('nhsuk-textarea', { 'nhsuk-textarea--error': error }, className)}
14-
ref={textareaRef}
15-
{...rest}
16-
>
9+
const TextareaComponent: FC<TextareaProps> = (props) => (
10+
<SingleInputFormGroup <TextareaProps> inputType="textarea" {...props}>
11+
{({ children, className, error, textareaRef, ...rest }) => (
12+
<>
13+
<textarea
14+
className={classNames('nhsuk-textarea', { 'nhsuk-textarea--error': error }, className)}
15+
ref={textareaRef}
16+
{...rest}
17+
/>
1718
{children}
18-
</textarea>
19+
</>
1920
)}
2021
</SingleInputFormGroup>
2122
);

stories/Form Elements/CharacterCount.stories.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,15 @@ export const MessageThresholdPercentage: Story = {
7979
thresholdPercent={75}
8080
>
8181
<Label htmlFor="threshold">Can you provide more detail?</Label>
82-
<Textarea id="threshold" className="nhsuk-js-character-count" name="threshold" rows={5}>
83-
Type another letter into this field after this message to see the threshold feature
84-
</Textarea>
82+
<Textarea
83+
id="threshold"
84+
className="nhsuk-js-character-count"
85+
name="threshold"
86+
defaultValue={
87+
'Type another letter into this field after this message to see the threshold feature'
88+
}
89+
rows={5}
90+
/>
8591
</CharacterCount>
8692
),
8793
};

0 commit comments

Comments
 (0)