feat(html): add aria-controls helper
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 18:18:30 +00:00
parent ec2ccc7653
commit a925142e4e
4 changed files with 19 additions and 1 deletions

View file

@ -37,6 +37,7 @@ Accessibility-oriented helpers are also provided for common attribute patterns:
- `AriaLabel(node, label)`
- `AriaDescribedBy(node, ids...)`
- `AriaLabelledBy(node, ids...)`
- `AriaControls(node, ids...)`
- `Role(node, role)`
- `Lang(node, locale)`
- `Dir(node, direction)`

View file

@ -52,7 +52,7 @@ This builds a Header-Content-Footer layout with semantic HTML elements (`<header
## Key Concepts
**Node tree** -- All renderable units implement `Node`, a single-method interface: `Render(ctx *Context) string`. The library composes nodes into trees using `El()` for elements, `Text()` for translated text, and control-flow constructors (`If`, `Unless`, `Each`, `Switch`, `Entitled`).
**Node tree** -- All renderable units implement `Node`, a single-method interface: `Render(ctx *Context) string`. The library composes nodes into trees using `El()` for elements, `Text()` for translated text, and control-flow constructors (`If`, `Unless`, `Each`, `Switch`, `Entitled`), plus accessibility helpers such as `AriaLabel()`, `AriaControls()`, `AriaHidden()`, and `TabIndex()`.
**HLCRF Layout** -- A five-slot compositor that maps to semantic HTML: `<header>` (H), `<aside>` (L/R), `<main>` (C), `<footer>` (F). The variant string controls which slots render: `"HLCRF"` for all five, `"HCF"` for three, `"C"` for content only. Layouts nest: placing a `Layout` inside another layout's slot produces hierarchical `data-block` paths like `L-0-C-0`.

View file

@ -197,6 +197,13 @@ func AriaLabelledBy(n Node, ids ...string) Node {
return Attr(n, "aria-labelledby", strings.Join(ids, " "))
}
// node.go: AriaControls sets the aria-controls attribute on an element node.
// Example: AriaControls(El("button"), "menu-panel").
// Multiple IDs are joined with spaces, matching the HTML attribute format.
func AriaControls(n Node, ids ...string) Node {
return Attr(n, "aria-controls", strings.Join(ids, " "))
}
// node.go: Role sets the role attribute on an element node.
// Example: Role(El("aside"), "complementary").
func Role(n Node, role string) Node {

View file

@ -275,6 +275,16 @@ func TestAriaLabelledByHelper(t *testing.T) {
}
}
func TestAriaControlsHelper(t *testing.T) {
ctx := NewContext()
node := AriaControls(El("button", Raw("menu")), "menu-panel", "shortcut-hints")
got := node.Render(ctx)
want := `<button aria-controls="menu-panel shortcut-hints">menu</button>`
if got != want {
t.Errorf("AriaControls() = %q, want %q", got, want)
}
}
func TestRoleHelper(t *testing.T) {
ctx := NewContext()
node := Role(El("button", Raw("menu")), "navigation")