Forms
Field
The layout every form control is built on: label, description, the control, help text and validation error, stacked or side by side. The form tags (tk:input, tk:select, tk:checkbox...) already use it; write these tags yourself to give the same layout to a control of your own, or to join several controls into one group with attached prefix and suffix blocks.
tk:field.wrapper builds the whole field from props. tk:field.control adds icons, a spinner and other content beside the control, in one row. tk:field.group joins controls side by side. tk:field is only the grid that lays the parts out, for markup written by hand.
Nothing to show
"Color" over "Used in the header", then the color input, then "Any CSS color" under it in muted text. When color has a validation error, the message shows under everything in red. The label points to the control through for, and the description and help get the ids color-description and color-help, so pass the control's id to the wrapper: without it the label is not linked and the texts have no ids.
A group of controls #
The input and the button are joined into one block, with only the outer corners rounded. Buttons, prefixes and suffixes in the group take the controls' border, shadow, focus ring and outer corners (those of the group's size), so the block reads as one field. The group has role="group", named by "Search" and described by its description and help, so screen readers announce both when focus enters it.
Nothing to show
Attached prefix and suffix #
Gray blocks with "https://" before the input and ".com" after it, attached to it. Inputs take prefix and suffix themselves (<tk:input prefix="R$" />); the group is for controls that do not, or for several controls between the same blocks.
Nothing to show
Inline layout #
The label on the left and the checkbox at the end of the line, as tk:checkbox and tk:switch lay themselves out. tk:field places its children by their data-tallkit-label, data-tallkit-control and data-tallkit-text attributes.
Nothing to show
Field control #
tk:field.control places icon, icon-trailing, kbd and loading around your own control, inside a row you style with class.
Nothing to show
Several controls #
A group joins any number of controls: here a select, an input and a button share one block.
Nothing to show
Prefix and suffix components #
tk:field.group.prefix and tk:field.group.suffix inside the group take element props, such as an icon or a label.
Nothing to show
Label extras #
The field props add a badge and an info tooltip next to the label, and labelAppend puts content at its end.
Nothing to show
Inline alignment #
With inline, align chooses where the control goes: left, right, justify-left or justify-right.
Nothing to show
Validation in a group #
The error of a control with no label of its own is shown under the whole row, so the row stays aligned.
Nothing to show
Rows from data #
In a Livewire @foreach, put the wire:key on an element that wraps each row, so removing a row keeps the others as they are.
Nothing to show
Sizes #
size on the group sets the size of its label, texts, prefix and suffix; give the controls the same size.
Nothing to show
Customization #
On a group, class goes to the block that joins the controls and prefix: / suffix: reach the blocks.
Nothing to show
Reference
tk:field.wrapper
├── tk:field.group
│ ├── tk:field.group.prefix
│ ├── (controls)
│ └── tk:field.group.suffix
└── tk:field.control
tk:field
tk:field.wrapper
| Prop | Type | Default | Description |
|---|---|---|---|
name |
string | null |
The field whose validation error is shown. |
id |
string | null |
The id of the control: the label's for, and the base of the ids of the description, help and error. Not derived from name here. |
inline |
bool | false |
Puts the control and the label side by side, for checkboxes and switches. |
align |
string | left |
With inline: left puts the control before the label, right after it. justify-right puts the label at the start and the control at the end of the line; justify-left puts the control at the start and the label at the end. |
Also accepts the field props: label, description, help, prefix, suffix, badge, info, size, showError... bag has no effect here: the error bag is the one of the control with the same id, or the one set with error:bag. When there is nothing around the control (no label, description, help, prefix or suffix), only the control and its error are rendered. Inside a tk:field.group, that error is rendered below the group's row instead (before the group's help text), with the same <id>-error id.
tk:field.control
Takes the field control props: prepend, icon, iconTrailing, kbd, append and loading, plus size. With none of them and no class, it renders the slot alone. It draws no border or background of its own: the form tags style it as their box, and with a control of your own the box is up to its class (border rounded-lg h-10 items-center...).
tk:field.group
| Prop | Type | Default | Description |
|---|---|---|---|
label |
string | slot | null |
The label of the group, which names it. |
description |
string | slot | null |
Text under the label, which describes the group. |
help |
string | slot | null |
Text under the group. |
prefix |
string | slot | null |
A block attached before the controls. |
suffix |
string | slot | null |
A block attached after the controls. |
size |
string | md |
Sets the size of the label, texts, prefix and suffix. |
labelPrepend, labelAppend, badge and info work as on the field props.
tk:field.group.prefix and tk:field.group.suffix
Take size and the element props, so a block can have an icon, a label or any slot content.
tk:field
| Prop | Type | Default | Description |
|---|---|---|---|
inline |
bool | false |
Side-by-side layout. |
align |
string | left |
With inline, as on tk:field.wrapper. |
Slots
| Tag | Slot | Description |
|---|---|---|
tk:field.wrapper |
default | The control. |
tk:field.control |
default | The control. |
tk:field.group |
default | The controls to join. |
tk:field.group.prefix, tk:field.group.suffix |
default | The block content, in place of label. |
tk:field |
default | The label, control and texts, laid out by their data attributes. |
Customization
Classes and attributes on tk:field.wrapper go to the parts through the prefixes of the field props (field:, label:, description:, help:, error:, group:, prefix:, suffix:...); tk:field.control takes those of the field control props. On tk:field.group, class goes to the block that joins the controls, and prefix: / suffix: reach the blocks.
Nothing to show
Accessibility
The label is a <label> whose for is the field's id. The description, the help text and the error get the ids <id>-description, <id>-help and <id>-error, which the form controls list in their aria-describedby (the error only while it has a message, so a forced invalid with none adds no reference); a control of your own should do the same. The error is a polite live region. A tk:field.group with a label, a description or a help text is a role="group" labelled and described by them.
Behavior notes
- The label is dimmed while the control inside has
disabled. - With
inline, the field getsdata-tallkit-field-inlinewith thealignvalue, and the package CSS places the label, control and texts from it, in thecomponentslayer: a utility class on one of them (<tk:checkbox align="right" label:class="col-start-2" />) overrides that placement. - A
tk:field.groupwithlabel:forkeeps a real<label>pointing to that id instead of becoming a named group. - The validation error is read from the bag by
name; without aname, no error is shown. - In a
tk:field.group, the validation error of a control with no label, description, help, prefix or suffix of its own is shown under the whole row, not between the controls, so the row stays aligned; its id is still<id>-error, as listed in the control'saria-describedby. - In a
tk:field.group, a control with icons, a clear button or a spinner (wrapped bytk:field.control) fills the free width of the row, and an invalid control keeps its red border on every side, including the sides next to the prefix and suffix.