Skip to content

Commit 9e49abd

Browse files
authored
Textarea: Add minHeight and maxHeight as props (#6182)
1 parent fbdcac4 commit 9e49abd

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

.changeset/social-ants-bow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': minor
3+
---
4+
5+
Textarea: Adds `minHeight` and `maxHeight` as props

packages/react/src/Textarea/Textarea.docs.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@
9797
"name": "className",
9898
"type": "string | undefined",
9999
"description": "The className to apply to the wrapper element"
100+
},
101+
{
102+
"name": "minHeight",
103+
"type": "number",
104+
"description": "The minimum height of the textarea"
105+
},
106+
{
107+
"name": "maxHeight",
108+
"type": "number",
109+
"description": "The maximum height of the textarea"
100110
}
101111
],
102112
"subcomponents": []

packages/react/src/Textarea/Textarea.features.stories.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,21 @@ export const CustomResizeBehavior = () => (
104104
</FormControl>
105105
</Stack>
106106
)
107+
108+
export const MinimumHeight = () => (
109+
<Box as="form">
110+
<FormControl>
111+
<FormControl.Label>Default label</FormControl.Label>
112+
<Textarea rows={1} minHeight={100} />
113+
</FormControl>
114+
</Box>
115+
)
116+
117+
export const MaximumHeight = () => (
118+
<Box as="form">
119+
<FormControl>
120+
<FormControl.Label>Default label</FormControl.Label>
121+
<Textarea rows={20} maxHeight={200} />
122+
</FormControl>
123+
</Box>
124+
)

packages/react/src/Textarea/Textarea.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,16 @@ describe('Textarea', () => {
138138
rerender(<Textarea validationStatus="error" />)
139139
expect(textareaElement).toHaveAttribute('aria-invalid', 'true')
140140
})
141+
142+
it('renders textarea with minHeight and maxHeight styles', () => {
143+
const minHeight = 100
144+
const maxHeight = 200
145+
render(<Textarea minHeight={minHeight} maxHeight={maxHeight} />)
146+
147+
const textareaElement = screen.getByRole('textbox') as HTMLTextAreaElement
148+
const style = window.getComputedStyle(textareaElement)
149+
150+
expect(style.minHeight).toBe(`${minHeight}px`)
151+
expect(style.maxHeight).toBe(`${maxHeight}px`)
152+
})
141153
})

packages/react/src/Textarea/Textarea.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ export type TextareaProps = {
3434
* The className to apply to the wrapper element
3535
*/
3636
className?: string
37+
/**
38+
* The minimum height of the Textarea
39+
*/
40+
minHeight?: number
41+
/**
42+
* The maximum height of the Textarea
43+
*/
44+
maxHeight?: number
45+
/**
46+
* CSS styles to apply to the Textarea
47+
*/
48+
style?: React.CSSProperties
3749
} & TextareaHTMLAttributes<HTMLTextAreaElement> &
3850
SxProp
3951

@@ -55,6 +67,9 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
5567
block,
5668
contrast,
5769
className,
70+
minHeight,
71+
maxHeight,
72+
style,
5873
...rest
5974
}: TextareaProps,
6075
ref,
@@ -78,6 +93,11 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
7893
rows={rows}
7994
cols={cols}
8095
className={classes.TextArea}
96+
style={{
97+
minHeight,
98+
maxHeight,
99+
...style,
100+
}}
81101
{...rest}
82102
/>
83103
</TextInputBaseWrapper>

0 commit comments

Comments
 (0)