all repos — gomponents @ 6efec2175f61125c3cae694b9a4327a990484ca0

HTML components in pure Go

Add aria-* and role attributes (#59) Fixes #50.

Markus Wüstenberg
commit

6efec2175f61125c3cae694b9a4327a990484ca0

parent

f22ce3fb68ca6702a683b7759410ae50a9fddabd

2 files changed, 17 insertions(+), 0 deletions(-)

changed files
M html/attributes.gohtml/attributes.go
@@ -56,6 +56,11 @@ func Alt(v string) g.Node {
return g.Attr("alt", v) } +// Aria attributes automatically have their name prefixed with "aria-". +func Aria(name, v string) g.Node { + return g.Attr("aria-"+name, v) +} + func AutoComplete(v string) g.Node { return g.Attr("autocomplete", v) }
@@ -138,6 +143,10 @@ }
func Rel(v string) g.Node { return g.Attr("rel", v) +} + +func Role(v string) g.Node { + return g.Attr("role", v) } func Rows(v string) g.Node {
M html/attributes_test.gohtml/attributes_test.go
@@ -57,6 +57,7 @@ "pattern": Pattern,
"preload": Preload, "placeholder": Placeholder, "rel": Rel, + "role": Role, "rows": Rows, "src": Src, "style": StyleAttr,
@@ -75,3 +76,10 @@ assert.Equal(t, fmt.Sprintf(`<div %v="hat"></div>`, name), n)
}) } } + +func TestAria(t *testing.T) { + t.Run("returns an attribute which name is prefixed with aria-", func(t *testing.T) { + n := Aria("selected", "true") + assert.Equal(t, ` aria-selected="true"`, n) + }) +}