diff options
Diffstat (limited to 'html')
-rw-r--r-- | html/attributes.go | 5 | ||||
-rw-r--r-- | html/attributes_test.go | 7 | ||||
-rw-r--r-- | html/elements.go | 2 | ||||
-rw-r--r-- | html/elements_test.go | 2 |
4 files changed, 14 insertions, 2 deletions
diff --git a/html/attributes.go b/html/attributes.go index fabfbf0..23559f6 100644 --- a/html/attributes.go +++ b/html/attributes.go @@ -81,6 +81,11 @@ func Content(v string) g.Node { return g.Attr("content", v) } +// DataAttr attributes automatically have their name prefixed with "data-". +func DataAttr(name, v string) g.Node { + return g.Attr("data-"+name, v) +} + func For(v string) g.Node { return g.Attr("for", v) } diff --git a/html/attributes_test.go b/html/attributes_test.go index 23445db..b0f76c1 100644 --- a/html/attributes_test.go +++ b/html/attributes_test.go @@ -83,3 +83,10 @@ func TestAria(t *testing.T) { assert.Equal(t, ` aria-selected="true"`, n) }) } + +func TestDataAttr(t *testing.T) { + t.Run("returns an attribute which name is prefixed with data-", func(t *testing.T) { + n := DataAttr("id", "partyhat") + assert.Equal(t, ` data-id="partyhat"`, n) + }) +} diff --git a/html/elements.go b/html/elements.go index c3fa396..18dbeb1 100644 --- a/html/elements.go +++ b/html/elements.go @@ -83,7 +83,7 @@ func ColGroup(children ...g.Node) g.NodeFunc { return g.El("colgroup", children...) } -func Data(children ...g.Node) g.NodeFunc { +func DataEl(children ...g.Node) g.NodeFunc { return g.El("data", children...) } diff --git a/html/elements_test.go b/html/elements_test.go index e9220e5..d7bd8bf 100644 --- a/html/elements_test.go +++ b/html/elements_test.go @@ -41,7 +41,7 @@ func TestSimpleElements(t *testing.T) { "cite": Cite, "code": Code, "colgroup": ColGroup, - "data": Data, + "data": DataEl, "datalist": DataList, "details": Details, "dialog": Dialog, |