Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

StringField.tsx

32 lines721 Bytes

1import { FieldError } from './FieldError'
2import type { FieldWithValue } from '@tanstack/react-form'
3​
4interface StringFieldProps {
5 field: FieldWithValue<string>
6 label: string
7}
8​
9export function StringField(props: StringFieldProps) {
10 const { field, label } = props
11​
12 return (
13 <label
14 className={field.meta.isValidating ? 'validating' : ''}
15 style={{
16 display: 'block',
17 }}
18 >
19 <span>{label}</span>
20​
21 <input
22 name={field.name}
23 value={field.value}
24 onBlur={field.handleBlur}
25 onChange={(e) => field.handleChange(e.target.value)}
26 aria-invalid={field.meta.isInvalid}
27 />
28 <br />
29 <FieldError field={field} />
30 </label>
31 )