The Textarea component provides an enhanced textarea field with additional features like auto-sizing, character counting, clear button, and custom styling options.
Metro UI Core
DOM utilities
< textarea data-role = "textarea" ></ textarea >
< textarea data-role = "textarea" data-max-height = "300" ></ textarea >
< textarea data-role = "textarea" data-label = "Text" ></ textarea >
< textarea data-role = "textarea" data-chars-counter = "#counter" ></ textarea >
< span id = "counter" > 0 </ span >
< textarea data-role = "textarea" data-prepend = " < span class='mif-pencil'> < /span>" data-append = " < span class='mif-checkmark'> < /span>" ></ textarea >
Parameter Type Default Description labelString ""Label text for textarea textareaDeferredNumber 0Defer initialization of component charsCounterString nullSelector for element to display character count charsCounterTemplateString "$1"Template for character counter, where $1 is replaced with the count defaultValueString ""Default value for the textarea prependString ""Content to prepend before textarea appendString ""Content to append after textarea clearButtonBoolean trueShow clear button clearButtonIconString "❌"Icon for clear button autoSizeBoolean trueAuto-resize textarea based on content maxHeightNumber 0Maximum height for textarea (0 = no limit) clsPrependString ""Additional class for prepend element clsAppendString ""Additional class for append element clsComponentString ""Additional class for component element clsTextareaString ""Additional class for textarea element clsLabelString ""Additional class for label element
resize() - Recalculates the height of the textarea based on its content.
const textarea = Metro . getPlugin ( '#my-textarea' , 'textarea' );
clear() - Clears the textarea.
const textarea = Metro . getPlugin ( '#my-textarea' , 'textarea' );
toDefault() - Resets the textarea to its default value.
const textarea = Metro . getPlugin ( '#my-textarea' , 'textarea' );
length() - Returns the number of characters in the textarea.
const textarea = Metro . getPlugin ( '#my-textarea' , 'textarea' );
const charCount = textarea . length ();
disable() - Disables the textarea.
const textarea = Metro . getPlugin ( '#my-textarea' , 'textarea' );
enable() - Enables the textarea.
const textarea = Metro . getPlugin ( '#my-textarea' , 'textarea' );
toggleState() - Toggles between enabled and disabled states.
const textarea = Metro . getPlugin ( '#my-textarea' , 'textarea' );
Event Description onChangeTriggered when textarea value changes, provides {val, length} onTextareaCreateTriggered after textarea component creation, provides {element}
Variable Default (Light) Dark Mode Description --textarea-color#191919#dbdfe7Text color --textarea-border-colorvar(--border-color)#444444Border color --textarea-font-size14px14pxFont size --textarea-border-radius4px4pxBorder radius
--textarea-color : #0066cc ;
--textarea-border-color : #99ccff ;
--textarea-font-size : 16 px ;
--textarea-border-radius : 8 px ;
.textarea - Main container class
.fake-textarea - Hidden textarea used for auto-sizing calculations
.no-scroll-vertical - Hides vertical scrollbar when auto-sizing is enabled
.disabled - Applied when the textarea is disabled
.rtl - Applied for right-to-left text direction
.prepend - Container for prepended content
.append - Container for appended content
.input-clear-button - Clear button