Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TabView: Fix all tabs squeezed into viewport when last tab is closed #3955

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion dev/TabView/InteractionTests/TabViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ public void VerifySizingBehaviorOnTabCloseComingFromNonScroll()
Wait.ForIdle();

Log.Comment("Verify correct TabView width");
Verify.IsTrue(Math.Abs(GetActualTabViewWidth() - 500) < pixelTolerance);
Verify.IsTrue(Math.Abs(GetActualTabViewWidth() - 283) < pixelTolerance);
}

void CloseTabAndVerifyWidth(string tabName, int expectedValue, string expectedScrollbuttonStates)
Expand All @@ -804,6 +804,44 @@ double GetActualTabViewWidth()
}
}

[TestMethod]
public void VerifyHeaderSizeWhenClosingLastTab()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VerifyHeaderSizeWhenClosingLastTab [](start = 20, length = 34)

Does this test fail without your change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the TabViewItem Width gets set to ~79 without the fix (because all tabs are compressed into the visible viewport)

{
using (var setup = new TestSetupHelper(new[] { "TabView Tests", "TabViewTabClosingBehaviorButton" }))
{
var increaseScrollButton = FindElement.ByName<Button>("IncreaseScrollButton");
increaseScrollButton.Click();
Wait.ForIdle();
var readTabViewWidthButton = new Button(FindElement.ByName("GetActualWidthButton"));
readTabViewWidthButton.Click();
Wait.ForIdle();

var initialWidth = GetTabViewHeaderWidth();
Verify.AreEqual(100, initialWidth);

var lastTab = FindElement.ByName("Tab 5");
FindCloseButton(lastTab).Click();
Wait.ForIdle();

var widthAfterClose = GetTabViewHeaderWidth();
Verify.AreEqual(100, widthAfterClose);
Verify.AreEqual("False;True;", FindElement.ByName("ScrollButtonStatus").GetText());

var newLastTab = FindElement.ByName("Tab 4");
FindCloseButton(newLastTab).Click();
Wait.ForIdle();

var widthAfterSecondClose = GetTabViewHeaderWidth();
Verify.AreEqual(100, widthAfterSecondClose);

double GetTabViewHeaderWidth()
{
var tabViewHeaderWidth = new TextBlock(FindElement.ByName("TabViewHeaderWidth"));
return double.Parse(tabViewHeaderWidth.GetText());
}
}
}

public void PressButtonAndVerifyText(String buttonName, String textBlockName, String expectedText)
{
Button button = FindElement.ByName<Button>(buttonName);
Expand Down
3 changes: 2 additions & 1 deletion dev/TabView/TabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,8 @@ void TabView::UpdateTabWidths(bool shouldUpdateWidths,bool fillAllAvailableSpace
}

// Use current size to update items to fill the currently occupied space
tabWidth = availableTabViewSpace / (double)(TabItems().Size());
auto const tabWidthUnclamped = availableTabViewSpace / (double)(TabItems().Size());
tabWidth = std::clamp(tabWidthUnclamped, minTabWidth, maxTabWidth);
}


Expand Down
7 changes: 6 additions & 1 deletion dev/TabView/TestUI/TabViewTabClosingBehaviorPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<muxc:TabViewItem Header="Tab 0" AutomationProperties.Name="Tab 0"/>
<muxc:TabViewItem Header="Tab 1" AutomationProperties.Name="Tab 1"/>
<muxc:TabViewItem Header="Tab 2" AutomationProperties.Name="Tab 2"/>
<muxc:TabViewItem Header="Tab 3" AutomationProperties.Name="Tab 3"/>
<muxc:TabViewItem Header="Tab 3" x:Name="Tab3" AutomationProperties.Name="Tab 3"/>
<muxc:TabViewItem Header="Tab 4" AutomationProperties.Name="Tab 4"/>
<muxc:TabViewItem Header="Tab 5" AutomationProperties.Name="Tab 5"/>
</muxc:TabView>
Expand All @@ -33,11 +33,16 @@
<TextBlock x:Name="TabViewWidth" AutomationProperties.Name="TabViewWidth"/>
<TextBlock Text="Scroll buttons status"/>
<TextBlock x:Name="ScrollButtonStatus" AutomationProperties.Name="ScrollButtonStatus" />
<TextBlock Text="Header Width"/>
<TextBlock x:Name="TabViewHeaderWidth" AutomationProperties.Name="TabViewHeaderWidth"/>
</StackPanel>
<StackPanel>
<Button AutomationProperties.Name="GetActualWidthButton"
Click="GetActualWidthsButton_Click"
Content="Get actual TabView width"/>
<Button AutomationProperties.Name="IncreaseScrollButton"
Click="IncreaseScrollButton_Click"
Content="Increase scroll" />
</StackPanel>
</StackPanel>
</Grid>
Expand Down
10 changes: 10 additions & 0 deletions dev/TabView/TestUI/TabViewTabClosingBehaviorPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private void TabViewTabCloseRequested(object sender, Microsoft.UI.Xaml.Controls.
Tabs.TabItems.Remove(e.Tab);

TabViewWidth.Text = Tabs.ActualWidth.ToString();
TabViewHeaderWidth.Text = Tab3.Width.ToString();

var scrollButtonStateValue = "";

Expand All @@ -66,6 +67,15 @@ public void GetActualWidthsButton_Click(object sender, RoutedEventArgs e)
{
// This is the smallest width that fits our content without any scrolling.
TabViewWidth.Text = Tabs.ActualWidth.ToString();

// Header width
TabViewHeaderWidth.Text = Tab3.Width.ToString();
}

public void IncreaseScrollButton_Click(object sender, RoutedEventArgs e)
{
var sv = VisualTreeUtils.FindVisualChildByName(Tabs, "ScrollViewer") as ScrollViewer;
sv.ChangeView(10000, null, null, disableAnimation: true);
}

}
Expand Down