accessibilityChildren
Replaces the existing accessibility element's children with one or more new synthetic accessibility elements.
Declaration
compose().accessibilityChildren({
children: ReactNode,
})nonisolated func accessibilityChildren<V>(
@ContentBuilder children: () -> V
) -> some View
where V : ViewParameters
options.children*ReactNodeA
ContentBuilderthat represents the replacement child views the framework uses to generate accessibility elements.
Discussion
Use this modifier to replace an existing element's children with one or more new synthetic accessibility elements you provide. This allows for synthetic, non-visual accessibility elements to be set as children of a visual accessibility element.
SwiftUI creates an accessibility container implicitly when needed. If an accessibility element already exists, the framework converts it into an accessibility container.
In the example below, a Canvas displays a graph of vertical bars that don't have any
inherent accessibility elements. You make the view accessible by adding
the accessibilityChildren(children:) modifier with views whose accessibility
elements represent the values of each bar drawn in the canvas:
var body: some View {
Canvas { context, size in
// Draw Graph
for data in dataSet {
let path = Path(
roundedRect: CGRect(
x: (size.width / CGFloat(dataSet.count))
* CGFloat(data.week),
y: 0,
width: size.width / CGFloat(dataSet.count),
height: CGFloat(data.lines),
cornerRadius: 5)
context.fill(path, with: .color(.blue))
}
// Draw Axis and Labels
...
}
.accessibilityLabel("Lines of Code per Week")
.accessibilityChildren {
HStack {
ForEach(dataSet) { data in
RoundedRectangle(cornerRadius: 5)
.accessibilityLabel("Week \(data.week)")
.accessibilityValue("\(data.lines) lines")
}
}
}
}SwiftUI hides any views that you provide with the children parameter,
then the framework uses the views to generate the accessibility elements.
See also
More in Accessibility.
- accessibilityActionAdds an accessibility action to the view. Actions allow assistive technologies, such as the VoiceOver, to interact with the view by invoking the action.
- accessibilityActionsAdds multiple accessibility actions to the view.
- accessibilityActivationPointThe activation point for an element is the location assistive technologies use to initiate gestures.
- accessibilityAddTraitsAdds the given traits to the view.
- accessibilityAdjustableActionAdds an accessibility adjustable action to the view. Actions allow assistive technologies, such as the VoiceOver, to interact with the view by invoking the action.
- accessibilityCustomContentAdd additional accessibility information to the view.
- accessibilityDefaultFocusDefines a region in which default accessibility focus is evaluated by assigning a value to a given accessibility focus state binding.
- accessibilityDirectTouchExplicitly set whether this accessibility element is a direct touch area. Direct touch areas passthrough touch events to the app rather than being handled through an assistive technology, such as VoiceOver. The modifier accepts an optional AccessibilityDirectTouchOptions option set to customize the functionality of the direct touch area.
- accessibilityDragPointThe point an assistive technology should use to begin a drag interaction.
- accessibilityDropPointThe point an assistive technology should use to end a drag interaction.
- accessibilityElementCreates a new accessibility element, or modifies the AccessibilityChildBehavior of the existing accessibility element.
- accessibilityFocusedModifies this view by binding its accessibility element's focus state to the given boolean state value.