Skip to content

Commit aa8def0

Browse files
authored
Merge pull request #774 from JPToroDev/grid
Fix positioning issues caused by nested `<div>`s in `Grid`.
2 parents 6a62f28 + 522f0a3 commit aa8def0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Sources/Ignite/Elements/Grid.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public struct Grid: HTML, HorizontalAligning {
149149
} else {
150150
handleItem(item)
151151
.class(gutterClass)
152+
.render()
152153
}
153154
}
154155
}
@@ -157,15 +158,17 @@ public struct Grid: HTML, HorizontalAligning {
157158
}
158159

159160
/// Removes a column class, if it exists, from the item and reassigns it to a wrapper.
160-
private func handleItem(_ item: any HTML) -> some HTML {
161+
private func handleItem(_ item: any HTML) -> any HTML {
161162
var item = item
162163
var name: String?
163164
if let widthClass = item.attributes.classes.first(where: { $0.starts(with: "col-md-") }) {
164165
item.attributes.remove(classes: widthClass)
165166
name = scaleWidthClass(widthClass)
166167
}
167168

168-
return Section(item)
169+
item = item.isSection ? item : Section(item)
170+
171+
return item
169172
.class(name ?? "col")
170173
.class(alignment.vertical.itemAlignmentClass)
171174
}
@@ -185,6 +188,7 @@ public struct Grid: HTML, HorizontalAligning {
185188
return ForEach(passthrough.items) { item in
186189
handleItem(item.attributes(attributes))
187190
.class(gutterClass)
191+
.render()
188192
}
189193
}
190194

Sources/Ignite/Framework/ElementTypes/HTML.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ extension HTML {
8989
var isImage: Bool {
9090
self is Image || (self as? AnyHTML)?.wrapped is Image
9191
}
92+
93+
/// A Boolean value indicating whether this represents `Section`.
94+
var isSection: Bool {
95+
self is Section || (self as? AnyHTML)?.wrapped is Section
96+
}
9297
}
9398

9499
extension HTML {

0 commit comments

Comments
 (0)