feat(html): add aria-labelledby 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 17:16:39 +00:00
parent 97a48fc73d
commit 264ecc3f84
3 changed files with 17 additions and 0 deletions

View file

@ -36,6 +36,7 @@ Accessibility-oriented helpers are also provided for common attribute patterns:
- `AriaLabel(node, label)`
- `AriaDescribedBy(node, ids...)`
- `AriaLabelledBy(node, ids...)`
- `Role(node, role)`
- `Alt(node, text)`
- `AriaHidden(node, hidden)`

View file

@ -175,6 +175,12 @@ func AriaDescribedBy(n Node, ids ...string) Node {
return Attr(n, "aria-describedby", strings.Join(ids, " "))
}
// AriaLabelledBy sets the aria-labelledby attribute on an element node.
// Multiple IDs are joined with spaces, matching the HTML attribute format.
func AriaLabelledBy(n Node, ids ...string) Node {
return Attr(n, "aria-labelledby", strings.Join(ids, " "))
}
// Role sets the role attribute on an element node.
func Role(n Node, role string) Node {
return Attr(n, "role", role)

View file

@ -252,6 +252,16 @@ func TestAriaDescribedByHelper(t *testing.T) {
}
}
func TestAriaLabelledByHelper(t *testing.T) {
ctx := NewContext()
node := AriaLabelledBy(El("input"), "label-1", "label-2")
got := node.Render(ctx)
want := `<input aria-labelledby="label-1 label-2">`
if got != want {
t.Errorf("AriaLabelledBy() = %q, want %q", got, want)
}
}
func TestRoleHelper(t *testing.T) {
ctx := NewContext()
node := Role(El("button", Raw("menu")), "navigation")