diff --git a/framework/h/attribute.go b/framework/h/attribute.go index 87f30c7..9651607 100644 --- a/framework/h/attribute.go +++ b/framework/h/attribute.go @@ -17,9 +17,13 @@ func (m *AttributeMapOrdered) Set(key string, value any) { switch v := value.(type) { case string: m.data.Set(key, v) + case *AttributeMap: + for k, v2 := range *v { + m.Set(k, v2) + } case *AttributeMapOrdered: - v.Each(func(k string, v string) { - m.Set(k, v) + v.Each(func(k string, v2 string) { + m.Set(k, v2) }) case *AttributeR: m.data.Set(v.Name, v.Value) diff --git a/framework/h/render_test.go b/framework/h/render_test.go index 24c3e92..10a6662 100644 --- a/framework/h/render_test.go +++ b/framework/h/render_test.go @@ -64,6 +64,39 @@ func TestRenderAttributes_1(t *testing.T) { ) } +func TestRenderAttributes_2(t *testing.T) { + div := Div( + AttributePairs("class", "bg-red-500", "id", "my-div"), + Button( + AttributePairs("class", "bg-blue-500", "id", "my-button"), + Text("Click me"), + Attribute("disabled", "true"), + Attribute("data-attr", "value"), + ), + ) + + assert.Equal(t, + `
`, + Render(div)) +} + +func TestRenderEmptyDiv(t *testing.T) { + t.Parallel() + assert.Equal(t, + ``, + Render(Div()), + ) +} + +func TestRenderVoidElement(t *testing.T) { + t.Parallel() + assert.Equal(t, + ``, + Render(Input("text")), + ) + assert.Equal(t, ``, Render(Tag("input"))) +} + func TestRawContent(t *testing.T) { t.Parallel() str := "