Skip to content

Commit

Permalink
Enable attributes to be appended to members of nested component groups (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
JohnSundell authored May 13, 2021
1 parent f4fd706 commit cd60159
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Sources/Plot/API/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions Tests/PlotTests/HTMLComponentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ final class HTMLComponentTests: XCTestCase {
XCTAssertEqual(html, #"<p class="one two three">Hello</p>"#)
}

func testAppendingClassToWrappingComponentContainingGroup() {
struct Wrapper: Component {
var body: Component {
ComponentGroup {
Paragraph("One")
Paragraph("Two")
}
.class("one")
}
}

let html = Wrapper().class("two").render()
XCTAssertEqual(html, #"<p class="one two">One</p><p class="one two">Two</p>"#)
}

func testReplacingClass() {
let html = Paragraph("Hello")
.class("one")
Expand Down

0 comments on commit cd60159

Please sign in to comment.