Reference
Field
A label, a hint and an error around a control of your own: the first control in its block is named by the label and described by the hint and the error, and marked invalid while there is one.
Field(label: String, hint: String, error: String) { … }
Since 6.2.0
label
hint
Used for buttons and links.
Chosen: #0f766e
Example
state color = "#0f766e"
derived colorError = if color == "#ffffff" { "White disappears on the page." } else { "" }
Field(label: "Brand colour", hint: "Used for buttons and links.", error: colorError) {
ColorPicker(bind: color, label: "Brand colour", swatches: ["#0f766e", "#1d4ed8", "#b91c1c", "#ffffff"])
}
Text("Chosen: {color}").muted
Around a control of your own
state plan = "team"
Field(label: "Plan", hint: "You can change it at any time.") {
ToggleGroup(bind: plan, label: "Plan") {
ToggleGroup.Item("Free", value: "free")
ToggleGroup.Item("Team", value: "team")
ToggleGroup.Item("Scale", value: "scale")
}
}
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
label: | String | none | The label above the control; it names the first control in the block ( |
hint: | String | none | Help text under the control, linked to the first control in the block by |
error: | String | none | Error text under the control: |
Attribute families: global, aria, data. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.
Flags and cases
A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.
No flags of its own.
Events
Every element also takes the props, the events and the attribute families listed on every element.
Slots
children
Drawn for it
What Field draws itself, by the class a stylesheet can select. They are not written.
| Part | Class | Meaning |
|---|---|---|
Field.Label | — | Its label. |
Field.Hint | — | Its hint. |
Field.Error | — | Its error, announced as it appears. |
Renders with the class wf-field wf-field--custom, stable across releases, so a stylesheet may target it.