Label
A form label. Inside a Field it points at the control and
takes the field’s required and disabled.
<Field class="flex flex-col gap-1" required> <Label>Email</Label> <Input type="email" bind:value /></Field>On its own, associate it with for:
<Label for="email" required>Email</Label><Input id="email" bind:value /><Label
required={false}
disabled={false}
/>- A real
<label>, so clicking it focuses the control it points at. - Inside a
Fieldit finds the control, mirrorsrequiredanddisabled, and names aRadioGroupthrougharia-labelledby. - The required asterisk is a snippet, so it can be any mark you like.
On its own
Section titled “On its own”Outside a field, point it at the control with for.
Code
<script lang="ts"> import { Input, Label } from "@viamrobotics/prime-ui";</script>
<div class="not-content flex max-w-xs flex-col gap-1"> <Label for="standalone-email" required>Email</Label> <Input id="standalone-email" type="email" required placeholder="you@viam.com" /></div>Custom required indicator
Section titled “Custom required indicator”Pass an indicator snippet to replace the asterisk. It renders only while the label is required.
Code
<script lang="ts"> import { Field, Input, Label } from "@viamrobotics/prime-ui";</script>
<Field class="not-content flex max-w-xs flex-col gap-1" required> <Label> Email {#snippet indicator()} <span class="text-xs text-subtle-2">(required)</span> {/snippet} </Label> <Input type="email" placeholder="you@viam.com" /></Field>States
Section titled “States”States
In a field
Styling
Section titled “Styling”class lands on the <label>, an inline flex row with a small gap between the text and the indicator. The asterisk is aria-hidden, so it never reaches the accessible name. Put required on the control too.
| Prop | Type | Default | Description |
|---|---|---|---|
required | boolean | Show a required asterisk. Defaults to the enclosing field's required. | |
disabled | boolean | Dim the label and show a not-allowed cursor. Defaults to the enclosing field's disabled. | |
indicator | Snippet | Replaces the required asterisk. Rendered only when required. |
Plus everything in HTMLLabelAttributes, spread onto the element.