diff --git a/docs/architecture.md b/docs/architecture.md index 2e9020f..3398163 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -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)` diff --git a/node.go b/node.go index 0650042..837e2d8 100644 --- a/node.go +++ b/node.go @@ -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) diff --git a/node_test.go b/node_test.go index 5fe6aaf..1eac36a 100644 --- a/node_test.go +++ b/node_test.go @@ -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 := `` + 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")