diff --git a/src/Titano.App/Sections/AboutView.xaml b/src/Titano.App/Sections/AboutView.xaml index ac29b3b4..9f2c3b37 100644 --- a/src/Titano.App/Sections/AboutView.xaml +++ b/src/Titano.App/Sections/AboutView.xaml @@ -9,8 +9,7 @@ - - + diff --git a/src/Titano.App/Sections/WelcomeView.xaml b/src/Titano.App/Sections/WelcomeView.xaml index 281180ee..f19a4725 100644 --- a/src/Titano.App/Sections/WelcomeView.xaml +++ b/src/Titano.App/Sections/WelcomeView.xaml @@ -55,7 +55,7 @@ - + diff --git a/src/Titano.App/Shell/LoginDialog.xaml.cs b/src/Titano.App/Shell/LoginDialog.xaml.cs index 2447e2c3..b0adb296 100644 --- a/src/Titano.App/Shell/LoginDialog.xaml.cs +++ b/src/Titano.App/Shell/LoginDialog.xaml.cs @@ -8,7 +8,8 @@ namespace Titano.App.Shell; /// /// The login form (BRIEF §12.7). It calls back the connection with the credentials and stays open with the /// error sentence until the sign-in succeeds or the user cancels. The password never leaves the PasswordBox -/// except for that call. A failed sign-in is announced to screen readers and stays as the password box's help text. +/// except for that call. A failed sign-in is announced to screen readers and marks the password box (error border, +/// sentence as its help text) until the next attempt. /// public sealed partial class LoginDialog : TitanoWindow { @@ -42,7 +43,7 @@ public sealed partial class LoginDialog : TitanoWindow { SignIn.IsEnabled = false; Error.Visibility = Visibility.Collapsed; - AutomationProperties.SetHelpText(Password, string.Empty); + Field.SetError(Password, null); try { var error = await _signIn(User.Text, Password.Password); @@ -53,7 +54,7 @@ public sealed partial class LoginDialog : TitanoWindow } Error.Text = error; Error.Visibility = Visibility.Visible; - AutomationProperties.SetHelpText(Password, error); + Field.SetError(Password, error); Password.Clear(); Password.Focus(); UIElementAutomationPeer.CreatePeerForElement(this)?.RaiseNotificationEvent( diff --git a/src/Titano.Setup/Views/SetupWindow.xaml b/src/Titano.Setup/Views/SetupWindow.xaml index e7a794fb..d5793e6a 100644 --- a/src/Titano.Setup/Views/SetupWindow.xaml +++ b/src/Titano.Setup/Views/SetupWindow.xaml @@ -18,8 +18,7 @@ - - + diff --git a/src/Titano.Ui/Controls/Field.cs b/src/Titano.Ui/Controls/Field.cs index 98477d1e..befa93b6 100644 --- a/src/Titano.Ui/Controls/Field.cs +++ b/src/Titano.Ui/Controls/Field.cs @@ -2,7 +2,10 @@ using System.Windows; namespace Titano.Ui.Controls; -/// Attached field helpers: placeholder text and an inline leading icon for text inputs. +/// +/// Attached field helpers: placeholder text and an inline leading icon for text inputs, and the error of an input that +/// has no validating binding (a password box): the error border, with the message as help text for screen readers. +/// public static class Field { public static readonly DependencyProperty PlaceholderProperty = DependencyProperty.RegisterAttached( @@ -11,6 +14,16 @@ public static class Field public static readonly DependencyProperty GlyphProperty = DependencyProperty.RegisterAttached( "Glyph", typeof(IconData), typeof(Field), new FrameworkPropertyMetadata(null)); + /// One sentence saying what is wrong with the value; null when it is fine. + public static readonly DependencyProperty ErrorProperty = DependencyProperty.RegisterAttached( + "Error", typeof(string), typeof(Field), new FrameworkPropertyMetadata(null, OnErrorChanged)); + + private static readonly DependencyPropertyKey HasErrorKey = DependencyProperty.RegisterAttachedReadOnly( + "HasError", typeof(bool), typeof(Field), new FrameworkPropertyMetadata(false)); + + /// True while holds a message; the input templates trigger on it. + public static readonly DependencyProperty HasErrorProperty = HasErrorKey.DependencyProperty; + public static string? GetPlaceholder(DependencyObject d) => (string?)d.GetValue(PlaceholderProperty); public static void SetPlaceholder(DependencyObject d, string? value) => d.SetValue(PlaceholderProperty, value); @@ -18,6 +31,15 @@ public static class Field public static IconData? GetGlyph(DependencyObject d) => (IconData?)d.GetValue(GlyphProperty); public static void SetGlyph(DependencyObject d, IconData? value) => d.SetValue(GlyphProperty, value); + + public static string? GetError(DependencyObject d) => (string?)d.GetValue(ErrorProperty); + + public static void SetError(DependencyObject d, string? value) => d.SetValue(ErrorProperty, value); + + public static bool GetHasError(DependencyObject d) => (bool)d.GetValue(HasErrorProperty); + + private static void OnErrorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => + d.SetValue(HasErrorKey, !string.IsNullOrEmpty((string?)e.NewValue)); } /// Attached glyph for buttons: renders an before (or instead of) the content. diff --git a/src/Titano.Ui/Themes/Controls.xaml b/src/Titano.Ui/Themes/Controls.xaml index be8a204a..9abd07c1 100644 --- a/src/Titano.Ui/Themes/Controls.xaml +++ b/src/Titano.Ui/Themes/Controls.xaml @@ -223,24 +223,26 @@ + - - - - - - - - + + + + + @@ -282,10 +284,11 @@ + - @@ -295,6 +298,11 @@ + + + + + diff --git a/src/Titano.Uploader/Shell/MainWindow.xaml b/src/Titano.Uploader/Shell/MainWindow.xaml index fa3cd73b..487e0a00 100644 --- a/src/Titano.Uploader/Shell/MainWindow.xaml +++ b/src/Titano.Uploader/Shell/MainWindow.xaml @@ -136,8 +136,7 @@ - - + @@ -188,15 +187,9 @@ ToolTip="{l:Loc Tooltips.Uploader.User}" AutomationProperties.Name="{l:Loc Uploader.Connect.User}" /> + - - + ToolTip="{Binding PasswordToolTip}" AutomationProperties.Name="{l:Loc Uploader.Connect.Password}" ui:Field.Error="{Binding PasswordError}" /> diff --git a/tests/Titano.App.Tests/Uploader/UploaderScreenSmokeTests.cs b/tests/Titano.App.Tests/Uploader/UploaderScreenSmokeTests.cs index 3f16d8b4..fd3c9230 100644 --- a/tests/Titano.App.Tests/Uploader/UploaderScreenSmokeTests.cs +++ b/tests/Titano.App.Tests/Uploader/UploaderScreenSmokeTests.cs @@ -42,7 +42,7 @@ public sealed class UploaderScreenSmokeTests Assert.Null(vm.Connect.ErrorText); foreach (var box in screen.Visible()) Assert.False(Validation.GetHasError(box), $"{AutomationProperties.GetName(box)} shows an error before use"); - Assert.False(screen.Named("PasswordErrorRing").IsVisible, "the password box shows no error before use"); + Assert.False(Field.GetHasError(screen.Named("Password")), "the password box shows no error before use"); screen.AssertIconButtonsNamed("connect"); // Enter signs in from the form, not from the settings panel drawn over it.