Skip to content

Commit

Permalink
Tabs focus logic with Visible=false tabs fixed
Browse files Browse the repository at this point in the history
Fix #1722
  • Loading branch information
enchev committed Oct 3, 2024
1 parent f0f94eb commit 167bfcb
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Radzen.Blazor/RadzenTabs.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,25 +280,27 @@ async Task OnKeyPress(KeyboardEventArgs args)
{
var key = args.Code != null ? args.Code : args.Key;

var item = tabs.ElementAtOrDefault(focusedIndex) ?? tabs[0];

if (key == "ArrowLeft" || key == "ArrowRight")
{
preventKeyPress = true;

focusedIndex = Math.Clamp(focusedIndex + (key == "ArrowLeft" ? -1 : 1), 0, tabs.Where(t => t.Visible).Count() - 1);
focusedIndex = Math.Clamp(focusedIndex + (key == "ArrowLeft" ? -1 : 1), 0, tabs.Where(t => HasInvisibleBefore(item) ? true : t.Visible).Count() - 1);
}
else if (key == "Home" || key == "End")
{
preventKeyPress = true;

focusedIndex = key == "Home" ? 0 : tabs.Where(t => t.Visible).Count() - 1;
focusedIndex = key == "Home" ? 0 : tabs.Where(t => HasInvisibleBefore(item) ? true : t.Visible).Count() - 1;
}
else if (key == "Space" || key == "Enter")
{
preventKeyPress = true;

if (focusedIndex >= 0 && focusedIndex < tabs.Where(t => t.Visible).Count())
if (focusedIndex >= 0 && focusedIndex < tabs.Where(t => HasInvisibleBefore(item) ? true : t.Visible).Count())
{
await tabs.Where(t => t.Visible).ToList()[focusedIndex].OnClick();
await tabs.Where(t => HasInvisibleBefore(item) ? true : t.Visible).ToList()[focusedIndex].OnClick();
}
}
else
Expand All @@ -308,7 +310,12 @@ async Task OnKeyPress(KeyboardEventArgs args)
}
internal bool IsFocused(RadzenTabsItem item)
{
return tabs.Where(t => t.Visible).ToList().IndexOf(item) == focusedIndex && focusedIndex != -1;
return tabs.Where(t => HasInvisibleBefore(item) ? true : t.Visible).ToList().IndexOf(item) == focusedIndex && focusedIndex != -1;
}

internal bool HasInvisibleBefore(RadzenTabsItem item)
{
return tabs.Take(tabs.IndexOf(item)).Any(t => !t.Visible);
}
}
}

0 comments on commit 167bfcb

Please sign in to comment.