Skip to content

Commit bb3d9da

Browse files
Fix React warning "Use the defaultValue or value props instead of setting children on <textarea>"
1 parent 91c0094 commit bb3d9da

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ 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 }) => (
9+
const TextareaComponent: FC<TextareaProps> = (props) => (
1010
<SingleInputFormGroup<TextareaProps> inputType="textarea" {...props}>
1111
{({ className, error, textareaRef, ...rest }) => (
1212
<textarea
1313
className={classNames('nhsuk-textarea', { 'nhsuk-textarea--error': error }, className)}
1414
ref={textareaRef}
1515
{...rest}
16-
>
17-
{children}
18-
</textarea>
16+
/>
1917
)}
2018
</SingleInputFormGroup>
2119
);

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)