Input Group
Example sourceGo · Copyable
This is the complete source for the gallery example above.examples/components/input_group.go
Reuse the component construction and Render methods in a scaffolded project. The example’s registerSection and shared helpers are provided by the component gallery.
package main
import (
"fmt"
"github.com/dyike/keel/ui/core"
"github.com/dyike/keel/ui/el"
"github.com/dyike/keel/ui/kit"
"github.com/dyike/keel/ui/theme"
"unicode/utf8"
)
func init() {
registerSection("input_group", "inputs", func() core.Widget {
query := kit.Input("").Placeholder(demoText("Customer or order number", "客户或订单号")).Clearable()
status := demoText("Waiting for query", "等待查询")
group := kit.InputGroup(demoText("Find orders", "查询订单"), query).Prefix(kit.Icon(kit.IconSearch)).Suffix(kit.Button(demoText("Search", "查询"), func() { status = demoText("Query: ", "查询:") + query.Value() }))
amount := kit.InputGroup(demoText("Amount", "金额"), kit.Input("").Filter("0123456789.")).Prefix(el.ViewFunc(func(*el.Context) el.Element { return el.Text("¥") })).Suffix(el.ViewFunc(func(*el.Context) el.Element { return el.Text("CNY") }))
message := kit.TextArea("").Rows(3).Placeholder(demoText("Enter order notes…", "输入订单备注…"))
composer := kit.InputGroup(demoText("Order notes", "订单备注"), message).
Addon("heading", kit.InputGroupBlockStart, el.ViewFunc(func(*el.Context) el.Element {
return el.Text(demoText("Notes are saved with the order", "备注将随订单保存"))
})).
Addon("footer", kit.InputGroupBlockEnd, el.ViewFunc(func(cx *el.Context) el.Element {
return el.Div().WFull().Row().Items(el.Center).Gap(theme.SpaceMd).Child(
el.Text(fmt.Sprintf(demoText("%d characters", "%d 字"), utf8.RuneCountInString(message.Value()))).Grow(),
kit.Button(demoText("Save notes", "保存备注"), func() { status = demoText("Saved: ", "已保存:") + message.Value() }).Size(28).Render(cx))
}))
return el.Root(el.ViewFunc(func(cx *el.Context) el.Element {
return el.Div().P(24).W(el.Dp(440)).MaxW(el.Full).Gap(14).Child(group.Render(cx), el.Text(status), amount.Render(cx), composer.Render(cx))
}))
})
}
Group text boxes, icons, units, or action buttons into the same border.
query := kit.Input("").Placeholder("Customer or order number").Clearable()
search := kit.InputGroup("Find orders", query).
Prefix(kit.Icon(kit.IconSearch)).
Suffix(kit.Button("Search", func() { lookup(query.Value()) }))
The Input instance is responsible for text, filtering, read-only and callbacks, and the Input Group is responsible for borders, labels and additional content before and after. The incoming Input is only rendered through this group and cannot be rendered elsewhere at the same time. Additional content width is determined by itself; leave enough space for long buttons and narrow containers.
Prefix(el.View)/Suffix(el.View)places additional content, pass nil to remove. Dynamic addition and deletion of additional content retains input focus and text.Value/SetValue/OnChangeuses the state of the internal Input; programmatic assignment does not trigger a callback. Format, password, clear and commit configuration are still placed on the Input.SetDisableddisables the input and all attached operations, preserving the contents when restored; disabling the input itself also disables the entire group. Read-only input still allows the use of additional buttons.SetError/Error/FocusIDcan access Form. The group label also serves as the accessible name of the input; click on a visible label to focus the editor. Accepts Form field names when empty label.- Tab accesses the editor and focusable additional operations in sequence, and the text editing shortcut keys are the same as Input.
Agent: The outer layer is group, the inner editor is textbox with field names; additional buttons retain their own names, roles, and disabled states.
Verify: go run ./examples/components -section input_group; add -theme dark to verify dark color.
Addon(id, alignment, view) can add any number of additional content in four locations:
| alignment | location |
|---|---|
InputGroupInlineStart |
Left side of editor, after Prefix |
InputGroupInlineEnd |
Right side of editor, before Suffix |
InputGroupBlockStart |
Above the entire input line |
InputGroupBlockEnd |
Below the entire input line |
The same position is arranged in the order of addition. The ID must be non-empty and stable; replace the content and position with the same ID, and pass nil to delete. The upper and lower areas each occupy one row, and Row/Wrap can be used to combine counts, toolbars, buttons or menus within the View. Click to focus input on text, icons, and blank spaces; interactive controls retain their own click and focus behaviors.
message := kit.TextArea("").Rows(3)
composer := kit.InputGroup("Notes", message).
Addon("heading", kit.InputGroupBlockStart,
el.ViewFunc(func(*el.Context) el.Element { return el.Text("Enter order notes") })).
Addon("send", kit.InputGroupBlockEnd,
kit.Button("Save", func() { save(message.Value()) }).Size(28))
Additional buttons directly use kit.Button, which can be configured with Variant, Size, Icon, Name, Loading and disabled state; compact buttons can be set to .Variant(kit.ButtonGhost).Size(24). Icon button requires Name. Menus, Popovers and Tooltips can also be combined as additional Views, inheriting their respective interfaces.
The TextArea shares these locations with single-line input; the top and bottom panels grow with content, and the number of lines of text is controlled by the internal TextArea. Rows sets the minimum height; to increase the height with the content and set an upper limit, use AutoGrow(minRows, maxRows) of TextArea, see Input. There is only one layer of field borders outside the input and additional content, and the focus box covers the entire group. Read-only allows additional actions, input-disabled, group-disabled, and ancestor-disabled disable all additional actions.