Label at Front
Any active control with text should have a name that begins with that text, including the text children of the control.
Impact
VoiceOver users expect the accessible name announced first when interacting with a control. As a best practice, we recommend having a controls visible text within the name and all other information within the accessible value, hint, or role.
Confirmation
- Turn on VoiceOver
- Focus the element
- One of the following will happen:
- Inaccessible: VoiceOver will announce other text before announcing the active control's text
- Accessible: VoiceOver will announce the active control's text first
How to Fix
An issue found by this rule is caused by the visible text missing from the start of the control's accessibility label.
UIKit
In storyboard:
- Select the element with a
LabelAtFront
issue - Ensure that the Inspectors Panel is visible
- Select the Identity Inspector.
- Under Accessibility, there is a category called "Label". Enter a label that either exactly matches or begins with the visible text.
In code:
Find where the accessibility label has been set, and verify that the accessibilityLabel
's value either matches or begins with all the visible text of the component.
button.title = "Login"
button.accessibilityLabel = "Login to Your Account"
SwiftUI
Ensure to set an accessibility label that either matches or begins with all the visible text of the component.
Button(action: {
openMenu()
}) {
Text("Menu")
}