diff options
author | Ken Powers | 2024-10-30 10:06:20 -0400 |
---|---|---|
committer | GitHub | 2024-10-30 15:06:20 +0100 |
commit | 900ef87aac4f4c6c0be49faeb1fc7c190c17a482 (patch) | |
tree | 62b8c2c71512362e8a0edbe09a9159e3a119e20f | |
parent | 2e44d495769421423921bfcb06ebfc53f8370dd3 (diff) | |
download | gomponents-900ef87aac4f4c6c0be49faeb1fc7c190c17a482.tar.lz gomponents-900ef87aac4f4c6c0be49faeb1fc7c190c17a482.tar.zst gomponents-900ef87aac4f4c6c0be49faeb1fc7c190c17a482.zip |
Add popover attributes (#236)
This PR adds popover attributes as detailed here: https://developer.mozilla.org/en-US/docs/Web/API/Popover_API/Using --------- Co-authored-by: Markus Wüstenberg <markus@maragu.dk>
-rw-r--r-- | html/attributes.go | 12 | ||||
-rw-r--r-- | html/attributes_test.go | 33 |
2 files changed, 45 insertions, 0 deletions
diff --git a/html/attributes.go b/html/attributes.go index be8393e..e4cd796 100644 --- a/html/attributes.go +++ b/html/attributes.go @@ -213,6 +213,18 @@ func Placeholder(v string) g.Node { return g.Attr("placeholder", v) } +func Popover(value ...string) g.Node { + return g.Attr("popover", value...) +} + +func PopoverTarget(v string) g.Node { + return g.Attr("popovertarget", v) +} + +func PopoverTargetAction(v string) g.Node { + return g.Attr("popovertargetaction", v) +} + func Poster(v string) g.Node { return g.Attr("poster", v) } diff --git a/html/attributes_test.go b/html/attributes_test.go index 67b98f4..cfb64b5 100644 --- a/html/attributes_test.go +++ b/html/attributes_test.go @@ -78,6 +78,8 @@ func TestSimpleAttributes(t *testing.T) { {Name: "name", Func: Name}, {Name: "pattern", Func: Pattern}, {Name: "placeholder", Func: Placeholder}, + {Name: "popovertarget", Func: PopoverTarget}, + {Name: "popovertargetaction", Func: PopoverTargetAction}, {Name: "poster", Func: Poster}, {Name: "preload", Func: Preload}, {Name: "rel", Func: Rel}, @@ -107,6 +109,37 @@ func TestSimpleAttributes(t *testing.T) { } } +func TestVariadicAttributes(t *testing.T) { + tests := []struct { + Name string + Func func(...string) g.Node + }{ + {Name: "popover", Func: Popover}, + } + + for _, test := range tests { + t.Run(test.Name + "(no args)", func(t *testing.T) { + n := g.El("div", test.Func()) + assert.Equal(t, fmt.Sprintf(`<div %v></div>`, test.Name), n) + }) + + t.Run(test.Name +"(one arg)", func(t *testing.T) { + n := g.El("div", test.Func("hat")) + assert.Equal(t, fmt.Sprintf(`<div %v="hat"></div>`, test.Name), n) + }) + + t.Run(test.Name + "(two args panics)", func(t *testing.T) { + defer func() { + if r := recover(); r == nil { + t.Errorf("expected a panic") + } + }() + n := g.El("div", test.Func("hat", "party")) + assert.Equal(t, "unreachable", 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") |