Skip to content

Textarea: Add minHeight and maxHeight as props #6182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/social-ants-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': minor
---

Textarea: Adds `minHeight` and `maxHeight` as props
10 changes: 10 additions & 0 deletions packages/react/src/Textarea/Textarea.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@
"name": "className",
"type": "string | undefined",
"description": "The className to apply to the wrapper element"
},
{
"name": "minHeight",
"type": "number",
"description": "The minimum height of the textarea",
},
{
"name": "maxHeight",
"type": "number",
"description": "The maximum height of the textarea"
}
],
"subcomponents": []
Expand Down
18 changes: 18 additions & 0 deletions packages/react/src/Textarea/Textarea.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,21 @@ export const CustomResizeBehavior = () => (
</FormControl>
</Stack>
)

export const MinimumHeight = () => (
<Box as="form">
<FormControl>
<FormControl.Label>Default label</FormControl.Label>
<Textarea rows={1} minHeight={100} />
</FormControl>
</Box>
)

export const MaximumHeight = () => (
<Box as="form">
<FormControl>
<FormControl.Label>Default label</FormControl.Label>
<Textarea rows={20} maxHeight={200} />
</FormControl>
</Box>
)
12 changes: 12 additions & 0 deletions packages/react/src/Textarea/Textarea.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,16 @@ describe('Textarea', () => {
rerender(<Textarea validationStatus="error" />)
expect(textareaElement).toHaveAttribute('aria-invalid', 'true')
})

it('renders textarea with minHeight and maxHeight styles', () => {
const minHeight = 100
const maxHeight = 200
render(<Textarea minHeight={minHeight} maxHeight={maxHeight} />)

const textareaElement = screen.getByRole('textbox') as HTMLTextAreaElement
const style = window.getComputedStyle(textareaElement)

expect(style.minHeight).toBe(`${minHeight}px`)
expect(style.maxHeight).toBe(`${maxHeight}px`)
})
})
14 changes: 14 additions & 0 deletions packages/react/src/Textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
* The className to apply to the wrapper element
*/
className?: string
/**
* The minimum height of the Textarea
*/
minHeight?: number
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use small/medium/large/xlarge instead? 🤔 CC: @langermank

/**
* The maximum height of the Textarea
*/
maxHeight?: number
} & TextareaHTMLAttributes<HTMLTextAreaElement> &
SxProp

Expand All @@ -55,6 +63,8 @@
block,
contrast,
className,
minHeight,
maxHeight,
...rest
}: TextareaProps,
ref,
Expand All @@ -78,6 +88,10 @@
rows={rows}
cols={cols}
className={classes.TextArea}
style={{
Copy link
Preview

Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] User-supplied style props may override these height settings; consider merging existing rest.style first (e.g. style={{ ...rest.style, minHeight, maxHeight }}) to avoid unintentional overrides.

Suggested change
style={{
style={{
...rest.style,

Copilot uses AI. Check for mistakes.

minHeight: minHeight,

Check failure on line 92 in packages/react/src/Textarea/Textarea.tsx

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand
maxHeight: maxHeight,

Check failure on line 93 in packages/react/src/Textarea/Textarea.tsx

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand
}}
{...rest}
/>
</TextInputBaseWrapper>
Expand Down
Loading