Updates to FormItem label and A11y (#395)

* feat: 1. add AccessKey support for form item.
2. Support label positioning for different content height.
3. polish demo.

* feat: add a transparent background for label.
This commit is contained in:
Dong Bin
2024-09-11 18:47:42 +08:00
committed by GitHub
parent eb72a717c3
commit 60605de2c8
4 changed files with 146 additions and 68 deletions

View File

@@ -0,0 +1,36 @@
using System.Globalization;
using Avalonia.Controls;
using Avalonia.Data.Converters;
using Avalonia.Layout;
namespace Ursa.Themes.Semi.Converters;
public class FormContentHeightToAlignmentConverter: IValueConverter
{
public static FormContentHeightToAlignmentConverter Instance = new(32);
public double Threshold { get; set; }
public FormContentHeightToAlignmentConverter()
{
Threshold = 32;
}
// ReSharper disable once ConvertToPrimaryConstructor
// Justification: need to keep the default constructor for XAML
public FormContentHeightToAlignmentConverter(double threshold)
{
Threshold = threshold;
}
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if(value is not double d) return VerticalAlignment.Center;
return d > Threshold ? VerticalAlignment.Top : VerticalAlignment.Center;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

View File

@@ -0,0 +1,34 @@
using System.Globalization;
using Avalonia;
using Avalonia.Data.Converters;
namespace Ursa.Themes.Semi.Converters;
public class FormContentHeightToMarginConverter: IValueConverter
{
public static FormContentHeightToMarginConverter Instance = new();
public double Threshold { get; set; }
public FormContentHeightToMarginConverter()
{
Threshold = 32;
}
// ReSharper disable once ConvertToPrimaryConstructor
// Justification: need to keep the default constructor for XAML
public FormContentHeightToMarginConverter(double threshold)
{
Threshold = threshold;
}
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if(value is not double d) return new Thickness(0);
return d > Threshold ? new Thickness(0, 8, 8, 0) : new Thickness(0, 0, 8, 0);
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}