Defines the behavior for the child elements of the new parent element.
Members (3)
get · iOS 13.0+
ignore
TypeScript
static get ignore(): AccessibilityChildBehavior
Swift declaration
static let ignore: AccessibilityChildBehavior
Any child accessibility elements become hidden.
Use this behavior when you want a view represented by
a single accessibility element. The new accessibility element
has no initial properties. So you will need to use other
accessibility modifiers, such as ``View/accessibilityLabel(_:)``,
to begin making it accessible.
var body: some View {
VStack {
Button("Previous Page", action: goBack)
Text("\(pageNumber)")
Button("Next Page", action: goForward)
}
.accessibilityElement(children: .ignore)
.accessibilityValue("Page \(pageNumber) of \(pages.count)")
.accessibilityAdjustableAction { action in
if action == .increment {
goForward()
} else {
goBack()
}
}
}
Before using the ``AccessibilityChildBehavior/ignore``behavior, consider
using the ``AccessibilityChildBehavior/combine`` behavior.
- Note: A new accessibility element is always created.
get · iOS 13.0+
combine
TypeScript
static get combine(): AccessibilityChildBehavior
Swift declaration
static let combine: AccessibilityChildBehavior
Any child accessibility element's properties are merged
into the new accessibility element.
Use this behavior when you want a view represented by
a single accessibility element. The new accessibility element
merges properties from all non-hidden children. Some
properties may be transformed or ignored to achieve the
ideal combined result. For example, not all of ``AccessibilityTraits``
are merged and a ``AccessibilityActionKind/default`` action
may become a named action (``AccessibilityActionKind/init(named:)``).
struct UserCell: View {
var user: User
var body: some View {
VStack {
Image(user.image)
Text(user.name)
Button("Options", action: showOptions)
}
.accessibilityElement(children: .combine)
}
}
A new accessibility element is created when:
* The view contains multiple or zero accessibility elements.
* The view wraps a ``UIViewRepresentable``/``NSViewRepresentable``.
- Note: If an accessibility element is not created, the
``AccessibilityChildBehavior`` of the existing
accessibility element is modified.
get · iOS 13.0+
contain
TypeScript
static get contain(): AccessibilityChildBehavior
Swift declaration
static let contain: AccessibilityChildBehavior
Any child accessibility elements become children of the new
accessibility element.
Use this behavior when you want a view to be an accessibility
container. An accessibility container groups child accessibility
elements which improves navigation. For example, all children
of an accessibility container are navigated in order before
navigating through the next accessibility container.
var body: some View {
ScrollView {
VStack {
HStack {
ForEach(users) { user in
UserCell(user)
}
}
.accessibilityElement(children: .contain)
.accessibilityLabel("Users")
VStack {
ForEach(messages) { message in
MessageCell(message)
}
}
.accessibilityElement(children: .contain)
.accessibilityLabel("Messages")
}
}
}
A new accessibility element is created when:
* The view contains multiple or zero accessibility elements.
* The view contains a single accessibility element with no children.
- Note: If an accessibility element is not created, the
``AccessibilityChildBehavior`` of the existing
accessibility element is modified.