# Text Field Input
URL: /lynx/components/text-field-input
Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/text-field-input.mdx
A component that receives single-line text input and combines it with Field's label, description, and error states.
Lynx Engine 최소 버전: 3.6
사용 XElement:
사용 가능 버전: @seed-design/lynx-react@0.4.0, @seed-design/lynx-css@0.7.0
## Preview
```tsx
import "./styles";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
Lynx's `TextFieldInput` does not support React's `autoFocus` prop. If you need to focus from the beginning, specify an `id` for the input and call the `focus` UI method of Lynx native input after the screen is ready.
## Installation
- npm: npx @seed-design/cli add ui:text-field
- pnpm: pnpm dlx @seed-design/cli add ui:text-field
- yarn: yarn dlx @seed-design/cli add ui:text-field
- bun: bun x @seed-design/cli add ui:text-field
## Props
### `TextField`
### `TextFieldInput`
## Examples
### State
#### Enabled
```tsx
import "./styles";
import { useSeedClassName, VStack } from "@seed-design/lynx-react";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
#### Disabled
```tsx
import "./styles";
import { useSeedClassName, VStack } from "@seed-design/lynx-react";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
#### Read Only
```tsx
import "./styles";
import { useSeedClassName, VStack } from "@seed-design/lynx-react";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
### Size
Specify the TextField size with `size`. (default: `large`)
Lynx supports `large` and `medium`. `responsive` is not supported because there are no CSS viewport breakpoints.
```tsx
import "./styles";
import { useSeedClassName, VStack } from "@seed-design/lynx-react";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
### Customizable Parts
When conveying context with just icons, include text describing the icon's meaning in `description` or `label`. If the icon itself needs to be read, specify `accessibility-label`.
#### Prefix
```tsx
import "./styles";
import IconMagnifyingglassLine from "@karrotmarket/lynx-monochrome-icon/IconMagnifyingglassLine";
import { useSeedClassName, VStack } from "@seed-design/lynx-react";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
}
>
}
>
);
}
```
#### Suffix
```tsx
import "./styles";
import IconWonLine from "@karrotmarket/lynx-monochrome-icon/IconWonLine";
import { useSeedClassName, VStack } from "@seed-design/lynx-react";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
}>
}>
);
}
```
#### Both Affixes
```tsx
import "./styles";
import IconPlusCircleLine from "@karrotmarket/lynx-monochrome-icon/IconPlusCircleLine";
import IconWonLine from "@karrotmarket/lynx-monochrome-icon/IconWonLine";
import { useSeedClassName, VStack } from "@seed-design/lynx-react";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
}
suffixIcon={}
>
}
suffixIcon={}
>
);
}
```
#### Indicator
You can use the `indicator` or `showRequiredIndicator` prop.
```tsx
import "./styles";
import { useSeedClassName, VStack } from "@seed-design/lynx-react";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
#### Grapheme Count
```tsx
import "./styles";
import { useSeedClassName, VStack } from "@seed-design/lynx-react";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
);
}
```
The result of dividing `value` into user-perceived character (grapheme cluster) units is provided as `graphemes` and `slicedGraphemes` in the `onValueChange` callback.
Character segmentation is done via [unicode-segmenter](https://github.com/cometkim/unicode-segmenter).
```tsx
import "./styles";
import { useState } from "@lynx-js/react";
import { useSeedClassName, VStack } from "@seed-design/lynx-react";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const [value, setValue] = useState("");
const [graphemes, setGraphemes] = useState([]);
return (
{
setValue(slicedValue);
setGraphemes(slicedGraphemes);
}}
>
graphemes.length: {JSON.stringify(graphemes.length)}
value.length: {JSON.stringify(value.length)}
graphemes: {JSON.stringify(graphemes)}
value: {value}
);
}
```
### Use Cases
#### Controlled State
Lynx does not support HTML Forms. You can manage input values as React state using `value` and `onValueChange`.
```tsx
import "./styles";
import { useState } from "@lynx-js/react";
import { useSeedClassName, VStack } from "@seed-design/lynx-react";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const [value, setValue] = useState("안녕하세요");
return (
setValue(nextValue)}
>
입력값: {value}
);
}
```
#### Number Formatting
```tsx
import "./styles";
import { useState } from "@lynx-js/react";
import { useSeedClassName, VStack } from "@seed-design/lynx-react";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
function formatNumber(value: string) {
if (value === "") return value;
const number = Number(value.replace(/,/g, ""));
if (Number.isNaN(number)) return "";
return number.toLocaleString();
}
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const [value, setValue] = useState("1000");
const formattedValue = formatNumber(value);
return (
setValue(nextValue)}
>
);
}
```
#### Slicing
```tsx
import "./styles";
import { useState } from "@lynx-js/react";
import { useSeedClassName, VStack } from "@seed-design/lynx-react";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
export default function Example() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const [value, setValue] = useState("");
return (
setValue(slicedValue)}
>
);
}
```
### Lynx Usage
#### Keyboard Avoidance
When placed inside `KeyboardAvoidingScrollView`, `TextFieldInput` is automatically registered when focused and scrolls to a position not hidden by the keyboard.
```tsx
import { KeyboardAvoidingScrollView } from "@seed-design/lynx-react";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
export function KeyboardAwareFields() {
return (
);
}
```
## Web Version Differences
- In the editable state, it renders the Lynx native `` element instead of the HTML ``.
- In the `readOnly` state, it renders as a `` element to remove the native focus, selection, and cut menu. The ref in this state points to ``, and input-only UI methods and events cannot be used.
- Use `onValueChange` of the snippet `TextField` instead of `onChange`. It provides both the original text and the value cut in grapheme units.
- The native `bindinput` can be additionally passed to `TextFieldInput`.
- Since there is no DOM id connection between `Field.Label` and the input, provide `accessibility-label` directly to the input.
- The default value of `show-soft-input-on-focus` is `true` so that the keyboard appears on focus. The component explicitly applies this default so that `undefined` is not passed as a native attribute. If you use a custom keyboard, you can override it with `false`.
- The default value of `android-set-soft-input-mode` is `"unspecified"`. Since an error may occur on Android if `undefined` is passed as a native attribute, the component explicitly applies this default.
- `android-set-soft-input-mode` affects the entire host window containing the input element. The default value `"unspecified"` is not a value that preserves the existing Activity settings, but resets it to the system-determined mode. On a screen where `KeyboardAvoidingScrollView` is dedicated to keyboard avoidance, override it with `"nothing"` to prevent separate pan/resize. Use the same value as much as possible for input elements in the same window.
- `size="responsive"` is not supported in Lynx, which has no CSS viewport breakpoints. Specify `large` or `medium`.
## Unsupported Lynx Features
- HTML form submit, browser validation, React Hook Form, and `aria-describedby` id connection are not supported.