Hi there
Issue
I've implemented a custom DisclosureGroupStyle for a List, which shows hierarchical data. However, it seems that when applying this (or any other) custom DisclosureGroupStyle in macOS the context menu stops working, except on the lowest level. In iOS, on the other hand, the context menu keeps working on all levels.
Is this excepted behaviour?
Example
var body: some View {
List(categories, id: \.value, children: \.children) { tree in
Text(tree.value).font(.subheadline)
.contextMenu{
Button("Test") {}
}
}
.disclosureGroupStyle(SideBarDisclosureGroupStyle())
.padding(50)
}
}
struct SideBarDisclosureGroupStyle: DisclosureGroupStyle {
func makeBody(configuration: Configuration) -> some View {
HStack(alignment: .firstTextBaseline) {
configuration.label
Spacer()
Image(systemName:"chevron.\(configuration.isExpanded ? "down" : "right").circle")
.imageScale(.large)
.foregroundStyle(.secondary)
.onTapGesture() {
configuration.isExpanded.toggle()
}
}
.contentShape(Rectangle())
if configuration.isExpanded {
configuration.content
.disclosureGroupStyle(self)
}
}
}
// Example Data (Source: https://swiftwithmajid.com/2020/09/02/displaying-recursive-data-using-outlinegroup-in-swiftui/)
struct Tree<Value: Hashable>: Hashable {
let value: Value
var children: [Tree]? = nil
}
let categories: [Tree<String>] = [
.init(
value: "Clothing",
children: [
.init(value: "Hoodies"),
.init(value: "Jackets"),
.init(value: "Joggers"),
.init(value: "Jumpers"),
.init(
value: "Jeans",
children: [
.init(value: "Regular"),
.init(value: "Slim")
]
),
]
),
.init(
value: "Shoes",
children: [
.init(value: "Boots"),
.init(value: "Sliders"),
.init(value: "Sandals"),
.init(value: "Trainers"),
]
)
]
System info
macOS 13.0 Beta(22A5358e) Xcode 14.0 beta 6 (14A5294g)
Many thanks Sebastian