Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8ee5ebc
feat(textarea): 789012 - Add Textarea component
Jacksonmills Oct 3, 2025
1ec8837
add demos
Jacksonmills Oct 3, 2025
d4ef9bb
Merge branch 'master' into feat/718-Textarea
Jacksonmills Oct 3, 2025
2d08361
revert form demo change
Jacksonmills Oct 3, 2025
46c7bc4
Merge branch 'feat/718-Textarea' of github.com:Jacksonmills/base-ui i…
Jacksonmills Oct 3, 2025
c2b25c6
prettier
Jacksonmills Oct 3, 2025
671258b
dedupe
Jacksonmills Oct 3, 2025
42d30cf
stylelint
Jacksonmills Oct 3, 2025
933f4de
Merge branch 'master' into feat/718-Textarea
Jacksonmills Oct 3, 2025
5389067
Remove field-sizing from examples
Jacksonmills Oct 3, 2025
863b1c9
update docs
Jacksonmills Oct 3, 2025
dd9e92b
Merge branch 'feat/718-Textarea' of github.com:Jacksonmills/base-ui i…
Jacksonmills Oct 3, 2025
597384c
Remove 'compact' attribute from demo components in textarea documenta…
Jacksonmills Oct 3, 2025
a6eae6a
Enhance Textarea component with automatic height resizing and hidden …
Jacksonmills Oct 3, 2025
f346f3f
Extracts height calc and debounces resize
Jacksonmills Oct 4, 2025
0d9d6b6
Improve textarea style copying
Jacksonmills Oct 4, 2025
8478164
adopting the MUI Firefox double-set workaround, leading to more stabl…
Jacksonmills Oct 4, 2025
e96711a
Remove forced resize none
Jacksonmills Oct 4, 2025
a6b97b8
moved resize none to example CSS
Jacksonmills Oct 4, 2025
bea34bf
Add field-sizing demo
Jacksonmills Oct 4, 2025
fa6f22f
dedupe
Jacksonmills Oct 4, 2025
35e5187
cleanup comments
Jacksonmills Oct 4, 2025
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
58 changes: 58 additions & 0 deletions docs/reference/generated/textarea.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "Textarea",
"description": "A native textarea element that automatically works with [Field](https://base-ui.com/react/components/field).\nRenders an `<textarea>` element.",
"props": {
"defaultValue": {
"type": "string | number | string[]",
"detailedType": "string | number | string[] | undefined"
},
"onValueChange": {
"type": "((value: string, eventDetails: Textarea.ChangeEventDetails) => void)",
"description": "Callback fired when the `value` changes. Use when controlled.",
"detailedType": "| ((\n value: string,\n eventDetails: Textarea.ChangeEventDetails,\n ) => void)\n| undefined"
},
"maxRows": {
"type": "number",
"description": "Limit automatic height resizing to this many rows.",
"detailedType": "number | undefined"
},
"minRows": {
"type": "number",
"description": "Enable automatic height resizing by setting the minimum number of rows.\n\nPrefer the CSS property `field-sizing: content` when supported (not\nsupported in Safari and Firefox).",
"detailedType": "number | undefined"
},
"className": {
"type": "string | ((state: Field.Root.State) => string)",
"description": "CSS class applied to the element, or a function that\nreturns a class based on the component’s state."
},
"render": {
"type": "ReactElement | ((props: HTMLProps, state: Field.Root.State) => ReactElement)",
"description": "Allows you to replace the component’s HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render.",
"detailedType": "| ReactElement\n| ((\n props: HTMLProps,\n state: Field.Root.State,\n ) => ReactElement)"
}
},
"dataAttributes": {
"data-disabled": {
"description": "Present when the textarea is disabled."
},
"data-valid": {
"description": "Present when the textarea is in valid state."
},
"data-invalid": {
"description": "Present when the textarea is in invalid state."
},
"data-dirty": {
"description": "Present when the textarea's value has changed."
},
"data-touched": {
"description": "Present when the textarea has been touched."
},
"data-filled": {
"description": "Present when the textarea is filled."
},
"data-focused": {
"description": "Present when the textarea is focused."
}
},
"cssVariables": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
.Form {
display: flex;
flex-direction: column;
gap: 1rem;
width: 100%;
max-width: 16rem;
}

.Field {
display: flex;
flex-direction: column;
align-items: start;
gap: 0.25rem;
}

.Label {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 500;
color: var(--color-gray-900);
}

.Textarea {
box-sizing: border-box;
margin: 0;
border: 1px solid var(--color-gray-200);
width: 100%;
padding: 0.5rem 0.75rem;
max-width: 16rem;
min-height: 4rem;
border-radius: 0.375rem;
font-family: inherit;
font-size: 1rem;
line-height: 1.5rem;
font-weight: normal;
background-color: transparent;
color: var(--color-gray-900);
field-sizing: content;
resize: vertical;

&:focus {
outline: 2px solid var(--color-blue);
outline-offset: -1px;
}
}

.Error {
font-size: 0.875rem;
line-height: 1.25rem;
color: var(--color-red-800);
}

.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
height: 2.5rem;
padding: 0 0.875rem;
margin: 0;
outline: 0;
border: 1px solid var(--color-gray-200);
border-radius: 0.375rem;
background-color: var(--color-gray-50);
font-family: inherit;
font-size: 1rem;
font-weight: 500;
line-height: 1.5rem;
color: var(--color-gray-900);
user-select: none;

@media (hover: hover) {
&:hover {
background-color: var(--color-gray-100);
}
}

&:active {
background-color: var(--color-gray-100);
}

&:disabled {
cursor: not-allowed;
color: var(--color-gray-400);
background-color: var(--color-gray-100);
}

&:focus-visible {
outline: 2px solid var(--color-blue);
outline-offset: -1px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as React from 'react';
import { Field } from '@base-ui-components/react/field';
import { Form } from '@base-ui-components/react/form';
import { Textarea } from '@base-ui-components/react/textarea';
import styles from './index.module.css';

export default function ExampleForm() {
const [errors, setErrors] = React.useState({});
const [loading, setLoading] = React.useState(false);

return (
<Form
className={styles.Form}
errors={errors}
onClearErrors={setErrors}
onSubmit={async (event) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
const value = formData.get('feedback') as string;

setLoading(true);
const response = await submitForm(value);
const serverErrors = {
feedback: response.error,
};

setErrors(serverErrors);
setLoading(false);
}}
>
<Field.Root name="feedback" className={styles.Field}>
<Field.Label className={styles.Label}>Feedback</Field.Label>
<Textarea placeholder="Enter your feedback" className={styles.Textarea} />
<Field.Error className={styles.Error} />
</Field.Root>
<button disabled={loading} type="submit" className={styles.Button}>
Submit
</button>
</Form>
);
}

async function submitForm(value: string) {
// Mimic a server response
await new Promise((resolve) => {
setTimeout(resolve, 1000);
});

try {
if (value.length < 10) {
return { error: 'Feedback must be at least 10 characters long' };
}
} catch {
return { error: 'Invalid feedback' };
}

return { success: true };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use client';
export { default as CssModules } from './css-modules';
export { default as Tailwind } from './tailwind';
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import * as React from 'react';
import { Field } from '@base-ui-components/react/field';
import { Form } from '@base-ui-components/react/form';
import { Textarea } from '@base-ui-components/react/textarea';

export default function ExampleForm() {
const [errors, setErrors] = React.useState({});
const [loading, setLoading] = React.useState(false);

return (
<Form
className="flex w-full max-w-64 flex-col gap-4"
errors={errors}
onClearErrors={setErrors}
onSubmit={async (event) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
const value = formData.get('feedback') as string;

setLoading(true);
const response = await submitForm(value);
const serverErrors = {
feedback: response.error,
};

setErrors(serverErrors);
setLoading(false);
}}
>
<Field.Root name="feedback" className="flex flex-col items-start gap-1">
<Field.Label className="text-sm font-medium text-gray-900">Feedback</Field.Label>
<Textarea
placeholder="Enter your feedback"
className="field-sizing-content min-h-16 w-full max-w-64 resize-y rounded-md border border-gray-200 px-3 py-2 text-base text-gray-900 focus:outline-2 focus:-outline-offset-1 focus:outline-blue-800"
/>
<Field.Error className="text-sm text-red-800" />
</Field.Root>
<button
disabled={loading}
type="submit"
className="flex h-10 items-center justify-center rounded-md border border-gray-200 bg-gray-50 px-3.5 text-base font-medium text-gray-900 select-none hover:bg-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-blue-800 active:bg-gray-100 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:text-gray-400"
>
Submit
</button>
</Form>
);
}

async function submitForm(value: string) {
// Mimic a server response
await new Promise((resolve) => {
setTimeout(resolve, 1000);
});

try {
if (value.length < 10) {
return { error: 'Feedback must be at least 10 characters long' };
}
} catch {
return { error: 'Invalid feedback' };
}

return { success: true };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.Textarea {
box-sizing: border-box;
margin: 0;
border: 1px solid var(--color-gray-200);
width: 100%;
padding: 0.5rem 0.75rem;
max-width: 16rem;
min-height: 4rem;
border-radius: 0.375rem;
font-family: inherit;
font-size: 1rem;
line-height: 1.5rem;
font-weight: normal;
background-color: transparent;
color: var(--color-gray-900);
field-sizing: content;
resize: vertical;

&:focus {
outline: 2px solid var(--color-blue);
outline-offset: -1px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as React from 'react';
import { Textarea } from '@base-ui-components/react/textarea';
import styles from './index.module.css';

export default function ExampleTextarea() {
return <Textarea placeholder="Type something…" className={styles.Textarea} />;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use client';
export { default as CssModules } from './css-modules';
export { default as Tailwind } from './tailwind';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';
import { Textarea } from '@base-ui-components/react/textarea';

export default function ExampleTextarea() {
return (
<Textarea
placeholder="Type something…"
className="field-sizing-content min-h-16 w-full max-w-64 resize-y rounded-md border border-gray-200 px-3 py-2 text-base text-gray-900 focus:outline-2 focus:-outline-offset-1 focus:outline-blue-800"
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.Textarea {
box-sizing: border-box;
margin: 0;
border: 1px solid var(--color-gray-200);
width: 100%;
padding: 0.5rem 0.75rem;
max-width: 16rem;
min-height: 4rem;
border-radius: 0.375rem;
font-family: inherit;
font-size: 1rem;
line-height: 1.5rem;
font-weight: normal;
background-color: transparent;
color: var(--color-gray-900);
field-sizing: content;
resize: vertical;

&:focus {
outline: 2px solid var(--color-blue);
outline-offset: -1px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as React from 'react';
import { Textarea } from '@base-ui-components/react/textarea';
import styles from './index.module.css';

export default function ExampleTextarea() {
return <Textarea placeholder="Type something…" minRows={4} className={styles.Textarea} />;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use client';
export { default as CssModules } from './css-modules';
export { default as Tailwind } from './tailwind';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react';
import { Textarea } from '@base-ui-components/react/textarea';

export default function ExampleTextarea() {
return (
<Textarea
placeholder="Type something…"
minRows={4}
className="field-sizing-content min-h-16 w-full max-w-64 resize-y rounded-md border border-gray-200 px-3 py-2 text-base text-gray-900 focus:outline-2 focus:-outline-offset-1 focus:outline-blue-800"
/>
);
}
Loading
Loading