Skip to main content

Text Field

TextField allow users to enter text into the UI, Typically appear in forms.

Idle

Idle
Idle
Idle with error

Hover

Hover
Hover
Hover with error

Focused

Focused
Focused
Focused with error

Pressed

Pressed
Pressed
Pressed with error

Disabled

Disabled
Disabled
Disabled with error

Basic usage

import { TextField } from '@streamelements/frontend-ui';

export function MyTextField() {
return <TextField.Single label="Label" />
}

Components

TextField

The TextField Root component is a complete form control including a label and an input.

Sample
<TextField.Single label="Sample"/>

Adornment

The TextField.Adornment component exposes the ability to decorate a text field at the beginning and/or at the end of the input. There may be at most one per side (start and end). In case two are passed on, the one further down the list is picked.

KG

Weight
<TextField.Single label="Weight" type="number" defaultValue={83}>
<TextField.Adornment>KG</TextField.Adornment>
</TextField.Single>

HelperText

The TextField.HelperText component exposes the ability to add an explanatory text below an input. In case two or more are passed on, the one further down the list is picked.

KG
Weight
Raw muscle mass
<TextField.Single label="Weight" defaultValue={83}>
<TextField.Adornment>KG</TextField.Adornment>
<TextField.HelperText>Raw muscle mass</TextField.HelperText>
</TextField.Single>

CharLimitIndicator

The TextField.CharLimitIndicator component exposes the ability to show an a character limit.

Nickname
4
<TextField.Single label="Nickname" defaultValue="darkoe" maxLength={10}>
<TextField.CharLimitIndicator />
</TextField.Single>

Props

Root

For DX sake, the following props are passed straight down to the Input element:

  • type
  • placeholder
  • onChange

For additional prop-passing to the input element, check out the inputProps prop. With that said, the following props are available:

Name

Type

Default value

Description

labelstring
The label of the field
valuestring | number | readonly string[]
The controlled state of component.
Must be used in conjunction with onValueChange
defaultValuestring | number | readonly string[]
The initial state of the field
onValueChangeFunction
Callback function to be called when the state changes
(value: string | number) => void
disabledboolean
When true, prevents user interaction with the component.
errorboolean
When true, the field turns red. And if no Adornment with position="end" is passed on, an error icon is shown.
requiredboolean
When true, the user must check input a value.
namestring
The name of the input element. Submitted with its parent form.
maxLengthnumberInfinity
Sets a limit on the length of the value
inputPropsHTMLProps{}
Props to pass on to the input/textarea element
cssCSS{}
Pass on additional styling utilizing Stitches' tokens

Adornment

Name

Type

Default value

Description

positionstart | endend
The horizontal position of the adornment
childrenReact.Children
Components to render inside the adornment
cssCSS{}
Pass on additional styling utilizing Stitches' tokens

HelperText

The HelperText component is based on Text.Body with caption and some additional styling.

CharLimitIndicator

Name

Type

Default value

Description

cssCSS{}
Pass on additional styling utilizing Stitches' tokens

Examples

Multiline

Basic

Weight
Press enter for a new line
<TextField.Multi label="Weight">
<TextField.HelperText>Press enter for a new line
</TextField.HelperText>
</TextField.Multi>

Char limited

Weight
64
Press enter for a new line
<TextField.Multi
label="Weight"
maxLength={120}
defaultValue="Lorem ipsum dolor sit amet consectetur adipisicing elit."
>
<TextField.HelperText>Press enter for a new line
</TextField.HelperText>
<TextField.CharLimitIndicator />
</TextField.Multi>

Minimum height

Weight
<TextField.Multi
label="Weight"
maxLength={120}
defaultValue="Lorem ipsum dolor sit amet consectetur adipisicing elit."
inputProps={{
rows: 3, // Can't be less than this
// or via css
css: {
minHeight: 80
}
}}
/>