WlField
Content
Full example
<script setup lang="ts">
import { WlButton, WlCheckbox, WlField, WlInput, WlSelect } from "legato-ui";
import { computed, ref } from "vue";
const value = ref("");
const status = ref<string | null>(null);
const error = ref("");
const fluid = ref(false);
const options = computed(() => [
{ label: "Draft", value: "draft" },
{ label: "Published", value: "published" }
]);
function validate(): void {
error.value = value.value.trim() ? "" : "Enter a material title, then validate again.";
}
</script>
<template>
<form
class="wl-stack"
:class="{ 'wl-fluid': fluid }"
data-space="lg"
novalidate
@submit.prevent="validate"
>
<WlCheckbox v-model="fluid">{{ "Fill the form width (wl-fluid)" }}</WlCheckbox>
<WlField
v-slot="field"
label="Material title"
required
hint="Up to 80 characters."
:error="error"
announce-error
><WlInput
:id="field.id"
v-model="value"
:invalid="field.invalid"
:required="field.required"
:aria-labelledby="field.labelId"
:aria-describedby="field.ariaDescribedby"
maxlength="80"
/></WlField>
<WlField
v-slot="field"
label="Status"
hint="Optional. The visible label names the select through labelId; Clear removes the selection."
optional
orientation="horizontal"
>
<WlSelect
:id="field.id"
v-model="status"
:options="options"
option-label="label"
option-value="value"
clearable
:aria-labelledby="field.labelId"
:aria-describedby="field.ariaDescribedby"
/>
</WlField>
<div class="wl-inline" data-space="sm">
<WlButton type="submit" size="sm">{{ "Validate fields" }}</WlButton>
<WlButton size="sm" variant="ghost" @click="value = ''; status = null; error = ''">{{ "Start over" }}</WlButton>
</div>
</form>
</template>Validation
Full example
<script setup lang="ts">
import { WlButton, WlCheckbox, WlField, WlInput, WlSelect } from "legato-ui";
import { computed, ref } from "vue";
const value = ref("");
const status = ref<string | null>(null);
const error = ref("");
const fluid = ref(false);
const options = computed(() => [
{ label: "Draft", value: "draft" },
{ label: "Published", value: "published" }
]);
function validate(): void {
error.value = value.value.trim() ? "" : "Enter a material title, then validate again.";
}
</script>
<template>
<form
class="wl-stack"
:class="{ 'wl-fluid': fluid }"
data-space="lg"
novalidate
@submit.prevent="validate"
>
<WlCheckbox v-model="fluid">{{ "Fill the form width (wl-fluid)" }}</WlCheckbox>
<WlField
v-slot="field"
label="Material title"
required
hint="Up to 80 characters."
:error="error"
announce-error
><WlInput
:id="field.id"
v-model="value"
:invalid="field.invalid"
:required="field.required"
:aria-labelledby="field.labelId"
:aria-describedby="field.ariaDescribedby"
maxlength="80"
/></WlField>
<WlField
v-slot="field"
label="Status"
hint="Optional. The visible label names the select through labelId; Clear removes the selection."
optional
orientation="horizontal"
>
<WlSelect
:id="field.id"
v-model="status"
:options="options"
option-label="label"
option-value="value"
clearable
:aria-labelledby="field.labelId"
:aria-describedby="field.ariaDescribedby"
/>
</WlField>
<div class="wl-inline" data-space="sm">
<WlButton type="submit" size="sm">{{ "Validate fields" }}</WlButton>
<WlButton size="sm" variant="ghost" @click="value = ''; status = null; error = ''">{{ "Start over" }}</WlButton>
</div>
</form>
</template>Field label, hint and error
Required and optional fields, hint plus error, horizontal layout, labelId for Select, email/readonly/textarea and local validation.
Full example
<script setup lang="ts">
import { WlButton, WlField, WlInput, WlSelect, WlTextarea } from "legato-ui";
import { computed, ref } from "vue";
const email = ref("");
const note = ref("");
const error = ref("Enter an email for notifications.");
const saved = ref(false);
const status = ref<string | null>(null);
const options = computed(() => [
{ label: "Draft", value: "draft" },
{ label: "Published", value: "published" }
]);
function validate(): void {
saved.value = /^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/.test(email.value);
error.value = saved.value ? "" : "This example requires an email such as name@example.org.";
}
</script>
<template>
<form
class="wl-stack"
data-space="lg"
novalidate
@submit.prevent="validate"
>
<WlField
label="Notification email"
required
hint="The address is used only in the local example."
:error="error"
><template #default="{ id, labelId, ariaDescribedby, ariaInvalid, invalid, required }"><WlInput
:id="id"
v-model="email"
type="email"
:required="required"
:invalid="invalid"
:aria-invalid="ariaInvalid"
:aria-labelledby="labelId"
:aria-describedby="ariaDescribedby"
/></template></WlField>
<WlField label="Material ID" hint="The field is readable but cannot be changed.">
<template #default="{ id, ariaDescribedby }">
<WlInput
:id="id"
model-value="GAV-24"
readonly
:aria-describedby="ariaDescribedby"
/>
</template>
</WlField>
<WlField
label="Comment"
hint="The label and hint are associated with the textarea through scope."
>
<template #default="{ id, ariaDescribedby }">
<WlTextarea :id="id" v-model="note" :aria-describedby="ariaDescribedby" />
</template>
</WlField>
<WlField
v-slot="field"
label="Status"
hint="Optional. The visible label names the select through labelId; Clear removes the selection."
optional
orientation="horizontal"
>
<WlSelect
:id="field.id"
v-model="status"
:options="options"
option-label="label"
option-value="value"
clearable
:aria-labelledby="field.labelId"
:aria-describedby="field.ariaDescribedby"
/>
</WlField>
<div class="wl-inline" data-space="sm">
<WlButton type="submit" size="sm" variant="primary">{{ "Validate fields" }}</WlButton>
<WlButton
size="sm"
variant="ghost"
@click="email = ''; error = 'Enter an email for notifications.'; saved = false"
>{{ "Restore field error" }}</WlButton>
</div>
<p class="wl-text-small" role="status">
{{ saved ? "Fields passed local validation." : "Check the message below Email." }}
</p>
</form>
</template>Props
Types, accepted values and literal defaults come from the public manifest. Inherited settings name their source; “Not set” means no default is declared.
| Prop | Type / values | Default | Purpose |
|---|---|---|---|
label | string | Not set | Field label. |
required | boolean | false | Asterisk for a required field. |
hint | string | Not set | Hint below the field. |
error | string | Not set | Error text. The hint stays visible. |
id | string | Not set | Field id; generates wl-field-<uid> by default. |
announceError | boolean | false | Announce changing validation errors; static errors are described by the control. |
pt | WlPt< | Not set | Attributes for internal DOM sections. |
optional | boolean | Not set | Show the localized optional marker when required is false. |
orientation | "vertical" | | Not set | Arrange the label above or beside the control. |
Events
No public events.
Slots
| Slot | Type / values | Content |
|---|---|---|
default | default?(props: WlFieldSlotProps): unknown; | Form control; scope: { id, inputId, labelId, ariaDescribedby, ariaInvalid, invalid, required }. |
label | label?(props: { label: string | | Custom field label; receives the label text and required state. |
Pass-through: pt
Sections WlField are listed below. Attributes merge in this order: createWlPt() WlConfig.ptpt instance. Class and style merge; the last supplied value takes priority for other attributes.
| Section | DOM | Purpose |
|---|---|---|
root | div.wl-field | Main element of the component. |
label | label.wl-field__label | Visible component label. |
required | span.wl-field__req | Decorative required-field marker. |
hint | span.wl-field__hint | Help text associated with the field. |
error | span.wl-field__err | Validation message associated with the field. |
Sections refer to the component DOM. Dotted names identify a configuration group and its section; composite parts use their own pt groups. Global and local attributes merge, with class and style added together.
Keyboard and accessibility
- Import styles/primitives.css and add wl-fluid to a form to remove inherited width limits from Field and its controls. Component max-width tokens also allow individual limits; the defaults stay unchanged.
- Pass id, ariaDescribedby and invalid from the default slot to the real input/textarea; label is associated through for.
- Required in WlField shows the required-field marker. Pass required from scope to the field itself.
- Error takes priority over hint and has role=alert. The application owns validation and saving; set readonly/disabled on the control itself.
Keyboard and application responsibilities
Provide a meaningful accessible name and connect labels, hints and errors to the focusable element. Check the behavior with your own data and a screen reader.
WAI-ARIA Authoring PracticesIn your application, check keyboard controls, zoom and focus visibility. State labels and required information must be readable in every theme.