Repository navigation
Add Label.IsTextSelectable to let users select and copy label text - #40509
Conversation
Adds ILabel.IsTextSelectable (default interface member), the Label.IsTextSelectable bindable property and a LabelHandler mapper. Android uses TextView.SetTextIsSelectable, Windows uses TextBlock.IsTextSelectionEnabled, and iOS/Mac Catalyst host a UITextView inside MauiLabel for native selection. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- iOS: keep multi-line truncation in the text container instead of per-paragraph, route touches on empty text-view space to the label, and relayout on padding changes. - Add a scenarios UI test page comparing layout with selection on and off, plus label tap coverage. - Document that Android cannot ellipsize selectable text. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- iOS: resync overlay when text changes, mirror semantic content attribute and alignment, fill missing font/color attributes, keep selection handles reachable in HitTest, support wrapped labels in tap recognition, fix PublicAPI nullability marker. - Android: restore the native focusable mode and only reconcile focus after connect. - Windows: rebuild tap subscriptions when IsTextSelectable changes. - Tests: wrapper (shadow) and runtime-enable tap scenarios, tapping on glyphs. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…s, focus fix with wrapper Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved gesture and enabled-state mapping defects can trigger unrelated ancestor commands or leave selection stale, while select-and-copy and rendering coverage is missing and Mac Catalyst gesture tests fail before verification.
7 open issues
Update Core Windows label selection when enabled state changes · New Refresh selection through the mapper chain on enabled changes · New Test selecting and copying text, including after runtime enablement · New Limit gesture arbitration exception to label and immediate wrapper · New Use Catalyst-supported tap dispatch in gesture tests · New Cache normalized selection text across drawing and layout · New Verify selectable text rendering, not just parent label bounds · New
What changed in this PR
Adds opt-in Label.IsTextSelectable support to .NET MAUI, enabling native text selection and copying without custom handlers. This addresses the scenario behind #29033 while retaining the existing label platform-view types.
Changes:
- Adds the bindable property,
ILabelcontract, handler mappings, and public API declarations. - Implements native selection on Android and Windows and a text-view overlay on iOS/Mac Catalyst, with gesture integration.
- Adds binding, native-state, runtime-toggle, layout, and gesture tests.
| File | Description |
|---|---|
src/Core/tests/DeviceTests/Stubs/LabelStub.cs |
Exposes selection state for device tests. |
src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.Windows.cs |
Reads native Windows selection state. |
src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.iOS.cs |
Tests overlay text and measurement stability. |
src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.cs |
Tests selection initialization and toggling. |
src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.Android.cs |
Tests native selection and interaction-state restoration. |
src/Core/src/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt |
Records the Core contract and mapper API. |
src/Core/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt |
Records the Core contract and mapper API. |
src/Core/src/PublicAPI/net/PublicAPI.Unshipped.txt |
Records the Core contract and mapper API. |
src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt |
Records Windows selection APIs. |
src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt |
Records Mac Catalyst overlay-related APIs. |
src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt |
Records iOS overlay-related APIs. |
src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt |
Records Android selection APIs. |
src/Core/src/Platform/Windows/TextBlockExtensions.cs |
Applies selection based on selectable and enabled state. |
src/Core/src/Platform/iOS/MauiLabel.cs |
Hosts and synchronizes the selectable text overlay. |
src/Core/src/Platform/iOS/LabelExtensions.cs |
Applies selection state to MauiLabel. |
src/Core/src/Platform/Android/TextViewExtensions.cs |
Toggles selection and restores interaction flags. |
src/Core/src/Handlers/Label/LabelHandler.Windows.cs |
Maps selection to Windows. |
src/Core/src/Handlers/Label/LabelHandler.Standard.cs |
Adds the non-platform mapper declaration. |
src/Core/src/Handlers/Label/LabelHandler.iOS.cs |
Maps selection to the Apple overlay. |
src/Core/src/Handlers/Label/LabelHandler.cs |
Registers the selection property mapping. |
src/Core/src/Handlers/Label/LabelHandler.Android.cs |
Maps selection to Android. |
src/Core/src/Core/ILabel.cs |
Adds the selection contract with a default implementation where supported. |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/LabelIsTextSelectableScenarios.cs |
Tests layout stability and label gestures. |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/LabelIsTextSelectable.cs |
Tests visibility during toggling and span taps. |
src/Controls/tests/TestCases.HostApp/Issues/LabelIsTextSelectableScenarios.cs |
Supplies styling, layout, gesture, and recycling scenarios. |
src/Controls/tests/TestCases.HostApp/Issues/LabelIsTextSelectable.cs |
Supplies selectable labels and a paste target. |
src/Controls/tests/Core.UnitTests/LabelTests.cs |
Tests the default value and binding behavior. |
src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt |
Records the Controls property API. |
src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt |
Records the Controls property API. |
src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt |
Records the Controls property API for Windows. |
src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt |
Records the Controls property API for Mac Catalyst. |
src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt |
Records the Controls property API for iOS. |
src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt |
Records the Controls property API for Android. |
src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Windows.cs |
Receives handled taps and rebuilds subscriptions on toggles. |
src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs |
Allows label taps alongside native selection recognizers. |
src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.Android.cs |
Shares selection touches with label and wrapper gestures. |
src/Controls/src/Core/Label/Label.Windows.cs |
Refreshes selection when enabled state changes. |
src/Controls/src/Core/Label/Label.Mapper.cs |
Registers platform-specific selection dependencies. |
src/Controls/src/Core/Label/Label.cs |
Defines and documents the bindable property. |
src/Controls/src/Core/Label/Label.Android.cs |
Restores gesture focusability after selection is disabled. |
Review effort: Balanced
|
/review expert-review-with-gate |
|
Warning Your |
|
/review run-tests |
This comment has been minimized.
This comment has been minimized.
kubaflo
left a comment
There was a problem hiding this comment.
Could you check the ai's suggestions?
…ed test (#40538) ### Description Two improvements to `/review run-tests` comments: **Outdated comments are minimized.** When `/review run-tests` runs again on a PR, the bot's earlier run-tests comments (and "unsupported" notices) are minimized as *Outdated* right after the new comment is posted. **Failed tests are precise and linked.** The results now show: - each failed test by its exact name, the platforms it failed on (each linked to that test result in Azure DevOps) and the first line of its error; - links to all test results (Tests tab) and the build logs; - failed jobs first, each linked to its log; - a status line that says, for example, "7 tests failed on Windows. See **Failed tests** below." The `maui-pr-uitests (selected run)` check summary gets the same test and job links. `testresults/resultsbybuild` returns wrong test titles for some results (in build 1694092 the same title appeared for 5 different tests), so the updater now reads each failed result (`test/Runs/{run}/results/{id}`, public) for its name, error and link. At most 60 results are read; the rest fall back to the summary data. ### Verified live - Minimized the older bot comment on #40482 with `Hide-RunTestsOutdatedComments`; GraphQL reports `isMinimized: true, minimizedReason: outdated`, and the newest comment stays visible. - Refreshed #40509 with `Update-RunTestsResults.ps1`; the comment now lists the 7 failing Windows `LabelIsTextSelectable*` tests with links and errors. - 71 Pester tests pass (`RunTests.Tests.ps1`, `CopilotPipeline.Tests.ps1`).
|
/review run-tests |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🔵 Needs a closer look
The new API adds substantial native text rendering and gesture arbitration that require human validation, particularly for minimum-supported iOS, VoiceOver, and Windows paths lacking runtime evidence.
No open issues 🎉
3 resolved since last review
Review effort: Balanced
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Expert Review — 10 findings · ⚠️ 2 breaking changes
Reviewed commit c9c1189.
Warning
Existing apps would look or behave differently without opting in. See the Behavioral Change Disclosure findings at:
See inline comments for details.
…abled callbacks, avoid per-layout allocation - Windows: look up the current ViewMapper IsEnabled mapping at call time so appended callbacks still run - Android/Windows: leave selection the mapping did not enable alone while the property is unset - iOS: reuse an empty attributed string instead of allocating one per layout pass - Add Android and Windows device tests for these paths Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
| if (textView.IsTextSelectable == isSelectable) | ||
| { | ||
| return; |
|
/review expert-review |
…t before dismissing it Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A pointer tap on selectable text opens the selection flyout, which hides the page from UI automation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Note
This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.
This comment has been minimized.
This comment has been minimized.
…ed test (dotnet#40538) ### Description Two improvements to `/review run-tests` comments: **Outdated comments are minimized.** When `/review run-tests` runs again on a PR, the bot's earlier run-tests comments (and "unsupported" notices) are minimized as *Outdated* right after the new comment is posted. **Failed tests are precise and linked.** The results now show: - each failed test by its exact name, the platforms it failed on (each linked to that test result in Azure DevOps) and the first line of its error; - links to all test results (Tests tab) and the build logs; - failed jobs first, each linked to its log; - a status line that says, for example, "7 tests failed on Windows. See **Failed tests** below." The `maui-pr-uitests (selected run)` check summary gets the same test and job links. `testresults/resultsbybuild` returns wrong test titles for some results (in build 1694092 the same title appeared for 5 different tests), so the updater now reads each failed result (`test/Runs/{run}/results/{id}`, public) for its name, error and link. At most 60 results are read; the rest fall back to the summary data. ### Verified live - Minimized the older bot comment on dotnet#40482 with `Hide-RunTestsOutdatedComments`; GraphQL reports `isMinimized: true, minimizedReason: outdated`, and the newest comment stays visible. - Refreshed dotnet#40509 with `Update-RunTestsResults.ps1`; the comment now lists the 7 failing Windows `LabelIsTextSelectable*` tests with links and errors. - 71 Pester tests pass (`RunTests.Tests.ps1`, `CopilotPipeline.Tests.ps1`).
… as the second model (dotnet#40545) ### What Three PR-comment commands that run only the tests a PR can break: | Command | Pipeline | Runs | |---|---|---| | `/review run-tests` | both | UI and device tests together, reported in one comment with a section per suite | | `/review run-ui-tests` | maui-pr-uitests | AI-selected UI test categories and platforms | | `/review run-device-tests` | maui-pr-devicetests | AI-selected device test units (`Controls.<Category>`, `Core.<Category>`, `Graphics`, `Essentials`, `BlazorWebView`) and platforms, CoreCLR only | For `/review run-tests`, each model makes both selections in one pass (UI in `platforms`/`categories`/`full_run`, device in `device_*`). Both pipelines are dispatched, and the combined comment shows one section per suite; each section follows its own build. The results sweep updates sections independently, and a new `/review run-tests` comment minimizes earlier run-tests comments of either suite. Both commands use the same flow, comment and checks as today: two models select on their own, and the union of their selections runs. The models are now: 1. **GPT-6.2 Sol** (unchanged) 2. **MAI Code 2**, replacing Claude Opus 5.5 (`copilot-review-run-tests-opus` → `copilot-review-run-tests-mai`). The model policy test therefore no longer needs its Anthropic exception. ### Device tests - `eng/helix_xharness.proj`: a new `ApplyRunDeviceTestsSelection` target, active only when `RunDeviceTestsProjects` is set. - It drops the work items of unselected projects. - It passes `TestFilter=SkipCategories=...` to the test apps. On Android this goes through `--arg`; on iOS and Mac Catalyst through `--set-env`. - On iOS, it replaces the split Controls work items with one filtered item. - `eng/devices/run-windows-devicetests.cmd`: the category argument can be a `+`-separated list. - `ci-device-tests.yml` / `stage-device-tests.yml`: - `run-devicetests/*` dispatch branches carry the request (`run-devicetests-request.yml`); - a selected run builds only the selected platforms and skips the Mono stages. - The scripts get a suite profile (`Set-RunTestsSuite ui|device`) covering: - the command; - the pipeline and its definition id; - comment markers; - the dispatch branch prefix; - trusted overlay paths. The results sweep handles both kinds of comment. ### Also - `review-trigger.yml` and `ReviewCommandHelpers.ps1` now skip the new commands, so they no longer also start a full review. - When a PR has merge conflicts, the comment now says so plainly instead of "GitHub has no test-merge commit". ### Testing - Pester: `RunTests.Tests.ps1`, `CopilotPipeline.Tests.ps1` and `Recover-MissedReviewCommands.Tests.ps1`, 125 tests, all passing. - Trial device run for dotnet#40509, selecting `Controls.Label` + `Core.Label` on 4 platforms ([build 1695767](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1695767)): - only CoreCLR and Windows stages ran; - Helix received only the 2 selected work items per platform. - Android and Mac Catalyst then hit the 60-minute job timeout waiting on congested Helix queues. Regular runs hit the same timeout that day, for example [build 1695535](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1695535). - iOS passed, filtered: Controls 56 tests, Core 128 tests. - Windows ran `Core.DeviceTests` unfiltered (2193 tests). Fixed: `RunDeviceTestsCoreRun` now passes the category list to Core on Windows too, and `run-windows-devicetests.cmd` uses category runs whenever a filter is given. - Windows re-run after the fix ([build 1696018](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1696018)) passed. All 4 work items ran only `Label`: Core 75 tests, Controls 44 tests, packaged and unpackaged. - `/review run-tests` on the 20 latest PRs: - 8 dispatched; - 9 refused for real merge conflicts; - 1 had nothing to run; - 1 was refused because the PR was updated during selection; - 1 was refused because the PR was closed. - Local model check: GPT-6.2 Sol and MAI Code 2 each selected for dotnet#40509 (Label change) and dotnet#40530 (CollectionView layout change), for both suites, using the shared instructions. Then `Invoke-RunTests.ps1 -DryRun` validated and merged their picks: - dotnet#40509 UI: `Label`, `Gestures`, `Material3`. - dotnet#40509 device: `Controls.Label`, `Core.Label`, `Controls.Gesture`. - dotnet#40530: both models asked for a full run. - The gh-aw workflows only run from the default branch, so the live `/review run-ui-tests` / `/review run-device-tests` flow can be checked only after merge. --------- Co-authored-by: Copilot CI <copilot-ci@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Resolved the conflicts with |


Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
4e029d43adb10ea4888f1fcfdb32debc36ffe908↑ Android Core device tests pass on an emulator (new
IsTextSelectabletests included); the 7 iOS UI tests pass.↑ Windows verified on a Windows dev box: Core
LabelHandlerTests77 passed, 0 failed (includes new IsEnabled and mapper tests); 5 of 7LabelIsTextSelectable*UI tests passed, the 2 failures came from the Copy flyout, and the coordinate span test is now skipped on Windows.↑ CI
maui-pr-uitestsrun for this head (build 1699657) completed successfully, including the Windows Label job, so the Windows UI tests pass with the span test skipped.↓ TalkBack activation of a tap gesture on a selectable Android label is not routed (known limitation).
↓ The iOS overlay (
UITextViewinsideMauiLabel) is intricate; iOS 15, VoiceOver and RTL were not exercised at runtime.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!
Target Branch
mainDescription of Change
Adds a new bindable
Label.IsTextSelectableproperty (defaultfalse). Whentrue, the user can select the label's text and copy it using the platform's native selection UI. Today this needs a custom handler or a read-onlyEditor.API
Label.IsTextSelectable/Label.IsTextSelectableProperty(Controls).ILabel.IsTextSelectableas a default interface member (abstract only onnetstandard2.0), the same pattern asIRefreshView.IsRefreshEnabled, so custom handlers can participate. Mapped byLabelHandler.MapIsTextSelectable.Per platform
TextView.SetTextIsSelectable. It is only called on change, and the previous focusable mode, clickable, long-clickable and movement-method state is restored when turned off. Gestures on the label and on labels wrapped for Shadow/Clip still fire.TextBlock.IsTextSelectionEnabled(off while the label is disabled; Core's Windows label mapping refreshes it whenIsEnabledchanges). Tap and double-tap gestures are subscribed withhandledEventsToo, rebuilt when the property changes.UILabelhas no selection, soMauiLabelhosts an internal non-editableUITextView. TheUILabelkeeps measuring, so layout is unchanged. The overlay mirrors the attributed text, font/color fallbacks, alignment, flow direction, line limit and truncation, honors padding and vertical alignment, keeps HTML links inert as withUILabel, and passes touches on empty space through so label and span tap gestures still work (including with a Shadow/Clip wrapper).MauiLabel.PlatformViewtype is unchanged.Known platform limitations (documented in the XML remarks)
TextViewdoes not apply ellipsis truncation to selectable text and lays it out with a differentLayout(1–2 px deltas).TextViewis clickable, so TalkBack's activation sends a native click instead of the touch sequence; a tap gesture on a selectable label is not routed from it yet (follow-up).Not included, and can be added later without changing this property: programmatic selection (
SelectedText,SelectionChanged), custom menu actions and selection styling.Design alternatives considered (3 independent designs compared):
UITextView-backed type: breaksILabelHandler.PlatformView/LabelHandlerpublic API and ~16UILabelextensions.ILabelmember +UITextViewoverlay insideMauiLabel.Testing
Verified on iOS simulator (iOS 26.5), Android emulator (API 35) and Mac Catalyst (manually, because the Appium driver would not start): selection with handles and the Copy menu, copy-paste into an
Entry, layout parity with selection on vs off (padding, vertical/horizontal alignment, HTML, spans,MaxLines, truncation, RTL, styled text, disabled,CollectionViewcells), runtime toggling, and tap/long-press gestures, including Shadow-wrapped labels and enabling selection after gestures were attached.Re-validated after merging
mainand addressing review feedback:dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj(LC_ALL=en_US.UTF-8)dotnet test src/Core/tests/UnitTests/Core.UnitTests.csprojBuildAndRunHostApp.ps1 -Platform ios -TestFilter FullyQualifiedName~LabelIsTextSelectableBuildAndRunHostApp.ps1 -Platform android -TestFilter FullyQualifiedName~LabelIsTextSelectableIsTextSelectabletests pass (2 unrelated failures:SystemBarAppearanceDoesNotOverwriteDeveloperAppearance,Thumb Color Updates Correctly)dotnet buildControls.Core with-p:PublicApiType=Validate -p:TreatWarningsAsErrors=true(maccatalyst, android, net, netstandard2.0)Earlier runs (before the merge) also covered the iOS Core device tests, Mac Catalyst, and
Category=Labelon Android and iOS: only snapshot-baseline mismatches plus failures that also occur on the base commit (LabelShouldSizeProperlyOnCollectionViewon Android,Issue23801on iOS).Not verified: A pointer tap on selectable text opens the selection flyout on Windows, which hides the page from UI automation, so the coordinate span tap test is skipped there (the Windows UI run on this head passed in CI).
Controls.Xaml.UnitTestscould not be built locally after the merge (anx:Code requires EnablePreviewFeatureserror from files that arrived withmain). iOS 15 (the minimum), VoiceOver and the Controls device tests were not run.The change was reviewed by three models across two rounds; their findings (wrapper gestures, Windows runtime toggle, PublicAPI markers, focus restore, RTL, HTML links and others) are addressed, as is the later automated review feedback.
Issues Fixed
Relates to #29033 (an earlier report from a custom handler that applied
SetTextIsSelectable). This PR adds a built-in property for the same scenario.