diff options
-rw-r--r-- | html/attributes.go | 9 | ||||
-rw-r--r-- | html/attributes_test.go | 8 |
2 files changed, 17 insertions, 0 deletions
diff --git a/html/attributes.go b/html/attributes.go index e67bc1f..fabfbf0 100644 --- a/html/attributes.go +++ b/html/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) } @@ -140,6 +145,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 { return g.Attr("rows", v) } diff --git a/html/attributes_test.go b/html/attributes_test.go index ba8cbb4..23445db 100644 --- a/html/attributes_test.go +++ b/html/attributes_test.go @@ -57,6 +57,7 @@ func TestSimpleAttributes(t *testing.T) { "preload": Preload, "placeholder": Placeholder, "rel": Rel, + "role": Role, "rows": Rows, "src": Src, "style": StyleAttr, @@ -75,3 +76,10 @@ func TestSimpleAttributes(t *testing.T) { }) } } + +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) + }) +} |