From cd6015944cdd37ca6a43e9ea86b3b34079d2b1cf Mon Sep 17 00:00:00 2001 From: John Sundell Date: Thu, 13 May 2021 12:04:01 +0200 Subject: [PATCH] Enable attributes to be appended to members of nested component groups (#64) Make it possible to append attributes to the member elements of a `ComponentGroup`, when such a group is nested within a custom wrapper component. --- Sources/Plot/API/Node.swift | 4 +++- Tests/PlotTests/HTMLComponentTests.swift | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Sources/Plot/API/Node.swift b/Sources/Plot/API/Node.swift index acd0100..245883e 100644 --- a/Sources/Plot/API/Node.swift +++ b/Sources/Plot/API/Node.swift @@ -184,7 +184,9 @@ internal extension Node where Context == Any { static func components(_ components: [Component]) -> Node { Node { renderer in components.forEach { - renderer.renderComponent($0) + renderer.renderComponent($0, + deferredAttributes: renderer.deferredAttributes + ) } } } diff --git a/Tests/PlotTests/HTMLComponentTests.swift b/Tests/PlotTests/HTMLComponentTests.swift index 6491c62..1c6d3d2 100644 --- a/Tests/PlotTests/HTMLComponentTests.swift +++ b/Tests/PlotTests/HTMLComponentTests.swift @@ -116,6 +116,21 @@ final class HTMLComponentTests: XCTestCase { XCTAssertEqual(html, #"

Hello

"#) } + func testAppendingClassToWrappingComponentContainingGroup() { + struct Wrapper: Component { + var body: Component { + ComponentGroup { + Paragraph("One") + Paragraph("Two") + } + .class("one") + } + } + + let html = Wrapper().class("two").render() + XCTAssertEqual(html, #"

One

Two

"#) + } + func testReplacingClass() { let html = Paragraph("Hello") .class("one")