Skip to content

Textarea

Textarea components are Input Fields that allow the user to enter multi-line string chains.

textarea.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'textarea',
path: 'comments',
label: 'Comments',
},
],
});

Use these props to customize your Textarea component.

proptypedescription
placeholderstringA placeholder text to display when the textarea has no value
hintstringA description to display below the textarea
iconstringA css class to display an icon inside the textarea
counterModestringMode for the character counter if maxLength is set, possible values are remaining (default) or current
minimumHeightnumberMinimum height of the textarea in pixels, defaults to 120
autoGrowbooleanIf true, the textarea will automatically expand its height as the user types
autocompletestring'on', 'off', or a space-separated list of W3C autofill tokens

Use the property placeholder to add a placeholder.

textarea.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'textarea',
path: 'comments',
label: 'Comments',
props: {
placeholder: 'Enter your comments here...',
},
},
],
});

Use the property hint to add a description.

textarea.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'textarea',
path: 'comments',
label: 'Comments',
props: {
hint: 'Please be descriptive.',
},
},
],
});

Use the property icon to add an icon to the textarea. The value of icon represents a set of CSS classes separated by spaces. The icon is displayed inside the textarea on the left.

textarea.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'textarea',
path: 'comments',
label: 'Comments',
props: {
icon: 'edit_note',
hint: 'With an icon in the textarea',
},
},
],
});

Use the validator maxLength to limit the number of characters and display a character counter. You can change how it counts with counterMode (remaining or current).

textarea.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'textarea',
path: 'commentsRemaining',
label: 'Comments',
props: {
counterMode: 'remaining',
},
validator: {
type: 'string',
maxLength: 10,
required: true,
},
},
{
kind: 'input',
type: 'textarea',
path: 'commentsCurrent',
label: 'Comments',
props: {
counterMode: 'current',
},
validator: {
type: 'string',
maxLength: 10,
required: true,
},
},
],
});

Use the property autoGrow to allow the textarea to expand automatically based on content. You can combine it with minimumHeight to set its initial size.

textarea.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'textarea',
path: 'comments',
label: 'Comments',
props: {
autoGrow: true,
minimumHeight: 50,
},
},
],
});

Textareas can be styled as explained in the Styling Guide.

Following you will find a list with the CSS Variables and a quick description of what you will style.

CSS VariableDescription
--gui-space-10Icon left padding or inline-start space
--gui-font-smCounter text font size
--gui-space-2Counter top margin
--gui-intent-errorCounter error color when max length is exceeded
--gui-space-gap--innerLabel gap and margin bottom
--gui-paddingInput padding
--gui-color-borderInput border color
--gui-radiusInput radius
--gui-color-bgInput background color
--gui-color-fgInput text color
--gui-color-primaryInput border color and outline on focus
--gui-color-errorInput border color when invalid

This is the anatomy of the Textarea Component in case you want to use your CSS styles.

textarea-anatomy.html
<gui-textarea>
<label for="fieldUid">
Label
<div class="gui-textarea__hint" id="fieldUid_hint">Hint</div>
</label>
<div class="gui-widget">
<textarea
id="fieldUid"
class="gui-textarea--icon"
placeholder="Custom placeholder"
aria-required="true"
aria-describedby="fieldUid_hint"
></textarea>
<span class="gui-widget-icon fas fa-comment"></span>
</div>
<div class="gui-textarea--validation">
<div></div>
<div class="gui-textarea--counter">
<span>100</span>
<span> / 100</span>
</div>
</div>
</gui-textarea>