Label in Name
Any active control with visible text, including children, should have that text available within the accessible name.
Impact
VoiceOver users should have access to the same information visible on the screen. Anytime a control's text is updated, update the accessibility label to contain the new text.
Confirmation
- Turn on VoiceOver
- Focus on the element
- One of the following will happen:
- Inaccessible: VoiceOver will announce text that does not contain the visible text of the active control.
- Accessible: VoiceOver will announce text that contains the visible text of the active control.
- Accessible: VoiceOver will announce the visible text of the active control.
How to Fix
An issue found by this rule is caused by part or all of the visible text missing from the control's accessibility label.
UIKit
In storyboard:
- Select the element with a
LabelInName
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.
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.
button.title = "Login"
button.accessibilityLabel = "Account login"
SwiftUI
Ensure to set an accessibility label that either matches or contains all the visible text of the component.
Button(action: {
openMenu()
}) {
Text("Menu")
}.accessibility(label: Text("Main Menu"))