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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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 @@ -97,6 +97,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`)
})
})
20 changes: 20 additions & 0 deletions packages/react/src/Textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ export type TextareaProps = {
* 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

Copy link
Contributor

Choose a reason for hiding this comment

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

Nah, I feel like with a field its just going to be sooo specific to the use case

/**
* The maximum height of the Textarea
*/
maxHeight?: number
/**
* CSS styles to apply to the Textarea
*/
style?: React.CSSProperties
} & TextareaHTMLAttributes<HTMLTextAreaElement> &
SxProp

Expand All @@ -55,6 +67,9 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
block,
contrast,
className,
minHeight,
maxHeight,
style,
...rest
}: TextareaProps,
ref,
Expand All @@ -78,6 +93,11 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
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,
maxHeight,
...style,
}}
{...rest}
/>
</TextInputBaseWrapper>
Expand Down
Loading