diff --git a/README.md b/README.md index 39eccb8..2152f04 100644 --- a/README.md +++ b/README.md @@ -927,6 +927,16 @@ The `element.go`, `style.go`, `msg.go`, `program.go`, `key.go`, `cmd.go`, `statu **HTML**: every state change describes the new tree as lightweight virtual nodes and **patches** `#wui-root` in place. Children are matched by identity: controls with an ID (inputs, buttons, selects, checkboxes, text areas, links) find their old node wherever it moved, and other nodes reuse the next old sibling with the same tag. A node is replaced only when nothing matches, so a banner inserted above a form does not rebuild the inputs below it. Because the DOM nodes persist, browser-owned state survives updates without any bookkeeping: keyboard focus, caret and selection, scroll offsets, in-progress typing, and an open native dropdown. `Empty()` and false `If`/`When` branches render as invisible placeholders, so toggling one never shifts its siblings onto each other's nodes. +For lists whose rows have no ID'd controls, give each row a key with `wui.Keyed`. The renderer then moves existing rows and inserts only the new one, instead of re-patching every row from the insertion point down, and per-row browser state stays with its row: + +```go +wui.List(false, wui.Map(m.todos, func(_ int, t Todo) wui.Element { + return wui.Keyed(t.ID, row(t)) +})...) +``` + +`Keyed` adds no markup or layout, and the TUI renders the child unchanged. + Event listeners are attached once per node and swap their handler on each patch, so a re-render allocates no new `js.Func`s for unchanged elements. --- @@ -983,7 +993,6 @@ The WASM binary includes none of the charmbracelet packages. The TUI binary incl ## Limitations (v1) -- **No explicit keys** — the HTML renderer matches controls by their IDs and everything else by tag order. Rows without ID'd controls are matched in order, so inserting at the front of a long list patches every row rather than moving them. - **Button focus keys derive from labels by default** — two buttons with the same label and no `WithID` in one view share TUI focus; give repeated buttons IDs. - **No theme system** — style is applied per-element inline (`Style.Merge` helps compose variants); in the browser the base stylesheet's `--wui-*` custom properties, `WithStylesheet` and `Style.Class` are the global styling hooks. - **TextArea editing is basic in the TUI** — typing, Enter, and Backspace append and delete at the end of the buffer; there is no cursor movement within the text. The browser build uses a native `