Textarea
<pc-textarea> Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
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.
Eigenschaften#
| Name | Beschreibung | Reflektiert | Standard |
|---|---|---|---|
name | The name of the textarea, submitted as a name/value pair with form data. Typ: string |
| "" |
value | The current value of the textarea, submitted as a name/value pair with form data. Typ: string |
| "" |
size | The textarea’s size. Typ: "small" | "medium" | "large" |
| "medium" |
filled | Draws a filled textarea control. Typ: boolean |
| false |
label | The textarea’s label. If you need to display HTML, use the label slot instead.Typ: string |
| "" |
hint | The textarea’s hint. If you need to display HTML, use the hint slot instead.Typ: string |
| "" |
placeholder | Placeholder text to show as a hint when the textarea is empty. Typ: string |
| "" |
rows | The number of rows to display by default. Typ: number |
| 4 |
resize | Controls how the textarea can be resized. Typ: "none" | "vertical" | "horizontal" | "both" | "auto" |
| "vertical" |
disabled | Disables the textarea. Typ: boolean |
| false |
readonly | Makes the textarea readonly. Typ: 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.Typ: string |
| "" |
required | Indicates if the textarea must be filled in or not. Typ: boolean |
| false |
minlength | The minimum length of text in the textarea that will be considered valid. Typ: number | undefined |
| ‐ |
maxlength | The maximum length of text in the textarea that will be considered valid. Typ: number | undefined |
| ‐ |
autocapitalize | Controls whether and how text is automatically capitalised as it is entered by the user. Typ: "off"
| "none"
| "on"
| "sentences"
| "words"
| "characters" |
| "sentences" |
autocorrect | Indicates whether the browser’s autocorrect feature is on or off. Typ: 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. Typ: string | undefined |
| ‐ |
autofocus | Indicates that the textarea should receive focus on page load. Typ: boolean |
| false |
enterkeyhint | Used to customise the label or icon of the Enter key on virtual keyboards. Typ: "enter"
| "done"
| "go"
| "next"
| "previous"
| "search"
| "send" |
| "enter" |
spellcheck | Enable spellcheck on the textarea. Typ: 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. Typ: "none"
| "text"
| "decimal"
| "numeric"
| "tel"
| "search"
| "email"
| "url" | undefined |
| ‐ |
defaultValue | The default value of the textarea. Primarily used for resetting the textarea. Typ: string |
| "" |
validity | Gets the validity state object. |
| ‐ |
validationMessage | Gets the validation message. |
| ‐ |
updateComplete | Ein schreibgeschütztes Promise, das erfüllt ist, sobald die Komponente fertig aktualisiert wurde. | ‐ |
Erfahre mehr über Attribute und Eigenschaften.
Slots#
| Name | Beschreibung |
|---|---|
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. |
Erfahre mehr über die Benutzung von Slots.
Methoden#
| Name | Beschreibung | Argumente |
|---|---|---|
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 |
Erfahre mehr über Methoden.
Events#
| Name | Beschreibung | 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. | ‐ |
Erfahre mehr über Events.
Parts#
| Name | Beschreibung |
|---|---|
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. |
Erfahre mehr über das Anpassen von CSS‐Parts.
Importieren#
Wenn du den Autoloader oder den Standard‐Loader nutzt, kannst du diesen Abschnitt überspringen. Falls du „Cherry Picking“ betreibst, kannst du die folgenden Snippets verwenden, um diese Komponente zu importieren.
Um diese Komponente manuell vom CDN zu importieren, kopiere dieses Code‐Snippet und füge es in dein HTML ein.
<script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.3/cdn/components/textarea/textarea.js"></script> Um diese Komponente manuell vom CDN zu importieren, kopiere dieses Code‐Snippet und füge es in deine JavaScript‐Datei ein.
import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.3/cdn/components/textarea/textarea.js"; Um diese Komponente manuell via npm zu importieren, kopiere dieses Code‐Snippet und füge es in deine JavaScript‐Datei ein.
import "placer-toolkit/dist/components/textarea/textarea.js";