Skip to content

Commit 8d0a441

Browse files
Add SwiftUI Table demo and let container legend fill column width
SwiftUITableDemo exercises native SwiftUI Table accessibility on iPhone: the parser does see accessibilityContainerType = .dataTable, but Table collapses to a one-column List on iPhone and reports rowCount = 0, columnCount = 0 with no UIAccessibilityContainerDataTableCell elements, so the legend shows "Data Table (0 × 0)". Container legend entries now expand to the full available width (maxWidth: .infinity) so badges like "Data Table (0 × 0)" sit on a single line instead of wrapping to fit the narrowest child. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b7e51fd commit 8d0a441

9 files changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import AccessibilitySnapshotPreviews
2+
import SwiftUI
3+
4+
/// Spike: does native `SwiftUI.Table` emit `accessibilityContainerType = .dataTable`?
5+
/// Note: on iPhone, `Table` collapses to a single-column list; the accessibility tree
6+
/// may reflect that rather than a true data table.
7+
struct SwiftUITableDemo: View {
8+
struct Sale: Identifiable {
9+
let id = UUID()
10+
let quarter: String
11+
let revenue: String
12+
let growth: String
13+
}
14+
15+
private let sales: [Sale] = [
16+
Sale(quarter: "Q1", revenue: "$10", growth: "+5%"),
17+
Sale(quarter: "Q2", revenue: "$15", growth: "+50%"),
18+
Sale(quarter: "Q3", revenue: "$12", growth: "-20%"),
19+
]
20+
21+
var body: some View {
22+
VStack(alignment: .leading, spacing: 16) {
23+
DemoSection(title: "SwiftUI Table", description: "native Table") {
24+
Table(sales) {
25+
TableColumn("Quarter", value: \.quarter)
26+
TableColumn("Revenue", value: \.revenue)
27+
TableColumn("Growth", value: \.growth)
28+
}
29+
.frame(height: 220)
30+
}
31+
32+
Spacer()
33+
}
34+
.padding()
35+
}
36+
}
37+
38+
#Preview {
39+
SwiftUITableDemo()
40+
.accessibilityPreview(
41+
configuration: .init(viewRenderingMode: .drawHierarchyInRect, showContainers: true)
42+
)
43+
}
Loading
Loading
Loading
Loading
Loading
Loading

Example/AccessibilitySnapshotPreviewsTests/SwiftUIRendererTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ final class SwiftUIRendererTests: AccessibilitySnapshotPreviewsTestCase {
6262
)
6363
}
6464

65+
func testSwiftUITableDemo() {
66+
snapshotVerifyAccessibility(
67+
SwiftUITableDemo(),
68+
configuration: .init(viewRenderingMode: .drawHierarchyInRect, showContainers: true)
69+
)
70+
}
71+
6572
func testTabBarContainerDemo() {
6673
snapshotVerifyAccessibility(
6774
TabBarContainerDemo(),

Sources/AccessibilitySnapshot/AccessibilitySnapshotPreviews/ContainerLegendEntryView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct ContainerLegendEntryView: View {
2121
VStack(alignment: .leading, spacing: LegendLayoutMetrics.legendVerticalSpacing) {
2222
childViews
2323
}
24+
.frame(maxWidth: .infinity, alignment: .leading)
2425
.padding(Self.containerInset)
2526
.padding(.top, badgeHeight / 2)
2627
.overlay(

0 commit comments

Comments
 (0)