Reference
Input
Text field. With label, hint or error it is a labelled field.
Input(reveal: Bool, bind: State, label: String, …)
Before 5.0
reveal
label
type
text
password
number
search
placeholder
We send the invoice here.
Hello, Ada Lovelace
Example
state name = "Ada Lovelace"
state email = ""
Stack(gap: .md) {
Input(bind: name, label: "Full name", placeholder: "Ada Lovelace").text
Input(bind: email, label: "Work email", hint: "We send the invoice here.", placeholder: "ada@example.com").email.required
Text(if email == "" { "Hello, {name}" } else { "Hello, {name}: we write to {email}" }).muted
}
A password with a button that shows it
state password = ""
Input(bind: password, label: "Password", hint: "At least 12 characters").password.reveal
With an error message
state handle = "ada lovelace"
derived handleError = if handle.includes(" ") { "A handle has no spaces." } else { "" }
Input(bind: handle, label: "Handle", error: handleError).text
A number between two ends
state seats = 5
Input(bind: seats, label: "Seats", min: 1, max: 50, step: 1).number
Text("{seats} seats")
Disabled
state workspace = "acme-prod"
Input(bind: workspace, label: "Workspace", hint: "Ask an owner to rename it.").disabled
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
reveal: | Bool | false | With |
bind: | State | The state it reads and writes as you type: a | |
label: | String | none | Visible label; also the control's accessible name |
hint: | String | none | Help text under the control, linked to it by |
error: | String | none | Error text (a string; empty when there is none): announced as it appears and sets |
type: | one of its cases | text | What the field holds, and so the keyboard and picker a browser offers; it also sets what
|
placeholder: | String | none | Hint shown while the field is empty |
value: | String or Number | empty | The text it starts with, when no state is bound; |
min: | Number or String | none | The lowest value a |
max: | Number or String | none | The highest value a |
step: | Number | the browser's: 1, or 60 for a time | How far the arrow keys and the spinner move a |
required: | Bool | false | Whether the browser refuses to submit the form while it is empty. Written as a flag, |
disabled: | Bool | false | Whether the control is inert: it cannot be focused or changed, and a form does not send it. Written as a flag, |
size: | one of its cases | md | Its padding and text size. Written as a flag,
|
width: | one of its cases | none: the width of its container | Its width. Written as a flag,
|
rounded: | Bool | false | Fully rounded ends, a pill shape. Written as a flag, |
Attribute families: global, aria, data, input. 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.
.reveal
.text
.password
.number
.search
.tel
.url
.date
.time
.datetime
.color
.required
.disabled
.sm
.md
.lg
.full
.rounded
Events
The DOM events it is drawn to answer. Any other DOM event works too, in an on … { } handler.
| Event | Sends | Meaning |
|---|---|---|
on input | DOM | The value changed, on every keystroke |
on change | DOM | The value was committed |
on keydown | DOM | A key went down; `e.key` names it |
on focus | DOM | The element received focus |
on blur | DOM | The element lost focus |
Every element also takes the props, the events and the attribute families listed on every element.
Slots
It takes no slots.
Renders with the class wf-input, stable across releases, so a stylesheet may target it.
Codes this can raise
E103
A flag, case, part, event or slot the component does not have
E109
An element this output cannot draw
C04
An attribute a built-in does not declare
C05
A positional argument a built-in does not take
F01
A bind: to something that cannot be written
F02
A bind: to a state the control cannot hold
F03
A validate block no control can satisfy
A03
An input with no label