A component that accepts multi-line text input and automatically adjusts its height.
@seed-design/lynx-react@0.4.0, @seed-design/lynx-css@0.7.0
import "./styles" ;
import { useSeedClassName, VStack } from "@seed-design/lynx-react" ;
import { TextField, TextFieldTextarea } from "@/components/ui/text-field" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-text-field-textarea-root` }>
< VStack width = "full" height = "full" align = "center" justify = "center" >
< VStack width = "full" maxWidth = "480px" >
< TextField label = "라벨" >
< TextFieldTextarea accessibility-label = "라벨" />
</ TextField >
</ VStack >
</ VStack >
</ view >
);
}
Props corresponding to React's autoFocus are not supported. If you need to focus from the beginning, call the native focus UI method on the TextFieldTextarea ref after the screen is rendered.
npx @seed-design/cli add ui:text-field pnpm dlx @seed-design/cli add ui:text-field yarn dlx @seed-design/cli add ui:text-field bun x @seed-design/cli add ui:text-field
Install dependencies
npm install @seed-design/lynx-react yarn add @seed-design/lynx-react pnpm add @seed-design/lynx-react bun add @seed-design/lynx-react Copy the code below and paste it in /**
* @file ui:text-field
* @requires @seed-design/lynx-react@>=0.1.0 <1.0.0
* @requires @seed-design/lynx-css@>=0.1.0 <1.0.0
**/
import * as React from "@lynx-js/react" ;
import {
Field as SeedField,
TextField as SeedTextField,
type UseTextFieldWithGraphemesParams,
useTextFieldWithGraphemes,
} from "@seed-design/lynx-react" ;
type TextFieldRootRef = React . ComponentRef < typeof SeedTextField.Root>;
type FieldRootRef = React . ComponentRef < typeof SeedField.Root>;
export interface TextFieldProps
extends Omit < SeedTextField . RootProps , "children" | "onValueChange" > {
children ?: React . ReactNode ;
label ?: React . ReactNode ;
labelWeight ?: SeedField . LabelProps [ "weight" ];
indicator ?: React . ReactNode ;
prefixIcon ?: SeedTextField . PrefixIconProps [ "icon" ];
prefix ?: React . ReactNode ;
suffixIcon ?: SeedTextField . SuffixIconProps [ "icon" ];
suffix ?: React . ReactNode ;
description ?: React . ReactNode ;
errorMessage ?: React . ReactNode ;
hideCharacterCount ?: boolean ;
maxGraphemeCount ?: number ;
showRequiredIndicator ?: boolean ;
fieldRef ?: React . Ref < FieldRootRef >;
onValueChange ?: UseTextFieldWithGraphemesParams [ "onValueChange" ];
}
/**
* @see https://crispy.carrot-soft.tech/lynx/components/text-field-input
*/
export const TextField = React. forwardRef < TextFieldRootRef , TextFieldProps >(
(
{
children,
label,
labelWeight,
indicator,
prefixIcon,
prefix,
suffixIcon,
suffix,
description,
errorMessage,
hideCharacterCount,
maxGraphemeCount,
showRequiredIndicator,
fieldRef,
value,
defaultValue,
onValueChange,
required,
disabled,
invalid,
readOnly,
name,
... rootProps
},
ref,
) => {
const { textFieldRootProps , counterProps } = useTextFieldWithGraphemes ({
value,
defaultValue,
onValueChange,
maxGraphemeCount,
});
const renderHeader = label != null || indicator != null ;
const renderDescription = description != null && ! (invalid && errorMessage != null );
const renderErrorMessage = invalid && errorMessage != null ;
const renderCharacterCount = ! hideCharacterCount && maxGraphemeCount !== undefined ;
const renderFooter = renderDescription || renderErrorMessage || renderCharacterCount;
return (
< SeedField.Root
ref = {fieldRef}
required = {required}
disabled = {disabled}
invalid = {invalid}
readOnly = {readOnly}
>
{renderHeader ? (
< SeedField.Header >
< SeedField.Label weight = {labelWeight}>
{label}
{showRequiredIndicator ? < SeedField.RequiredIndicator /> : null }
{indicator != null ? (
< SeedField.IndicatorText >{indicator}</ SeedField.IndicatorText >
) : null }
</ SeedField.Label >
</ SeedField.Header >
) : null }
< SeedTextField.Root ref = {ref} name = {name} { ... rootProps} { ... textFieldRootProps}>
{prefixIcon ? < SeedTextField.PrefixIcon icon = {prefixIcon} /> : null }
{prefix != null ? < SeedTextField.PrefixText >{prefix}</ SeedTextField.PrefixText > : null }
{children}
{suffix != null ? < SeedTextField.SuffixText >{suffix}</ SeedTextField.SuffixText > : null }
{suffixIcon ? < SeedTextField.SuffixIcon icon = {suffixIcon} /> : null }
</ SeedTextField.Root >
{renderFooter ? (
< SeedField.Footer >
{renderDescription ? (
< SeedField.Description >{description}</ SeedField.Description >
) : null }
{renderErrorMessage ? (
< SeedField.ErrorMessage >{errorMessage}</ SeedField.ErrorMessage >
) : null }
{renderCharacterCount ? < SeedField.CharacterCount { ... counterProps} /> : null }
</ SeedField.Footer >
) : null }
</ SeedField.Root >
);
},
);
TextField.displayName = "TextField" ;
export interface TextFieldInputProps extends SeedTextField . InputProps {}
/**
* @see https://crispy.carrot-soft.tech/lynx/components/text-field-input
*/
export const TextFieldInput = SeedTextField.Input;
export interface TextFieldTextareaProps extends SeedTextField . TextareaProps {}
/**
* @see https://crispy.carrot-soft.tech/lynx/components/text-field-textarea
*/
export const TextFieldTextarea = SeedTextField.Textarea;
/**
* This file is a snippet from Crispy, helping you get started quickly with @seed-design/* packages.
* You can extend this snippet however you want.
*/
children?React.ReactNode
label?React.ReactNode
labelWeight?"medium" | "bold" | undefined
indicator?React.ReactNode
prefixIcon?React.ReactElement < LynxIconElementProps, string | React.JSXElementConstructor < any >> | undefined
prefix?React.ReactNode
suffixIcon?React.ReactElement < LynxIconElementProps, string | React.JSXElementConstructor < any >> | undefined
suffix?React.ReactNode
description?React.ReactNode
errorMessage?React.ReactNode
hideCharacterCount?boolean | undefined
maxGraphemeCount?number | undefined
showRequiredIndicator?boolean | undefined
fieldRef?React.Ref < NodesRef > | undefined
onValueChange?(( values : { value : string ; graphemes : string []; slicedValue : string ; slicedGraphemes : string []; }) => void ) | undefined
variant?"outline" | "underline" | undefined
size?"medium" | "large" | undefined
invalid?boolean | undefined
readOnly?boolean | undefined
disabled?boolean | undefined
value?string | undefined
defaultValue?string | undefined
required?boolean | undefined
name?string | undefined
style?CSSProperties | undefined
className?string | undefined
autoresize?boolean | undefined
placeholder?string | undefined
confirm-type?"send" | "search" | "go" | "done" | "next" | undefined
maxlength?number | undefined
maxlines?number | undefined
bounces?boolean | undefined
line-spacing?number | `${ number }px` | `${ number }rpx` | undefined
readonly?boolean | undefined
disabled?boolean | undefined
input-filter?string | undefined
enable-scroll-bar?boolean | undefined
type?"number" | "text" | "digit" | "tel" | "email" | undefined
ios-auto-correct?boolean | undefined
ios-spell-check?boolean | undefined
android-fullscreen-mode?boolean | undefined
bindfocus?(( e : BaseEvent < "bindfocus" , TextAreaFocusEvent >) => void ) | undefined
bindblur?(( e : BaseEvent < "bindblur" , TextAreaBlurEvent >) => void ) | undefined
bindconfirm?(( e : BaseEvent < "bindconfirm" , TextAreaConfirmEvent >) => void ) | undefined
bindinput?(( e : BaseEvent < "bindinput" , TextAreaInputEvent >) => void ) | undefined
bindselection?(( e : BaseEvent < "bindselection" , TextAreaSelectionChangeEvent >) => void ) | undefined
id?string | undefined
name?string | undefined
hidden?boolean | undefined
flatten?boolean | undefined
focusable?boolean | undefined
bindlayoutchange?EventHandler < LayoutChangeDetailEvent < Target >> | undefined
main-thread:bindlayoutchange?EventHandler < LayoutChangeDetailEvent < Element >> | undefined
style?CSSProperties | undefined
className?string | undefined
import "./styles" ;
import { useSeedClassName, VStack } from "@seed-design/lynx-react" ;
import { TextField, TextFieldTextarea } from "@/components/ui/text-field" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-text-field-textarea-root` }>
< VStack width = "full" height = "full" align = "center" justify = "center" >
< VStack width = "full" maxWidth = "480px" gap = "x5" >
< TextField label = "라벨" description = "설명을 써주세요" >
< TextFieldTextarea accessibility-label = "라벨" placeholder = "플레이스홀더" />
</ TextField >
< TextField
label = "라벨"
description = "설명을 써주세요"
invalid
errorMessage = "오류가 발생한 이유를 써주세요"
>
< TextFieldTextarea accessibility-label = "라벨" placeholder = "플레이스홀더" />
</ TextField >
</ VStack >
</ VStack >
</ view >
);
}
import "./styles" ;
import { useSeedClassName, VStack } from "@seed-design/lynx-react" ;
import { TextField, TextFieldTextarea } from "@/components/ui/text-field" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-text-field-textarea-root` }>
< VStack width = "full" height = "full" align = "center" justify = "center" >
< VStack width = "full" maxWidth = "480px" gap = "x5" >
< TextField label = "라벨" description = "설명을 써주세요" disabled >
< TextFieldTextarea accessibility-label = "라벨" placeholder = "플레이스홀더" />
</ TextField >
< TextField
label = "라벨"
description = "설명을 써주세요"
disabled
invalid
errorMessage = "오류가 발생한 이유를 써주세요"
>
< TextFieldTextarea accessibility-label = "라벨" placeholder = "플레이스홀더" />
</ TextField >
</ VStack >
</ VStack >
</ view >
);
}
import "./styles" ;
import { useSeedClassName, VStack } from "@seed-design/lynx-react" ;
import { TextField, TextFieldTextarea } from "@/components/ui/text-field" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-text-field-textarea-root` }>
< VStack width = "full" height = "full" align = "center" justify = "center" >
< VStack width = "full" maxWidth = "480px" gap = "x5" >
< TextField label = "라벨" description = "설명을 써주세요" readOnly >
< TextFieldTextarea accessibility-label = "라벨" placeholder = "플레이스홀더" />
</ TextField >
< TextField
label = "라벨"
description = "설명을 써주세요"
readOnly
invalid
errorMessage = "오류가 발생한 이유를 써주세요"
>
< TextFieldTextarea accessibility-label = "라벨" placeholder = "플레이스홀더" />
</ TextField >
</ VStack >
</ VStack >
</ view >
);
}
Set the size of TextField with size. (default: large)
Lynx supports large and medium. responsive is not supported because there is no CSS viewport breakpoint.
import "./styles" ;
import { useSeedClassName, VStack } from "@seed-design/lynx-react" ;
import { TextField, TextFieldTextarea } from "@/components/ui/text-field" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-text-field-textarea-root` }>
< VStack width = "full" height = "full" align = "center" justify = "center" >
< VStack width = "full" maxWidth = "480px" gap = "spacingY.componentDefault" >
< TextField label = "라벨" description = "size=large (default)" size = "large" >
< TextFieldTextarea accessibility-label = "라벨" placeholder = "플레이스홀더" />
</ TextField >
< TextField label = "라벨" description = "size=medium" size = "medium" >
< TextFieldTextarea accessibility-label = "라벨" placeholder = "플레이스홀더" />
</ TextField >
< TextField variant = "underline" description = "size=large (default)" size = "large" >
< TextFieldTextarea accessibility-label = "라벨" placeholder = "플레이스홀더" />
</ TextField >
< TextField variant = "underline" description = "size=medium" size = "medium" >
< TextFieldTextarea accessibility-label = "라벨" placeholder = "플레이스홀더" />
</ TextField >
</ VStack >
</ VStack >
</ view >
);
}
You can fix the height or set the minimum/maximum height by directly specifying height-related styles to <TextFieldTextarea>.
When using a fixed height, specify autoresize={false} and an explicit height together.
import "./styles" ;
import { useSeedClassName, VStack } from "@seed-design/lynx-react" ;
import { TextField, TextFieldTextarea } from "@/components/ui/text-field" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-text-field-textarea-root` }>
< VStack width = "full" height = "full" align = "center" justify = "center" >
< VStack width = "full" maxWidth = "480px" >
< TextField label = "라벨" description = "설명을 써주세요" >
< TextFieldTextarea
accessibility-label = "라벨"
placeholder = "플레이스홀더"
autoresize = { false }
style = {{ height: "250px" }}
/>
</ TextField >
</ VStack >
</ VStack >
</ view >
);
}
import "./styles" ;
import { useSeedClassName, VStack } from "@seed-design/lynx-react" ;
import { TextField, TextFieldTextarea } from "@/components/ui/text-field" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-text-field-textarea-root` }>
< VStack width = "full" height = "full" align = "center" justify = "center" >
< VStack width = "full" maxWidth = "480px" >
< TextField label = "라벨" description = "설명을 써주세요" >
< TextFieldTextarea
accessibility-label = "라벨"
placeholder = "플레이스홀더"
style = {{ minHeight: "200px" , maxHeight: "300px" }}
/>
</ TextField >
</ VStack >
</ VStack >
</ view >
);
}
You can use the indicator or showRequiredIndicator prop.
import "./styles" ;
import { useSeedClassName, VStack } from "@seed-design/lynx-react" ;
import { TextField, TextFieldTextarea } from "@/components/ui/text-field" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-text-field-textarea-root` }>
< VStack width = "full" height = "full" align = "center" justify = "center" >
< VStack width = "full" maxWidth = "480px" gap = "spacingY.componentDefault" >
< TextField
label = "선택 필드"
labelWeight = "bold"
description = "설명을 써주세요"
indicator = "선택"
>
< TextFieldTextarea accessibility-label = "선택 필드" placeholder = "플레이스홀더" />
</ TextField >
< TextField label = "필수 필드" description = "설명을 써주세요" required >
< TextFieldTextarea accessibility-label = "필수 필드" placeholder = "플레이스홀더" />
</ TextField >
< TextField label = "필수 필드" description = "설명을 써주세요" required showRequiredIndicator >
< TextFieldTextarea accessibility-label = "필수 필드" placeholder = "플레이스홀더" />
</ TextField >
</ VStack >
</ VStack >
</ view >
);
}
import "./styles" ;
import { useSeedClassName, VStack } from "@seed-design/lynx-react" ;
import { TextField, TextFieldTextarea } from "@/components/ui/text-field" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-text-field-textarea-root` }>
< VStack width = "full" height = "full" align = "center" justify = "center" >
< VStack width = "full" maxWidth = "480px" gap = "x3" >
< TextField label = "라벨" description = "설명을 써주세요" maxGraphemeCount = { 8 }>
< TextFieldTextarea accessibility-label = "라벨" placeholder = "플레이스홀더" />
</ TextField >
</ VStack >
</ VStack >
</ view >
);
}
Provides the result of splitting value into user-perceivable character (grapheme cluster) units via graphemes and slicedGraphemes in the onValueChange callback.
Character segmentation is done through unicode-segmenter .
import "./styles" ;
import { useState } from "@lynx-js/react" ;
import { useSeedClassName, VStack } from "@seed-design/lynx-react" ;
import { TextField, TextFieldTextarea } from "@/components/ui/text-field" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
const [ value , setValue ] = useState ( "" );
const [ graphemes , setGraphemes ] = useState < string []>([]);
return (
< view className = { `${ seedClassName } docs-lynx-text-field-textarea-root` }>
< VStack width = "full" height = "full" align = "center" justify = "center" >
< VStack width = "full" maxWidth = "480px" gap = "x4" >
< TextField
label = "라벨"
description = "국기 이모지 🇰🇷 를 추가해보세요."
maxGraphemeCount = { 100 }
value = {value}
onValueChange = {({ slicedValue , slicedGraphemes }) => {
setValue (slicedValue);
setGraphemes (slicedGraphemes);
}}
>
< TextFieldTextarea accessibility-label = "라벨" placeholder = "플레이스홀더" />
</ TextField >
< VStack gap = "x2" >
< text className = "text-field-textarea-preview__status" >
graphemes.length: { JSON . stringify (graphemes. length )}
</ text >
< text className = "text-field-textarea-preview__status" >
value.length: { JSON . stringify (value. length )}
</ text >
< text className = "text-field-textarea-preview__status" >
graphemes: { JSON . stringify (graphemes)}
</ text >
< text className = "text-field-textarea-preview__status" >value: {value}</ text >
</ VStack >
</ VStack >
</ VStack >
</ view >
);
}
Lynx does not support HTML forms. You can manage input values as React state using value and onValueChange.
import "./styles" ;
import { useState } from "@lynx-js/react" ;
import { useSeedClassName, VStack } from "@seed-design/lynx-react" ;
import { TextField, TextFieldTextarea } from "@/components/ui/text-field" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
const [ value , setValue ] = useState ( "안녕하세요" );
return (
< view className = { `${ seedClassName } docs-lynx-text-field-textarea-root` }>
< VStack width = "full" height = "full" align = "center" justify = "center" >
< VStack width = "full" maxWidth = "480px" gap = "x3" >
< TextField
label = "자기소개"
description = "입력값을 React state로 관리합니다."
value = {value}
onValueChange = {({ value : nextValue }) => setValue (nextValue)}
>
< TextFieldTextarea accessibility-label = "자기소개" placeholder = "저는…" />
</ TextField >
< text className = "text-field-textarea-preview__status" >입력값: {value}</ text >
</ VStack >
</ VStack >
</ view >
);
}
import "./styles" ;
import { useState } from "@lynx-js/react" ;
import { useSeedClassName, VStack } from "@seed-design/lynx-react" ;
import { TextField, TextFieldTextarea } from "@/components/ui/text-field" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
const [ value , setValue ] = useState ( "" );
return (
< view className = { `${ seedClassName } docs-lynx-text-field-textarea-root` }>
< VStack width = "full" height = "full" align = "center" justify = "center" >
< VStack width = "full" maxWidth = "480px" >
< TextField
label = "레이블"
description = "공백을 입력할 수 없어요"
value = {value}
onValueChange = {({ value : nextValue }) => setValue (nextValue. replace ( / / g , "" ))}
>
< TextFieldTextarea accessibility-label = "레이블" placeholder = "공백을 입력해보세요" />
</ TextField >
</ VStack >
</ VStack >
</ view >
);
}
import "./styles" ;
import { useState } from "@lynx-js/react" ;
import { useSeedClassName, VStack } from "@seed-design/lynx-react" ;
import { TextField, TextFieldTextarea } from "@/components/ui/text-field" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
const [ value , setValue ] = useState ( "" );
return (
< view className = { `${ seedClassName } docs-lynx-text-field-textarea-root` }>
< VStack width = "full" height = "full" align = "center" justify = "center" >
< VStack width = "full" maxWidth = "480px" >
< TextField
label = "라벨"
description = "6글자까지 입력 가능합니다"
maxGraphemeCount = { 6 }
value = {value}
onValueChange = {({ slicedValue }) => setValue (slicedValue)}
>
< TextFieldTextarea accessibility-label = "라벨" placeholder = "플레이스홀더" />
</ TextField >
</ VStack >
</ VStack >
</ view >
);
}
TextFieldTextarea by default uses the measurement capability of the Lynx native textarea to automatically increase its height to fit the content. On iOS, the sizing wrapper handles minimum height and vertical padding, while on Android, the native textarea handles it directly. When the actual area height changes, KeyboardAvoidingScrollView recalculates the avoidance position.
On Android, line-spacing="3.2px" is applied by default to match the line height of Crispy typography. When line-spacing is specified, that value takes priority on all platforms, and Android's default correction can be disabled with line-spacing={0}. If you directly change fontSize or lineHeight, you must also specify the corresponding line-spacing.
When placed inside KeyboardAvoidingScrollView, TextFieldTextarea is automatically registered when focused. When the layout changes due to autoresize, the active input position is recalculated.
import { KeyboardAvoidingScrollView } from "@seed-design/lynx-react" ;
import { TextField, TextFieldTextarea } from "@/components/ui/text-field" ;
export function KeyboardAwareFields () {
return (
< KeyboardAvoidingScrollView >
< TextField label = "Content" >
< TextFieldTextarea accessibility-label = "Content" />
</ TextField >
</ KeyboardAvoidingScrollView >
);
}
In editable state, renders a Lynx native <textarea> element instead of HTML <textarea>.
In readOnly state, renders as a <text> element to remove native focus, selection, and cut menus. The ref in this state points to <text> and textarea-specific UI methods and events are not available.
Uses onValueChange from TextField instead of onChange. Provides both the original text and values sliced at grapheme units.
The native bindinput can be additionally passed to TextFieldTextarea.
Since there is no DOM id connection between Field.Label and input, accessibility-label is provided directly to the input.
Autoresize uses native intrinsic height instead of DOM scrollHeight. On iOS, the sizing wrapper owns vertical padding and minimum height to prevent duplication with native content size on first input. On Android, the native textarea owns vertical padding and minimum height directly.
On Android, CSS line-height is not applied to native textarea, so line-spacing="3.2px" is applied by default. An explicit line-spacing value takes priority over this default.
Controlled textarea also maintains native input events as-is and synchronizes via setValue only when the value changes from outside. Since readonly is not toggled on each input, native scroll offset and height measurement are not reset when lines are added.
The default value of show-soft-input-on-focus is true to make the keyboard appear on focus. The component explicitly applies this default value to prevent undefined from being passed as a native attribute. If using a custom keyboard, it can be redefined to false.
Android's fullscreen extract input is disabled by default. When needed, explicitly set android-fullscreen-mode={true}.
The default value of android-set-soft-input-mode is "unspecified". Since passing undefined as a native attribute on Android can cause errors, the component explicitly applies this default value.
android-set-soft-input-mode affects the entire host window containing the input element. The default "unspecified" does not preserve the existing Activity setting but resets it to system-determined mode. On screens where KeyboardAvoidingScrollView handles keyboard avoidance exclusively, it is redefined to "nothing" to prevent separate pan/resize. Use the same value when possible for input elements in the same window.
size="responsive" is not supported in Lynx because there is no CSS viewport breakpoint. Explicitly use large or medium.
HTML form submit, browser validation, React Hook Form, and aria-describedby id connection are not supported.
In large textareas, keyboard avoidance based only on the current caret position is not supported. Currently, the largest area that fits within the safe area among Field, TextField, and native input areas is selected.