Keep track of selected TabItem for focus#8300
Merged
Merged
Conversation
ff1bd78 to
3abaf72
Compare
3abaf72 to
2bf59ad
Compare
anjaligupta-dev
approved these changes
Jun 6, 2024
anjaligupta-dev
left a comment
There was a problem hiding this comment.
LGTM, thanks for your contribution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8293
Description
When a
TabItemis selected inTabControl, it sets focus to its content (unless theTabItemitself is focused). If the content gets succesfully focused, then theTabItemsupresses receiving focus to not steal it from the content back.When the content is a
Buttonin its own focus scope (such as in aToolBar), theButtonwill try to switch back to the main focus scope after pressed (on losing mouse capture).Finally, when a
TabItemis focused, theTabControlwill switch to that tab.As a result, if a
TabItemcontainsToolBarwith aButton, thatButtonwill try to re-focus the previously focused element. However, if theTabItemsuppressed receiving focus, then the previously selected tab will still be remembered as the last focused element, and re-focusing it will select it and thus unexpectedly change the displayed tab.Customer Impact
Customers not taking this fix will experience undesirable UI behaviour with buttons in their own focus scope inside a
TabItem. By default that is only the case for buttons insideToolBar, although developers can change that.Workarounds of the original issue exist, as described in #8293 (comment)
Regression
No. Well technically the
Switch.System.Windows.Controls.TabControl.SelectionPropertiesCanLagBehindSelectionChangedEventcompatibility switch introduced this issue in .NET 4.7.1. Before that, theTabItemwould not opt out of receiving focus, so this issue did not happen, but there were even worse problems.Testing
Compiled and tested with the repro app in #8293 on .NET 8.0.100-preview.7.23376.3. Verified the issue repros without the fix and does not repro after the fix.
Risk
This is potentially a higher impact change (focusing behaviour changes) and there is a lot of corner cases that might be difficult to pick up. To minimize the risk as much as possible, the new behavior is executed in a very specific case only:
The focused element is another tab item of the same control.(in that case the code does not run, so issue does not exist)Microsoft Reviewers: Open in CodeFlow