The Placer Toolkit alpha has
arrived! 🎉
Plenty of changes are coming your
way—some big, some breaking, some
even nuclear! Beware the changelog…
Textarea
<pc-textarea> Textareas collect data from the user and allow multiple lines of text.
<pc-textarea></pc-textarea> This component works well with standard <form> elements. Please refer to the form controls page to learn more about form submission and client‐side validation.
Demos#
Labels#
Use the label attribute to give the textarea an accessible label. For labels that contain HTML, use the label slot instead.
Hints#
Add a descriptive hint to a textarea with the hint attribute. For hints that contain HTML, use the hint slot instead.
Rows#
Use the rows attribute to change the number of text rows that get shown.
Placeholders#
Use the placeholder attribute to add a placeholder.
Filled#
Add the filled attribute to draw a filled textarea.
Disabled#
Use the disabled attribute to disable the textarea.
Sizes#
Use the size attribute to change the textarea’s size.
Prevent resizing#
By default, textareas can be resized vertically by the user. To prevent resizing, set the resize attribute to none.
Expand with content#
Textareas will automatically resize to fit their content when resize is set to auto.
Properties#
| Name | Description | Reflects | Default |
|---|---|---|---|
name | The name of the textarea, submitted as a name/value pair with form data. Type: string |
| "" |
value | The current value of the textarea, submitted as a name/value pair with form data. Type: string |
| "" |
size | The textarea’s size. Type: "small" | "medium" | "large" |
| "medium" |
filled | Draws a filled textarea control. Type: boolean |
| false |
label | The textarea’s label. If you need to display HTML, use the label slot instead.Type: string |
| "" |
hint | The textarea’s hint. If you need to display HTML, use the hint slot instead.Type: string |
| "" |
placeholder | Placeholder text to show as a hint when the textarea is empty. Type: string |
| "" |
rows | The number of rows to display by default. Type: number |
| 4 |
resize | Controls how the textarea can be resized. Type: "none" | "vertical" | "horizontal" | "both" | "auto" |
| "vertical" |
disabled | Disables the textarea. Type: boolean |
| false |
readonly | Makes the textarea readonly. Type: boolean |
| false |
form | By default, form controls are associated with the nearest containing <form> element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work.Type: string |
| "" |
required | Indicates if the textarea must be filled in or not. Type: boolean |
| false |
minlength | The minimum length of text in the textarea that will be considered valid. Type: number | undefined |
| ‐ |
maxlength | The maximum length of text in the textarea that will be considered valid. Type: number | undefined |
| ‐ |
autocapitalize | Controls whether and how text is automatically capitalised as it is entered by the user. Type: "off"
| "none"
| "on"
| "sentences"
| "words"
| "characters" |
| "sentences" |
autocorrect | Indicates whether the browser’s autocorrect feature is on or off. Type: boolean |
| false |
autocomplete | Specifies what permission the browser has to provide assistance in filling in form fields. Refer to this page on MDN for valid values. Type: string | undefined |
| ‐ |
autofocus | Indicates that the textarea should receive focus on page load. Type: boolean |
| false |
enterkeyhint | Used to customise the label or icon of the Enter key on virtual keyboards. Type: "enter"
| "done"
| "go"
| "next"
| "previous"
| "search"
| "send" |
| "enter" |
spellcheck | Enable spellcheck on the textarea. Type: boolean |
| true |
inputmode | Tells the browser what type of data will be entered by the user, allowing virtual keyboards to display the correct keyboard type to the user. Type: "none"
| "text"
| "decimal"
| "numeric"
| "tel"
| "search"
| "email"
| "url" | undefined |
| ‐ |
defaultValue | The default value of the textarea. Primarily used for resetting the textarea. Type: string |
| "" |
validity | Gets the validity state object. |
| ‐ |
validationMessage | Gets the validation message. |
| ‐ |
updateComplete | A read‐only promise that resolves when the component has finished updating. | ‐ |
Learn more about attributes and properties.
Slots#
| Name | Description |
|---|---|
label | The textarea’s label. Alternatively, you can use the label attribute. |
hint | Text that describes how to use the textarea. Alternatively, you can use the hint attribute. |
Learn more about using slots.
Methods#
| Name | Description | Arguments |
|---|---|---|
focus() | Focuses the textarea. | options: FocusOptions |
blur() | Unfocuses the textarea (i.e., blurs it). | ‐ |
select() | Selects all the text in the textarea. | ‐ |
getScrollPosition() | Gets the textarea’s scroll position. | ‐ |
setScrollPosition() | Sets the textarea’s scroll position. | position: { top?: number; left?: number } |
setSelectionRange() | Sets the start and end positions of the text selection (0‐based). | selectionStart: number, selectionEnd: number, selectionDirection: "forward" | "backward" | "none" |
setRangeText() | Replaces a range of text with a new string. | replacement: string, start: number, end: number, selectMode: "select" | "start" | "end" | "preserve" |
checkValidity() | Checks for validity but does not show a validation message. Returns true when valid and false when invalid. | ‐ |
getForm() | Gets the associated form, if one exists. | ‐ |
reportValidity() | Checks for validity and shows the browser’s validation message if the select is invalid. | ‐ |
setCustomValidity() | Sets a custom validation message. Pass an empty string to restore validity. | message: string |
Learn more about methods.
Events#
| Name | Description | Event detail |
|---|---|---|
pc-input | Emitted when the textarea receives input. | ‐ |
pc-change | Emitted when an alteration to the textarea’s value is committed by the user. | ‐ |
pc-focus | Emitted when the textarea gains focus. | ‐ |
pc-blur | Emitted when the textarea loses focus. | ‐ |
pc-invalid | Emitted when the textarea has been checked for validity and its constraints aren’t satisfied. | ‐ |
Learn more about events.
Parts#
| Name | Description |
|---|---|
form-control | The form control that wraps the label, textarea and hint. |
base | The internal textarea element’s wrapper. |
label | The textarea’s label. |
hint | The textarea’s hint. |
textarea | The internal <textarea> element. |
Learn more about customising CSS parts.
Importing#
If you’re using the autoloader or the standard loader, you can skip this section. But if you’re cherry picking, you can use any of the following snippets to import this component.
To manually import this component from the CDN, copy this code snippet and paste it in your HTML.
<script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.1/cdn/components/textarea/textarea.js"></script> To manually import this component from the CDN, copy this code snippet and paste it in your JavaScript file.
import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.1/cdn/components/textarea/textarea.js"; To manually import this component from npm, copy this code snippet and paste it in your JavaScript file.
import "placer-toolkit/dist/components/textarea/textarea.js";