Field
A field adds a label, a required mark and an error message to an input.
Default
A label above the input. Clicking the label focuses the input.
svelte
svelte
<Field label="Username" name="username">
<TextField bind:value={username} />
</Field>Required
The required mark follows the label, and the input is marked as required.
svelte
svelte
<Field required label="Username" name="username">
<TextField bind:value={username} />
</Field>Invalid
The message shows under the input, and the input turns invalid. Clear the message when the input is valid again.
This username is taken.
svelte
svelte
<Field label="Username" name="username" invalid="This username is taken.">
<TextField bind:value={username} />
</Field>Label hidden
The label is not shown. Give the input its own label, for example an aria-label, so it stays accessible.
svelte
svelte
<Field overidelabel label="Search" name="search">
<TextField bind:value={search} aria-label="Search" />
</Field>Status bar
An input can add content to the right of the status bar. TextField shows a character counter when it has a maxlength, and reports an error to the field when the text is too long.
svelte
svelte
<Field label="Username" name="username">
<TextField bind:value={username} maxlength={12} />
</Field>