Skip to content

Commit 599af62

Browse files
committed
fix: max height
1 parent 728ae30 commit 599af62

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TextareaProps } from './types'
1010
import { TEXTAREA_CONSTRAINTS } from './constants'
1111
import './textarea.scss'
1212

13-
const { MIN_HEIGHT, MAX_HEIGHT } = TEXTAREA_CONSTRAINTS
13+
const { MIN_HEIGHT, AUTO_EXPANSION_MAX_HEIGHT } = TEXTAREA_CONSTRAINTS
1414

1515
const Textarea = ({
1616
name,
@@ -37,18 +37,19 @@ const Textarea = ({
3737
}
3838

3939
const reInitHeight = () => {
40+
const currentHeight = parseInt(textareaRef?.current?.style.height, 10)
4041
let nextHeight = textareaRef?.current?.scrollHeight || 0
4142

42-
if (nextHeight < parseInt(textareaRef?.current?.style.height, 10)) {
43+
if (nextHeight < currentHeight || currentHeight > AUTO_EXPANSION_MAX_HEIGHT) {
4344
return
4445
}
4546

4647
if (nextHeight < MIN_HEIGHT) {
4748
nextHeight = MIN_HEIGHT
4849
}
4950

50-
if (nextHeight > MAX_HEIGHT) {
51-
nextHeight = MAX_HEIGHT
51+
if (nextHeight > AUTO_EXPANSION_MAX_HEIGHT) {
52+
nextHeight = AUTO_EXPANSION_MAX_HEIGHT
5253
}
5354

5455
updateRefsHeight(nextHeight)
@@ -114,7 +115,8 @@ const Textarea = ({
114115
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`}
115116
ref={textareaRef}
116117
style={{
117-
maxHeight: MAX_HEIGHT,
118+
// No max height when user is expanding
119+
maxHeight: 'none',
118120
minHeight: MIN_HEIGHT,
119121
}}
120122
/>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export const TEXTAREA_CONSTRAINTS = {
22
MIN_HEIGHT: 56,
3-
MAX_HEIGHT: 140,
3+
AUTO_EXPANSION_MAX_HEIGHT: 140,
44
}

0 commit comments

Comments
 (0)