Skip to content

Commit 6637a9d

Browse files
committed
Fix controls not showing up in accessibility when made visibile (#14424)
* Add failing test for control visibility changing. There was already a test for when visibility moves from visible to invisible but we were missing one for the other way around. * Create peer even for invisible controls. When an invisible control is encountered, unless a peer is created for it, there is nothing to listen for the `IsVisible` property changing to `true`. Make sure we create a peer even for invisible controls; we just don't add them to the child collection.
1 parent b3a8ba2 commit 6637a9d

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ protected override IReadOnlyList<AutomationPeer> GetOrCreateChildrenCore()
8787

8888
foreach (var child in children)
8989
{
90-
if (child is Control c && c.IsVisible)
90+
if (child is Control c)
9191
{
92-
result.Add(GetOrCreate(c));
92+
var peer = GetOrCreate(c);
93+
if (c.IsVisible)
94+
result.Add(peer);
9395
}
9496
}
9597

tests/Avalonia.Controls.UnitTests/Automation/ControlAutomationPeerTests.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void Updates_Children_When_VisualChildren_Removed()
106106
}
107107

108108
[Fact]
109-
public void Updates_Children_When_Visibility_Changes()
109+
public void Updates_Children_When_Visibility_Changes_From_Visible_To_Invisible()
110110
{
111111
var panel = new Panel
112112
{
@@ -130,6 +130,27 @@ public void Updates_Children_When_Visibility_Changes()
130130
children = target.GetChildren();
131131
Assert.Equal(2, children.Count);
132132
}
133+
134+
[Fact]
135+
public void Updates_Children_When_Visibility_Changes_From_Invisible_To_Visible()
136+
{
137+
var panel = new Panel
138+
{
139+
Children =
140+
{
141+
new Border(),
142+
new Border { IsVisible = false },
143+
},
144+
};
145+
146+
var target = CreatePeer(panel);
147+
var children = target.GetChildren();
148+
Assert.Equal(1, children.Count);
149+
150+
panel.Children[1].IsVisible = true;
151+
children = target.GetChildren();
152+
Assert.Equal(2, children.Count);
153+
}
133154
}
134155

135156
public class Parent

0 commit comments

Comments
 (0)