Meaningful Accessible Name
An element's accessible name should not include its accessibility trait.
Impact
VoiceOver users should have access to the same information visible on the screen without repeated information in the VoiceOver announcement.
Confirmation
- Turn on VoiceOver
- Focus on the element
- One of the following will happen:
- Inaccessible: VoiceOver will announce the element's accessibility trait twice - as part of the element's accessible name, and as an accessibility trait (e.g. announcement will be "Next Button, button").
- Accessible: VoiceOver will announce the element's accessible name followed by the accessibility trait. The trait will only be announced once after the name (e.g. announcement will be "Next, button").
How to Fix
An issue found by this rule is caused when the accessible name contains the element's accessibility trait.
UIKit
In storyboard:
- Select the element with a
MeaningfulAccessibleName
issue - Ensure that the Inspectors Panel is visible
- Select the Identity Inspector
- Under Accessibility, there is a category called "Label". Enter a label that exactly matches or contains all of the visible text, and do not include the element's accessibility trait as part of the label.
In code:
Find where the accessibility label was set and ensure that the accessibility label's value either matches or contains all the visible text of the component, and does not contain the element's accessibility trait.
button.title = "Next"
button.accessibilityTraits = .button
SwiftUI
Ensure to set an accessibility label that either matches or contains all the visible text of the component, and does not include the element's accessibility trait.
Button(action: {
openMenu()
}) {
Text("Next")
}.accessibility(label: Text("Next"))