TextArea

view
size
placeholder
note
minRows
maxRows
validationState
errorMessage
disabled
hasClear
import {TextArea} from '@gravity-ui/uikit';

TextArea allow users to enter text into a UI.

Appearance

The TextArea's appearance is controlled by the view and pin properties.

View

normal - is the main view of the TextArea (used by default).

clear - can be used when using a custom wrapper for the TextArea.

Pin

Allows you to control the appearance of the right and left edges of the TextArea's border.

States

Disabled

The state of the TextArea where you don't want the user to be able to interact with the component.

Error

The state of the TextArea where you want to show incorrect user input. To change the appearance of the TextArea, use the validationState property with the "invalid" value. An optional message text can be added via the errorMessage property.

Error message
Error message

Size

s – Used when standard controls are too big (tables, small cards).

m – The basic size, used in most components.

l – Used for basic controls in a page's header, modal windows, or pop-ups.

xl – Used on promo and landing pages.

Row management

The row count of the TextArea is controlled by the rows, minRows and maxRows properties. The rows property disables automatic height calculation. To set the desired height of the TextArea, use the className or style property with the rows property set to 1.

rows = 2
minRows = 2
maxRows = 2
height = 200px

Resizable TextArea

You can get resizable behaviour by providing resize style to controlProps property. Be sure to specify the rows property if you allow the text area height to be resized, otherwise resizing will conflict with the automatic height calculation.

Properties

NameDescriptionTypeDefault
autoCompleteThe control's autocomplete attributeboolean string
autoFocusThe control's autofocus attributeboolean
classNameThe control's wrapper class namestring
controlPropsThe control's html attributesReact.TextareaHTMLAttributes<HTMLTextAreaElement>
controlRefReact ref provided to the controlReact.Ref<HTMLTextAreaElement>
defaultValueThe control's default value. Used when the component is not controlledstring
disabledIndicates that the user cannot interact with the controlbooleanfalse
errorMessageError textstring
hasClearShows the icon for clearing the control's valuebooleanfalse
idThe control's id attributestring
maxRowsThe maximum number of visible text lines for the control. Ignored if rows is specifiednumber
minRowsThe minimum number of visible text lines for the control. Ignored if rows is specifiednumber
nameThe control's name attribute. If unspecified, it will be autogenerated.string
noteAn optional element displayed under the bottom-right corner of the control and sharing space with the error containerReact.ReactNode
onBlurFires when the control lost focus. Provides focus event as a callback's argumentfunction
onChangeFires when the input’s value is changed by the user. Provides change event as a callback's argumentfunction
onFocusFires when the control gets focus. Provides focus event as a callback's argumentfunction
onKeyDownFires when a key is pressed. Provides keyboard event as a callback's argumentfunction
onKeyUpFires when a key is released. Provides keyboard event as a callback's argumentfunction
onUpdateFires when the input’s value is changed by the user. Provides new value as a callback's argumentfunction
pinThe control's border viewstring"round-round"
placeholderText that appears in the control when no value is setstring
qaTest id attribute (data-qa)string
readOnlyIndicates that the user cannot change control's valuebooleanfalse
rowsThe number of visible text lines for the control. If unspecified, the hight will be calculated automatically based on the contentnumber
sizeThe control's size"s" "m" "l" "xl""m"
tabIndexThe control's tabindex attributestring
typeThe control's typestring
validationStateValidation state"invalid"
valueThe control's valuestring
viewThe control's view"normal" "clear""normal"

CSS API

NameDescription
--g-text-area-text-colorText color
--g-text-area-placeholder-colorPlaceholder color
--g-text-area-background-colorBackground color
--g-text-area-border-radiusBorder radius
--g-text-area-border-widthBorder width
--g-text-area-border-colorBorder color
--g-text-area-border-color-hoverBorder color if hovered
--g-text-area-border-color-activeBorder color if active
--g-text-area-focus-outline-colorOutline color if focused (by default not presented)