Textarea
Textarea
lets you create accessible textareas. The API is pretty much the same as TextInput
.
-->
Textarea
lets you create accessible textareas. The API is pretty much the same as TextInput
.
Textarea
has possibly the simplest markup you’ll ever see. The minimum you need is just name
and label
.
Just use hint
and error
properties to add them.
Textarea
can grow automatically according to its contents. To activate this feature, just set autogrow
to true.
Like TextInput
, Textarea
comes with before
and after
slots for you to add on elements easily.
We get all the tiny details right too. Try it out: Focus on the send button and you’ll see a nice-looking outline that doesn’t include the divider!
Like TextInput
, Textarea
comes with before
and after
slots for you to add on elements easily.
We get all the tiny details right too. Try it out: Focus on the send button and you’ll see a nice-looking outline that doesn’t include the divider!
Textarea
creates a textarea.
You can create hint text for each Textarea
by adding a hint
property.
You can create error messages for each Textarea
by adding an error
property.
Use the value
property to set a default value.
Use the placeholder
property to add a placeholder.
Use readonly
and disabled
respectively to create and readonly and disabled states. These two states have a similar style (greyed out) but different behavior:
readonly
will send data to the server when the form is submitteddisabled
will not send data to the server when the form is submitted.All other attributes will be added directly to the textarea
element.
If you set autogrow
to true, Textarea
will automatically grow in height as you type. This feature requires JavaScript.
To keep things consistent with TextInput
, Textarea
contains two slots: before
and after
.
before
lets you create a prefix for the textareaafter
lets you create a suffix for the textareaThe contents of this section will only work in a .svelte
file and not inside
an .astro
file.
You can bind to the <textarea>
element with ref
. This is useful if you need the element when handling events.
The following events are supported by Textarea
right now:
input
change
focus
blur
keydown
keyup
keypress
click
You can listen to these the way Svelte handles event listeners.
We forward the above events manually because Svelte 4 doesn’t have automatic event-forwarding capability. All events will be forwarded automatically when we migrate to Svelte 5.
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
Textarea
creates a textarea.
You can create hint text for each Textarea
by adding a hint
property.
You can create error messages for each Textarea
by adding an error
property.
Use the value
property to set a default value.
Use the placeholder
property to add a placeholder.
Use readonly
and disabled
respectively to create and readonly and disabled states. These two states have a similar style (greyed out) but different behavior:
readonly
will send data to the server when the form is submitteddisabled
will not send data to the server when the form is submitted.All other attributes will be added directly to the textarea
element.
If you set autogrow
to true, Textarea
will automatically grow in height as you type. This feature requires JavaScript.
To keep things consistent with TextInput
, Textarea
contains two slots: before
and after
.
before
lets you create a prefix for the textareaafter
lets you create a suffix for the textareaThe contents of this section will only work in a .svelte
file and not inside
an .astro
file.
You can bind to the <textarea>
element with ref
. This is useful if you need the element when handling events.
The following events are supported by Textarea
right now:
input
change
focus
blur
keydown
keyup
keypress
click
You can listen to these the way Svelte handles event listeners.
We forward the above events manually because Svelte 4 doesn’t have automatic event-forwarding capability. All events will be forwarded automatically when we migrate to Svelte 5.
Textarea
uses several styles from both Splendid Styles and Splendid Layouts. The easiest way to include all basic styles is to import all styles from both libraries:
But if you wish to include only the necessary styles for Textarea
, you can use the following rules:
Like TextInput
, Textarea
creates the following HTML when label
and name
are used:
If hint
is added, Textarea
creates an additional Hint
element and adds links the Hint
element to the <textarea>
with aria-describedby
.
If error
is added, Textarea
creates an additional Error
element (using <output>
). It also links the error element to the <textarea>
with aria-describedby
:
If both hint
and error
are added, Textarea
creates both hint and error elements, and links them both to the <textarea>
with aria-describedby
:
If you added before
or after
slots, Textarea
will create these elements inside InputGroup
, before or after the <textarea>
element.
The following classes are used by Textarea
:
Class | Description |
---|---|
Textarea | Styles the Textarea container |
TextField | Styles the Textarea container. Also used for TextInput |
Label | Styles the label |
Hint | Styles the hint element |
Error | Styles for the error element |
InputGroup | Styles the input group |
Field | Styles for the <textarea> field. |
The following properties can be used to add classes to Textarea
.
Property | Description |
---|---|
class | Add classes to the Textarea |
styles | Inline styles to the Textarea |
labelClass | Add classes to the label |
hintClass | Add classes to the hint element |
errorClass | Add classes to the error element |
inputGroupclass | Add classes to the input group |
fieldClass | Add classes to the <textarea> field |
All other custom properties will be passed directly into the <textarea>
element.
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
Textarea
uses several styles from both Splendid Styles and Splendid Layouts. The easiest way to include all basic styles is to import all styles from both libraries:
But if you wish to include only the necessary styles for Textarea
, you can use the following rules:
Like TextInput
, Textarea
creates the following HTML when label
and name
are used:
If hint
is added, Textarea
creates an additional Hint
element and adds links the Hint
element to the <textarea>
with aria-describedby
.
If error
is added, Textarea
creates an additional Error
element (using <output>
). It also links the error element to the <textarea>
with aria-describedby
:
If both hint
and error
are added, Textarea
creates both hint and error elements, and links them both to the <textarea>
with aria-describedby
:
If you added before
or after
slots, Textarea
will create these elements inside InputGroup
, before or after the <textarea>
element.
The following classes are used by Textarea
:
Class | Description |
---|---|
Textarea | Styles the Textarea container |
TextField | Styles the Textarea container. Also used for TextInput |
Label | Styles the label |
Hint | Styles the hint element |
Error | Styles for the error element |
InputGroup | Styles the input group |
Field | Styles for the <textarea> field. |
The following properties can be used to add classes to Textarea
.
Property | Description |
---|---|
class | Add classes to the Textarea |
styles | Inline styles to the Textarea |
labelClass | Add classes to the label |
hintClass | Add classes to the hint element |
errorClass | Add classes to the error element |
inputGroupclass | Add classes to the input group |
fieldClass | Add classes to the <textarea> field |
All other custom properties will be passed directly into the <textarea>
element.
Name | Description |
---|---|
before | Inserts HTML before <textarea> |
after | Inserts HTML after <textarea> |
Use these properties to customize the Textarea
component.
Property | Type | Description |
---|---|---|
name | string | Name of the textarea field (required) |
label | string | The label |
hint | string | Hint text |
error | string | Error text |
value | string | Textarea value |
placeholder | string | Placeholder text |
disabled | boolean | Adds the disabled state when present. |
readonly | boolean | Adds the readonly state when present. |
required | boolean | Adds the required state when present. |
ref | object | Reference for the <textarea> element |
options | object | Options for Textarea. See options |
Configuration object Textarea
component.
Property | Type | Default | Description |
---|---|---|---|
autogrow | boolean | false | Whether textarea should grow with content |
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
Name | Description |
---|---|
before | Inserts HTML before <textarea> |
after | Inserts HTML after <textarea> |
Use these properties to customize the Textarea
component.
Property | Type | Description |
---|---|---|
name | string | Name of the textarea field (required) |
label | string | The label |
hint | string | Hint text |
error | string | Error text |
value | string | Textarea value |
placeholder | string | Placeholder text |
disabled | boolean | Adds the disabled state when present. |
readonly | boolean | Adds the readonly state when present. |
required | boolean | Adds the required state when present. |
ref | object | Reference for the <textarea> element |
options | object | Options for Textarea. See options |
Configuration object Textarea
component.
Property | Type | Default | Description |
---|---|---|---|
autogrow | boolean | false | Whether textarea should grow with content |