Skip to content

Commit 6fcf1dd

Browse files
committed
fix(ItemsRepeater): FindFocusCandidate did not return focused child
1 parent 9bda7e9 commit 6fcf1dd

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

src/Uno.UI.RuntimeTests/MUX/Microsoft_UI_Xaml_Controls/Repeater/RepeaterTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ public void NestedRepeaterWithDataTemplateScenario()
309309
}
310310

311311
[TestMethod]
312-
// TODO: MZ fails
313312
public void VerifyFocusedItemIsRecycledOnCollectionReset()
314313
{
315314
List<Layout> layouts = new List<Layout>();

src/Uno.UI/Microsoft/UI/Xaml/Controls/Repeater/ViewManager.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public void ClearElementToElementFactory(UIElement element)
216216
void MoveFocusFromClearedIndex(int clearedIndex)
217217
{
218218
UIElement focusedChild = null;
219-
var focusCandidate = FindFocusCandidate(clearedIndex, focusedChild);
219+
var focusCandidate = FindFocusCandidate(clearedIndex, out focusedChild);
220220
if (focusCandidate != null)
221221
{
222222
FocusState focusState = FocusState.Programmatic;
@@ -240,7 +240,7 @@ void MoveFocusFromClearedIndex(int clearedIndex)
240240
}
241241
}
242242

243-
Control FindFocusCandidate(int clearedIndex, UIElement focusedChild)
243+
Control FindFocusCandidate(int clearedIndex, out UIElement focusedChild)
244244
{
245245
// Walk through all the children and find elements with index before and after the cleared index.
246246
// Note that during a delete the next element would now have the same index.
@@ -280,9 +280,10 @@ Control FindFocusCandidate(int clearedIndex, UIElement focusedChild)
280280
// Find the next element if one exists, if not use the previous element.
281281
// If the container itself is not focusable, find a descendent that is.
282282
Control focusCandidate = null;
283+
focusedChild = null;
283284
if (nextElement != null)
284285
{
285-
//focusedChild = nextElement as UIElement;
286+
focusedChild = nextElement as UIElement;
286287
focusCandidate = nextElement as Control;
287288
if (focusCandidate == null)
288289
{
@@ -294,20 +295,19 @@ Control FindFocusCandidate(int clearedIndex, UIElement focusedChild)
294295
}
295296
}
296297

297-
// TODO UNO: Case declared as useless by intellisense
298-
//if (focusCandidate == null && previousElement != null)
299-
//{
300-
// focusedChild = previousElement as UIElement;
301-
// focusCandidate = previousElement as Control;
302-
// if (previousElement == null)
303-
// {
304-
// var lastFocus = FocusManager.FindLastFocusableElement(previousElement);
305-
// if (lastFocus != null)
306-
// {
307-
// focusCandidate = lastFocus as Control;
308-
// }
309-
// }
310-
//}
298+
if (focusCandidate == null && previousElement != null)
299+
{
300+
focusedChild = previousElement as UIElement;
301+
focusCandidate = previousElement as Control;
302+
if (previousElement == null)
303+
{
304+
var lastFocus = FocusManager.FindLastFocusableElement(previousElement);
305+
if (lastFocus != null)
306+
{
307+
focusCandidate = lastFocus as Control;
308+
}
309+
}
310+
}
311311

312312
return focusCandidate;
313313
}

0 commit comments

Comments
 (0)