[Enhancement]Add accessibility label support for toolbar back button#35011
[Enhancement]Add accessibility label support for toolbar back button#35011Vignesh-SF3580 wants to merge 12 commits intodotnet:net11.0from
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 35011Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 35011" |
There was a problem hiding this comment.
Pull request overview
Adds new APIs to let apps provide a dedicated accessibility label for the toolbar back button (separate from the visible back button title) for both NavigationPage and Shell, and wires it through the relevant toolbars/trackers and platform implementations.
Changes:
- Introduces
NavigationPage.BackButtonAccessibilityLabelProperty(+Get/SetBackButtonAccessibilityLabel) andBackButtonBehavior.AccessibilityLabel. - Plumbs the label into
Toolbar.BackButtonAccessibilityLabel, and updates Android/Windows (and partial Tizen) toolbar mappings/platform behavior. - Adds unit tests covering default/set/propagation and Shell dynamic update behavior.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Controls/tests/Core.UnitTests/ToolbarTests.cs | Adds unit tests for NavigationPage back button accessibility label behavior. |
| src/Controls/tests/Core.UnitTests/ShellToolbarTests.cs | Adds unit tests for Shell/BackButtonBehavior.AccessibilityLabel propagation and updates. |
| src/Controls/src/Core/Toolbar/Toolbar.cs | Adds Toolbar.BackButtonAccessibilityLabel property used by platform toolbars. |
| src/Controls/src/Core/Toolbar/Toolbar.Android.cs | Adds handler mapping to refresh the back button when accessibility label changes (Android). |
| src/Controls/src/Core/Toolbar/Toolbar.Windows.cs | Adds handler mapping to refresh the back button when accessibility label changes (Windows). |
| src/Controls/src/Core/Toolbar/Toolbar.Tizen.cs | Adds Tizen mapping stub for accessibility label. |
| src/Controls/src/Core/Toolbar/Toolbar.Mapper.cs | Registers the new mapping for BackButtonAccessibilityLabel. |
| src/Controls/src/Core/Platform/Android/Extensions/ToolbarExtensions.cs | Sets Android NavigationContentDescription with priority for the new accessibility label. |
| src/Controls/src/Core/Platform/Windows/Extensions/ToolbarExtensions.cs | Sets Windows AutomationProperties.Name for Narrator based on the new accessibility label with save/restore behavior. |
| src/Controls/src/Core/NavigationPage/NavigationPage.cs | Adds attached property and accessor methods for NavigationPage back button accessibility label. |
| src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs | Propagates the attached accessibility label into the toolbar when navigation stack changes. |
| src/Controls/src/Core/Shell/BackButtonBehavior.cs | Adds AccessibilityLabel bindable property to BackButtonBehavior. |
| src/Controls/src/Core/ShellToolbar.cs | Pulls BackButtonBehavior.AccessibilityLabel into Toolbar.BackButtonAccessibilityLabel. |
| src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellToolbarTracker.cs | Applies custom accessibility label to the Android Shell toolbar navigation content description. |
| src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs | Applies custom accessibility label to iOS Shell navigation items/back button items. |
| src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs | Applies back button accessibility label via UIBarButtonItem.AccessibilityLabel for NavigationPage on iOS/macCatalyst. |
| src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt | Adds new API entries for NavigationPage/Shell back button accessibility label APIs (netstandard). |
| src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt | Adds new API entries for NavigationPage/Shell back button accessibility label APIs (net). |
| src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt | Adds new API entries for NavigationPage/Shell back button accessibility label APIs (Android). |
| src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt | Adds new API entries for NavigationPage/Shell back button accessibility label APIs (iOS). |
| src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt | Adds new API entries for NavigationPage/Shell back button accessibility label APIs (MacCatalyst). |
| src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt | Adds new API entries for NavigationPage/Shell back button accessibility label APIs (Windows). |
| src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt | Adds new API entries for NavigationPage/Shell back button accessibility label APIs (Tizen). |
Multi-Model Code Review: PR #35011[Enhancement] Add accessibility label support for toolbar back button Re-Review (April 20) — After Author FixesThree independent reviewers re-analyzed the updated diff. Status of each prior finding below. CI Status
All PR-relevant checks pass: ✅ Build (Debug+Release, macOS+Windows), ✅ Pack, ✅ Helix Unit Tests, ✅ 18 Integration Test jobs (Build, Blazor, MultiProject, RunOnAndroid, RunOniOS ×8, WindowsTemplates, Samples Windows). Prior Review Status
✅ Finding 1: PublicAPI Entries — FIXEDAll ✅ Finding 2: Shell iOS Title Fallback — FIXED
else if (barButtonItem.Title is null)
{
// Preserve default back button title when only accessibility label is set
barButtonItem.Title = previousNavItem.Title;
}This prevents the chevron-only display and aligns with NavigationRenderer behavior. ✅ Finding 3: AutomationId/AccessibilityLabel Inconsistency — FIXEDThe else
{
NavigationItem.LeftBarButtonItem.AccessibilityIdentifier = image.AutomationId;
if (hasCustomLabel)
{
NavigationItem.LeftBarButtonItem.AccessibilityLabel = customAccessibilityLabel;
}
}iOS and Android now both apply the custom label regardless of AutomationId presence.
|
| # | Severity | Issue |
|---|---|---|
| 1 | 🔴 CRITICAL | Missing PublicAPI entries for Toolbar.BackButtonAccessibilityLabel + mapper methods |
| 2 | 🟡 MODERATE | Shell iOS: BackBarButtonItem loses visible title when only accessibility label set |
| 3 | 🟡 MODERATE | Cross-platform inconsistency: AutomationId vs AccessibilityLabel priority |
| 4 | 🟡 MODERATE | Test coverage gaps |
| 5 | 🟢 MINOR | Windows Tag-based save/restore edge case |
| 6 | 🟢 MINOR | iOS NavigationRenderer visual side effect |
kubaflo
left a comment
There was a problem hiding this comment.
Could you please review Shane's comment?
@PureWeen @kubaflo Based on the review comments, I have addressed the valid concerns.
|
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
|
1 similar comment
|
|
|
|
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Details
There is currently no way to set a custom accessibility label for the toolbar back button independently of the visible text. Screen readers (VoiceOver, TalkBack, Narrator) read the back button’s title, but developers often need a more descriptive label without changing the UI.
This PR addresses that gap for both NavigationPage and Shell across Android, iOS, macCatalyst, and Windows.
Description of Changes
Introduced new BackButtonAccessibilityLabel APIs for both NavigationPage and Shell, allowing developers to customize screen reader announcements independently of the visible back button text.
NavigationPage
Shell
Platform Implementations
Android
iOS / macCatalyst
Windows
Additional Notes
Added 7 unit tests:
NavigationPage: set, clear, default
Shell: set, clear, default, dynamic update
Updated Public API across all 7 TFM files
Issues Fixed
Fixes #17984
Screenshots
Mac:
iOS:
Android:
17984Android.mov