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

text-field.ts

21 lines643 Bytes

1import { html } from 'lit'
2import type { FieldWithValue } from '@tanstack/lit-form'
3​
4export function textField(field: FieldWithValue<string>, label: string) {
5 return html`
6 <label>
7 <span>${label}</span>
8 <input
9 name=${field.name}
10 .value=${field.value}
11 @input=${(event: InputEvent) =>
12 field.handleChange((event.currentTarget as HTMLInputElement).value)}
13 @blur=${() => field.handleBlur()}
14 aria-invalid=${field.meta.isInvalid ? 'true' : 'false'}
15 />
16 ${field.errors.map(
17 (error) => html`<small role="alert">${error.message}</small>`,
18 )}
19 </label>
20 `