Skip to content

Field

We'll never share it.

That name is taken.

Where you're based.

Optional.

Weekdays only.

A form-field wrapper that links a label, optional description and error message to a control, wiring aria-describedby / aria-invalid for you.

<script>
import Field from "@invisible-ui/svelte/Field.svelte";
</script>
PropTypeDefaultDescription
label *string—Field label.
descriptionstring | undefinedundefinedHelper text.
errorstring | undefinedundefinedError message (sets aria-invalid).
requiredbooleanfalseMark the field required.
disabledbooleanfalseDisable styling/state.
idstring | undefinedundefinedControl id.
childrenSnippet<[{ controlProps: FieldApi["controlProps"]; controlId: string }]> | undefinedundefinedThe control, given the props to spread onto it and its id.

In Svelte, the control is the children snippet, which receives controlProps and controlId:

<Field label="Email">
{#snippet children({ controlProps })}
<input {...controlProps} type="email" />
{/snippet}
</Field>

In React, children is a function that receives controlProps and controlId, and useField wires markup of your own:

<Field label="Email" error={error}>
{({ controlProps }) => <input {...controlProps} type="email" />}
</Field>

Themeable via --ds-field-*.