Skip to content

Commit 0ad5d3a

Browse files
zdpcdtCopilot
andauthored
fix: the colon should invisible when ItemsAlignmen=Plain. (#884)
* fix: the colon should invisible when ItemsAlignmen=Plain. * test: add HeadlessTest for colon visibility in DescriptionsItem Plain mode (#885) * Initial plan * test: add HeadlessTest for colon visibility in Plain mode Co-authored-by: zdpcdt <54255897+zdpcdt@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: zdpcdt <54255897+zdpcdt@users.noreply.github.com> --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
1 parent 4d5d105 commit 0ad5d3a

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

src/Ursa.Themes.Semi/Controls/Descriptions.axaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@
103103
<Setter Property="HorizontalAlignment" Value="Right" />
104104
</Style>
105105
</Style>
106+
<Style Selector="^[ItemAlignment=Plain]">
107+
<Style Selector="^ /template/ TextBlock#PART_Colon">
108+
<Setter Property="IsVisible" Value="{TemplateBinding Label, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" />
109+
</Style>
110+
</Style>
106111
</Style>
107112
<Style Selector="^:vertical">
108113
<Setter Property="iri:ClassHelper.ClassSource" Value="{Binding $parent[u:Descriptions]}" />

tests/HeadlessTest.Ursa/Controls/DescriptionTests/Test.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using Avalonia.Controls;
2+
using Avalonia.Controls.Primitives;
23
using Avalonia.Data;
34
using Avalonia.Headless.XUnit;
45
using Avalonia.LogicalTree;
6+
using Avalonia.Threading;
7+
using HeadlessTest.Ursa.TestHelpers;
58
using Ursa.Common;
69
using Ursa.Controls;
710

@@ -180,4 +183,80 @@ public void Descriptions_LabelWidth_Propagates_To_DescriptionItems()
180183
Assert.Equal(150, item.LabelWidth);
181184
}
182185
}
186+
187+
[AvaloniaFact]
188+
public void DescriptionItem_Colon_Visibility_When_ItemAlignment_Is_Plain()
189+
{
190+
// Test case 1: ItemAlignment=Plain with non-empty Label - colon should be visible
191+
var itemWithLabel = new DescriptionsItem
192+
{
193+
Label = "Name",
194+
Content = "John Doe",
195+
ItemAlignment = ItemAlignment.Plain,
196+
LabelPosition = Position.Left
197+
};
198+
var window1 = new Window { Content = itemWithLabel };
199+
window1.Show();
200+
Dispatcher.UIThread.RunJobs();
201+
202+
var colon1 = itemWithLabel.GetTemplateChildOfType<TextBlock>("PART_Colon");
203+
Assert.NotNull(colon1);
204+
Assert.True(colon1.IsVisible, "Colon should be visible when ItemAlignment=Plain and Label is not empty");
205+
206+
window1.Close();
207+
208+
// Test case 2: ItemAlignment=Plain with null Label - colon should be hidden
209+
var itemWithoutLabel = new DescriptionsItem
210+
{
211+
Label = null,
212+
Content = "John Doe",
213+
ItemAlignment = ItemAlignment.Plain,
214+
LabelPosition = Position.Left
215+
};
216+
var window2 = new Window { Content = itemWithoutLabel };
217+
window2.Show();
218+
Dispatcher.UIThread.RunJobs();
219+
220+
var colon2 = itemWithoutLabel.GetTemplateChildOfType<TextBlock>("PART_Colon");
221+
Assert.NotNull(colon2);
222+
Assert.False(colon2.IsVisible, "Colon should be hidden when ItemAlignment=Plain and Label is null");
223+
224+
window2.Close();
225+
226+
// Test case 3: ItemAlignment=Plain with empty string Label - colon should be hidden
227+
var itemWithEmptyLabel = new DescriptionsItem
228+
{
229+
Label = string.Empty,
230+
Content = "John Doe",
231+
ItemAlignment = ItemAlignment.Plain,
232+
LabelPosition = Position.Left
233+
};
234+
var window3 = new Window { Content = itemWithEmptyLabel };
235+
window3.Show();
236+
Dispatcher.UIThread.RunJobs();
237+
238+
var colon3 = itemWithEmptyLabel.GetTemplateChildOfType<TextBlock>("PART_Colon");
239+
Assert.NotNull(colon3);
240+
Assert.False(colon3.IsVisible, "Colon should be hidden when ItemAlignment=Plain and Label is empty string");
241+
242+
window3.Close();
243+
244+
// Test case 4: ItemAlignment=Center with Label - colon should be hidden (per existing style)
245+
var itemWithCenterAlignment = new DescriptionsItem
246+
{
247+
Label = "Age",
248+
Content = "30",
249+
ItemAlignment = ItemAlignment.Center,
250+
LabelPosition = Position.Left
251+
};
252+
var window4 = new Window { Content = itemWithCenterAlignment };
253+
window4.Show();
254+
Dispatcher.UIThread.RunJobs();
255+
256+
var colon4 = itemWithCenterAlignment.GetTemplateChildOfType<TextBlock>("PART_Colon");
257+
Assert.NotNull(colon4);
258+
Assert.False(colon4.IsVisible, "Colon should be hidden when ItemAlignment=Center (regardless of Label)");
259+
260+
window4.Close();
261+
}
183262
}

0 commit comments

Comments
 (0)