Merge pull request #535 from irihitech/534-form
Fix Form A11y for dynamic generated FormItems.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<UserControl
|
||||
x:Class="HeadlessTest.Ursa.Controls.FormTests.AccessibilityTests.DynamicForm"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:accessibilityTests="clr-namespace:HeadlessTest.Ursa.Controls.FormTests.AccessibilityTests"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
x:CompileBindings="True"
|
||||
x:DataType="accessibilityTests:DynamicFormViewModel"
|
||||
mc:Ignorable="d">
|
||||
<u:Form Name="form" ItemsSource="{Binding Items}">
|
||||
<u:Form.Styles>
|
||||
<Style x:DataType="accessibilityTests:FormTextViewModel" Selector="u|FormItem">
|
||||
<Setter Property="Label" Value="{Binding Label}" />
|
||||
</Style>
|
||||
</u:Form.Styles>
|
||||
<u:Form.ItemTemplate>
|
||||
<DataTemplate DataType="accessibilityTests:FormTextViewModel">
|
||||
<TextBox Text="{Binding Value}" />
|
||||
</DataTemplate>
|
||||
</u:Form.ItemTemplate>
|
||||
</u:Form>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace HeadlessTest.Ursa.Controls.FormTests.AccessibilityTests;
|
||||
|
||||
public partial class DynamicForm : UserControl
|
||||
{
|
||||
public DynamicForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.DataContext = new DynamicFormViewModel();
|
||||
}
|
||||
}
|
||||
|
||||
public partial class DynamicFormViewModel: ObservableObject
|
||||
{
|
||||
public ObservableCollection<FormTextViewModel> Items { get; set; } =
|
||||
[
|
||||
new() { Label = "_Name" },
|
||||
new() { Label = "_Email" }
|
||||
];
|
||||
}
|
||||
|
||||
public partial class FormTextViewModel : ObservableObject
|
||||
{
|
||||
[ObservableProperty] private string? _label;
|
||||
[ObservableProperty] private string? _value;
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Headless;
|
||||
using Avalonia.Headless.XUnit;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.LogicalTree;
|
||||
using Ursa.Controls;
|
||||
|
||||
namespace HeadlessTest.Ursa.Controls.FormTests.AccessibilityTests;
|
||||
|
||||
public class FormAccessibilityTests
|
||||
{
|
||||
[AvaloniaFact]
|
||||
public void Static_Form_Inner_Control_Accessible()
|
||||
{
|
||||
var window = new Window();
|
||||
var form = new StaticForm();
|
||||
window.Content = form;
|
||||
window.Show();
|
||||
|
||||
Assert.False(form.NameBox.IsFocused);
|
||||
Assert.False(form.EmailBox.IsFocused);
|
||||
window.KeyPressQwerty(PhysicalKey.N, RawInputModifiers.Alt);
|
||||
Assert.True(form.NameBox.IsFocused);
|
||||
Assert.False(form.EmailBox.IsFocused);
|
||||
window.KeyPressQwerty(PhysicalKey.E, RawInputModifiers.Alt);
|
||||
Assert.False(form.NameBox.IsFocused);
|
||||
Assert.True(form.EmailBox.IsFocused);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void Static_Form_With_FormItem_Accessible()
|
||||
{
|
||||
var window = new Window();
|
||||
var form = new StaticForm2();
|
||||
window.Content = form;
|
||||
window.Show();
|
||||
|
||||
Assert.False(form.NameBox.IsFocused);
|
||||
Assert.False(form.EmailBox.IsFocused);
|
||||
window.KeyPressQwerty(PhysicalKey.N, RawInputModifiers.Alt);
|
||||
Assert.True(form.NameBox.IsFocused);
|
||||
Assert.False(form.EmailBox.IsFocused);
|
||||
window.KeyPressQwerty(PhysicalKey.E, RawInputModifiers.Alt);
|
||||
Assert.False(form.NameBox.IsFocused);
|
||||
Assert.True(form.EmailBox.IsFocused);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void Dynamic_Form_Inner_Control_Accessible()
|
||||
{
|
||||
var window = new Window();
|
||||
var form = new DynamicForm();
|
||||
window.Content = form;
|
||||
window.Show();
|
||||
|
||||
var logicalChildren = form.form.GetLogicalChildren().ToList();
|
||||
Assert.Equal(2, logicalChildren.Count);
|
||||
var first = logicalChildren[0] as FormItem;
|
||||
var second = logicalChildren[1] as FormItem;
|
||||
Assert.NotNull(first);
|
||||
Assert.NotNull(second);
|
||||
|
||||
var text1 = first.GetLogicalChildren().OfType<TextBox>().FirstOrDefault();
|
||||
var text2 = second.GetLogicalChildren().OfType<TextBox>().FirstOrDefault();
|
||||
|
||||
Assert.NotNull(text1);
|
||||
Assert.NotNull(text2);
|
||||
|
||||
Assert.False(text1.IsFocused);
|
||||
Assert.False(text2.IsFocused);
|
||||
window.KeyPressQwerty(PhysicalKey.N, RawInputModifiers.Alt);
|
||||
Assert.True(text1.IsFocused);
|
||||
Assert.False(text2.IsFocused);
|
||||
window.KeyPressQwerty(PhysicalKey.E, RawInputModifiers.Alt);
|
||||
Assert.False(text1.IsFocused);
|
||||
Assert.True(text2.IsFocused);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
mc:Ignorable="d" d:DesignWidth="800"
|
||||
d:DesignHeight="450"
|
||||
x:Class="HeadlessTest.Ursa.Controls.FormTests.AccessibilityTests.StaticForm">
|
||||
<u:Form LabelWidth="200" LabelPosition="Left" LabelAlignment="Left">
|
||||
<TextBox Name="NameBox" Width="300" u:FormItem.Label="_Name" />
|
||||
<TextBox Name="EmailBox" Width="300" u:FormItem.Label="_Email" />
|
||||
</u:Form>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,13 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace HeadlessTest.Ursa.Controls.FormTests.AccessibilityTests;
|
||||
|
||||
public partial class StaticForm : UserControl
|
||||
{
|
||||
public StaticForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
mc:Ignorable="d" d:DesignWidth="800"
|
||||
d:DesignHeight="450"
|
||||
x:Class="HeadlessTest.Ursa.Controls.FormTests.AccessibilityTests.StaticForm2">
|
||||
<u:Form LabelWidth="200" LabelPosition="Left" LabelAlignment="Left">
|
||||
<u:FormItem Label="_Name">
|
||||
<TextBox Name="NameBox" Width="300" />
|
||||
</u:FormItem>
|
||||
<u:FormItem Label="_Email">
|
||||
<TextBox Name="EmailBox" Width="300" />
|
||||
</u:FormItem>
|
||||
</u:Form>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,13 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace HeadlessTest.Ursa.Controls.FormTests.AccessibilityTests;
|
||||
|
||||
public partial class StaticForm2 : UserControl
|
||||
{
|
||||
public StaticForm2()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user