Browse Source

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.
pull/14430/head
Steven Kirk 2 years ago
committed by GitHub
parent
commit
8e479e5df9
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs
  2. 23
      tests/Avalonia.Controls.UnitTests/Automation/ControlAutomationPeerTests.cs

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

@ -87,9 +87,11 @@ namespace Avalonia.Automation.Peers
foreach (var child in children)
{
if (child is Control c && c.IsVisible)
if (child is Control c)
{
result.Add(GetOrCreate(c));
var peer = GetOrCreate(c);
if (c.IsVisible)
result.Add(peer);
}
}

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

@ -102,7 +102,7 @@ namespace Avalonia.Controls.UnitTests.Automation
}
[Fact]
public void Updates_Children_When_Visibility_Changes()
public void Updates_Children_When_Visibility_Changes_From_Visible_To_Invisible()
{
var panel = new Panel
{
@ -126,6 +126,27 @@ namespace Avalonia.Controls.UnitTests.Automation
children = target.GetChildren();
Assert.Equal(2, children.Count);
}
[Fact]
public void Updates_Children_When_Visibility_Changes_From_Invisible_To_Visible()
{
var panel = new Panel
{
Children =
{
new Border(),
new Border { IsVisible = false },
},
};
var target = CreatePeer(panel);
var children = target.GetChildren();
Assert.Equal(1, children.Count);
panel.Children[1].IsVisible = true;
children = target.GetChildren();
Assert.Equal(2, children.Count);
}
}
public class Parent

Loading…
Cancel
Save