feat(html): add aria-hidden helper
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
739f1f52fc
commit
48884f7974
2 changed files with 24 additions and 0 deletions
8
node.go
8
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
|
||||
|
||||
|
|
|
|||
16
node_test.go
16
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")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue