Skip to content

Commit 728ae30

Browse files
committed
fix: new line insertion and esc stop propagation
1 parent 84faf51 commit 728ae30

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Shared/Components/Textarea/Textarea.component.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useRef } from 'react'
1+
import { TextareaHTMLAttributes, useRef } from 'react'
22
import {
33
COMPONENT_SIZE_TYPE_TO_FONT_AND_BLOCK_PADDING_MAP,
44
COMPONENT_SIZE_TYPE_TO_INLINE_PADDING_MAP,
@@ -54,10 +54,6 @@ const Textarea = ({
5454
updateRefsHeight(nextHeight)
5555
}
5656

57-
useEffect(() => {
58-
reInitHeight()
59-
}, [])
60-
6157
useThrottledEffect(reInitHeight, 300, [props.value])
6258

6359
const handleBlur: TextareaProps['onBlur'] = (event) => {
@@ -77,6 +73,14 @@ const Textarea = ({
7773
}
7874
}
7975

76+
const handleKeyDown: TextareaHTMLAttributes<HTMLTextAreaElement>['onKeyDown'] = (
77+
event: React.KeyboardEvent<HTMLTextAreaElement>,
78+
) => {
79+
if (event.key === 'Enter' || event.key === 'Escape') {
80+
event.stopPropagation()
81+
}
82+
}
83+
8084
return (
8185
<FormFieldWrapper
8286
inputId={name}
@@ -106,6 +110,7 @@ const Textarea = ({
106110
data-testid={name}
107111
required={required}
108112
onBlur={handleBlur}
113+
onKeyDown={handleKeyDown}
109114
className={`${COMPONENT_SIZE_TYPE_TO_FONT_AND_BLOCK_PADDING_MAP[size]} ${COMPONENT_SIZE_TYPE_TO_INLINE_PADDING_MAP[size]} w-100 dc__overflow-auto textarea`}
110115
ref={textareaRef}
111116
style={{

0 commit comments

Comments
 (0)