feat(html): add aria-controls helper
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
ec2ccc7653
commit
a925142e4e
4 changed files with 19 additions and 1 deletions
|
|
@ -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)`
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
|
||||
|
|
|
|||
7
node.go
7
node.go
|
|
@ -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 {
|
||||
|
|
|
|||
10
node_test.go
10
node_test.go
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue