From 48884f797455e368980c8e02779719fa6bd04c8c Mon Sep 17 00:00:00 2001 From: Virgil Date: Fri, 3 Apr 2026 16:29:33 +0000 Subject: [PATCH] feat(html): add aria-hidden helper Co-Authored-By: Virgil --- node.go | 8 ++++++++ node_test.go | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/node.go b/node.go index ec0582a..24a2da3 100644 --- a/node.go +++ b/node.go @@ -107,6 +107,14 @@ func Alt(n Node, text string) Node { return Attr(n, "alt", text) } +// AriaHidden sets the aria-hidden attribute on an element node. +func AriaHidden(n Node, hidden bool) Node { + if hidden { + return Attr(n, "aria-hidden", "true") + } + return Attr(n, "aria-hidden", "false") +} + func (n *elNode) Render(ctx *Context) string { var b strings.Builder diff --git a/node_test.go b/node_test.go index 2321727..4764bac 100644 --- a/node_test.go +++ b/node_test.go @@ -195,6 +195,22 @@ func TestAltHelper(t *testing.T) { } } +func TestAriaHiddenHelper(t *testing.T) { + ctx := NewContext() + + hidden := AriaHidden(El("span", Raw("decorative")), true) + gotHidden := hidden.Render(ctx) + if !strings.Contains(gotHidden, `aria-hidden="true"`) { + t.Errorf("AriaHidden(true) = %q, want aria-hidden=\"true\"", gotHidden) + } + + visible := AriaHidden(El("span", Raw("decorative")), false) + gotVisible := visible.Render(ctx) + if !strings.Contains(gotVisible, `aria-hidden="false"`) { + t.Errorf("AriaHidden(false) = %q, want aria-hidden=\"false\"", gotVisible) + } +} + func TestElNode_MultipleAttrs(t *testing.T) { ctx := NewContext() node := Attr(Attr(El("a", Raw("link")), "href", "/home"), "class", "nav")