Skip to content

Fix ToggleSwitch knob touching track boundary during drag - #11659

Open
Rashmi Thakur (rashmi-thakurr) wants to merge 2 commits into
mainfrom
fix/toggleswitch-knob-drag-margin
Open

Fix ToggleSwitch knob touching track boundary during drag#11659
Rashmi Thakur (rashmi-thakurr) wants to merge 2 commits into
mainfrom
fix/toggleswitch-knob-drag-margin

Conversation

@rashmi-thakurr

@rashmi-thakurr Rashmi Thakur (rashmi-thakurr) commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Fixes

Fixes #10822

PR Type

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Description

Current Behavior

While dragging a ToggleSwitch, the expanded pressed knob can touch the track boundary at the hard drag endpoint. The behavior is especially visible when the switch starts in the On state and is dragged toward Off.

New Behavior

The visible knob preserves its resting inset from the track boundary throughout a drag, including at both hard endpoints and regardless of whether the switch starts On or Off.

The drag logic now measures the visible state-specific knob (SwitchKnobOff or SwitchKnobOn) in the SwitchKnob container coordinate space and applies separate visual-only clamp bounds. The logical translation bounds, toggle thresholds, animation offsets, and state transitions remain unchanged. Custom templates without the optional visual parts retain the previous behavior.

A regression test performs oversized drags in both directions and verifies the visible knob geometry rather than only the knob container geometry.

Customer Impact

This fixes a user-visible graphical issue where the ToggleSwitch knob could appear flush against or overlap the track boundary while the pointer remained held during a drag.

Regression Potential

  • Low risk — isolated change, limited scope
  • Medium risk — touches shared components or public APIs
  • High risk — architectural or breaking API change

The adjustment is isolated to ToggleSwitch drag-time visual clamping. It does not change public APIs or the logical values used to determine toggle state.

How Has This Been Tested?

  • I have performed a self-review of my own code
  • I have added tests to cover my changes
  • Existing tests pass locally

Validation completed:

  • Built Microsoft.ui.xaml.vcxproj for x64 CHK.
  • Built Microsoft.UI.Xaml.Tests.External.Controls.vcxproj for x64 CHK.
  • Passed KnobMaintainsMarginsFromTrackDuringDrag for initially-Off and initially-On hard drag endpoints.
  • Passed the existing CanDragHorizontallyOverToggleSwitchToSelect mouse-drag test.
  • Manually verified initially-Off and initially-On drag-and-hold behavior in MUXControlsTestApp.
  • Confirmed the unrelated synthetic touch/tap failures reproduce on a clean main baseline in the same environment.

Screenshots (if appropriate)

Before

20251006-2254-06.9878498.mp4

After

togglebutton-fix.mp4

Rashmi Thakur and others added 2 commits August 26, 2026 13:24
Keep the expanded pressed knob within the track during drag without changing the translation range used for toggle behavior and animations. Add integration coverage for both Off and On drag directions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 52fc8e81-8915-40ba-9160-2826b6a549e7
Measure the visible knob inset in the knob container's coordinate space and strengthen the boundary regression with full-range drags.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 52fc8e81-8915-40ba-9160-2826b6a549e7
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the needs-triage Issue needs to be triaged by the area owners label Aug 26, 2026
@rashmi-thakurr
Rashmi Thakur (rashmi-thakurr) marked this pull request as ready for review August 26, 2026 14:26
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-triage Issue needs to be triaged by the area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Toggles slide too far graphical bug

1 participant