feat(html): add aria-hidden 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 16:29:33 +00:00
parent 739f1f52fc
commit 48884f7974
2 changed files with 24 additions and 0 deletions

View file

@ -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

View file

@ -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")