Basic
<template>
<NbField label="Name"><NbTextInput v-model="name" size="sm" /></NbField>
<NbField label="Channel"
><NbSelect v-model="ch" :options="channels" size="sm"
/></NbField>
</template>Every field reads --nb-field-label-width, so fields share one label column. Set it on the container to shift the whole spine:
.my-panel {
--nb-field-label-width: 8rem;
}Label association
The default slot receives a generated id; bind it to your control so the label points at it (or pass your own via labelFor):
<NbField label="Name" v-slot="{ id }">
<NbTextInput :id="id" v-model="name" />
</NbField>Mixed controls align
Every form control puts the same vertical gap between its label and its field, so a row that mixes control types lines its field tops up to the pixel. The gap is one token, --nb-field-label-gap, shared by NbTextInput, NbDatePicker, NbSelect, NbNumberInput, NbSlider and NbField's stack mode. It holds with or without a helper line.
With a helper or error line under one of them, the field tops still align. The message only adds height below the field:
To tighten or loosen every control at once, override the token on a container:
.my-form {
--nb-field-label-gap: 4px;
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | undefined | Label text. Omit and use the #label slot for a custom label. |
hint | string | undefined | Helper text shown under the control, muted. |
orientation | 'row' | 'stack' | 'row' | row: label beside the control on the shared spine. stack: label on its own line, control below. |
align | 'center' | 'start' | 'center' | Vertical alignment of the label against the control. start top-aligns against a tall control. |
control | 'fill' | 'fit' | 'fill' | fill: control fills the value column. fit: control hugs its content and the label runs wide. |
labelFor | string | undefined | Id of the control the label points at. Defaults to an auto-generated id, also exposed to the slot. |
Slots
| Slot | Description |
|---|---|
default | The control. Receives { id, describedby }: bind them to your control for the label and the hint. |
label | Custom label content, replacing the label prop. |
hint | Custom hint content, replacing the hint prop. |