diff --git a/path_test.go b/path_test.go index ed26979..15ef610 100644 --- a/path_test.go +++ b/path_test.go @@ -121,6 +121,19 @@ func TestNestedLayout_ThroughElementWrapper(t *testing.T) { } } +func TestNestedLayout_ThroughResponsiveWrapper(t *testing.T) { + ctx := NewContext() + + inner := NewLayout("C").C(Raw("wrapped")) + wrapped := NewResponsive(). + Variant("desktop", inner) + got := NewLayout("C").C(wrapped).Render(ctx) + + if !strings.Contains(got, `data-block="C-0-C-0"`) { + t.Fatalf("responsive wrapper should preserve nested block path, got:\n%s", got) + } +} + func TestNestedLayout_NilChild(t *testing.T) { ctx := NewContext() diff --git a/responsive.go b/responsive.go index e7ca77b..2928dc1 100644 --- a/responsive.go +++ b/responsive.go @@ -103,6 +103,10 @@ func (r *Responsive) Variant(name string, layout *Layout) *Responsive { // responsive.go: Render produces HTML with each variant in a data-variant container. // Example: NewResponsive().Variant("desktop", NewLayout("C")).Render(NewContext()). func (r *Responsive) Render(ctx *Context) string { + return r.renderWithPath(ctx, "") +} + +func (r *Responsive) renderWithPath(ctx *Context, path string) string { if r == nil { return "" } @@ -125,7 +129,7 @@ func (r *Responsive) Render(ctx *Context) string { b.WriteString(` data-variant="`) b.WriteString(escapeAttr(v.name)) b.WriteString(`">`) - b.WriteString(Render(v.layout, ctx)) + b.WriteString(renderNodeWithPath(v.layout, ctx, path)) b.WriteString(``) } return b.String()