fix(ui): text and password boxes pad their text once; shared password error state
- The text box hands its Padding to the content host itself; the template no longer adds it again, so typed text starts where the placeholder does (12 px, 8 px after a leading icon). Same for the password box. - ui:Field.Error marks an input without a validating binding (a password box) with the error border and makes the sentence its help text; the Uploader and the login dialog use it instead of drawing their own. - The brand mark keeps its orientation by itself; the local left-to-right settings are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
8 files changed
+52
-30
No files matched your search
@@ -9,8 +9,7 @@
|
||||
<Border Style="{StaticResource Border.Panel}" Padding="28,24" HorizontalAlignment="Left" VerticalAlignment="Top" MinWidth="600">
|
||||
<StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,22">
|
||||
<!-- The mark keeps its clockwise ring and its sun on the right in every reading direction. -->
|
||||
<ui:BrandMarkIcon Width="56" Height="56" ShowPlate="True" FlowDirection="LeftToRight" />
|
||||
<ui:BrandMarkIcon Width="56" Height="56" ShowPlate="True" />
|
||||
<StackPanel Margin="16,0,0,0" VerticalAlignment="Center">
|
||||
<TextBlock Text="{l:Loc Shell.AppName}" Style="{StaticResource Text.PageTitle}" FontSize="22" />
|
||||
<TextBlock Text="{Binding Version}" Style="{StaticResource Text.Secondary}" Margin="0,2,0,0" Typography.NumeralAlignment="Tabular" />
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
<DockPanel LastChildFill="True">
|
||||
<ComboBox DockPanel.Dock="Right" VerticalAlignment="Top" MinWidth="120" ItemsSource="{Binding Languages}" SelectedItem="{Binding SelectedLanguage}"
|
||||
DisplayMemberPath="Name" ToolTip="{l:Loc Tooltips.Welcome.Language}" AutomationProperties.Name="{l:Loc Settings.General.Language}" />
|
||||
<ui:BrandMarkIcon Width="56" Height="56" ShowPlate="True" FlowDirection="LeftToRight" />
|
||||
<ui:BrandMarkIcon Width="56" Height="56" ShowPlate="True" />
|
||||
<StackPanel Margin="16,0,16,0" VerticalAlignment="Center">
|
||||
<TextBlock Text="{l:Loc Shell.Welcome.Title}" FontSize="20" FontWeight="SemiBold" TextTrimming="CharacterEllipsis" />
|
||||
<TextBlock Text="{l:Loc Shell.Welcome.Question}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,4,0,0" TextTrimming="CharacterEllipsis" />
|
||||
|
||||
@@ -8,7 +8,8 @@ namespace Titano.App.Shell;
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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(
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
<DockPanel>
|
||||
<ComboBox DockPanel.Dock="Right" MinWidth="180" VerticalAlignment="Center" ItemsSource="{Binding Languages}" SelectedItem="{Binding SelectedLanguage}"
|
||||
DisplayMemberPath="Name" IsEnabled="{Binding IsOptions}" ToolTip="{l:Loc Tooltips.Setup.Language}" AutomationProperties.Name="{l:Loc Setup.Field.Language}" />
|
||||
<!-- The mark is artwork: its off-centre sun must not flip in right-to-left languages. -->
|
||||
<ui:BrandMarkIcon ShowPlate="True" Width="40" Height="40" Margin="0,0,14,0" VerticalAlignment="Center" FlowDirection="LeftToRight" />
|
||||
<ui:BrandMarkIcon ShowPlate="True" Width="40" Height="40" Margin="0,0,14,0" VerticalAlignment="Center" />
|
||||
<StackPanel VerticalAlignment="Center">
|
||||
<TextBlock Text="{Binding Heading}" Style="{StaticResource Text.PageTitle}" />
|
||||
<TextBlock Text="{Binding SubHeading}" Style="{StaticResource Text.Secondary}" />
|
||||
|
||||
@@ -2,7 +2,10 @@ using System.Windows;
|
||||
|
||||
namespace Titano.Ui.Controls;
|
||||
|
||||
/// <summary>Attached field helpers: placeholder text and an inline leading icon for text inputs.</summary>
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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));
|
||||
|
||||
/// <summary>One sentence saying what is wrong with the value; null when it is fine.</summary>
|
||||
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));
|
||||
|
||||
/// <summary>True while <see cref="ErrorProperty"/> holds a message; the input templates trigger on it.</summary>
|
||||
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));
|
||||
}
|
||||
|
||||
/// <summary>Attached glyph for buttons: renders an <see cref="IconData"/> before (or instead of) the content.</summary>
|
||||
|
||||
@@ -223,24 +223,26 @@
|
||||
<Setter Property="SelectionOpacity" Value="0.35" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<!-- The text box hands its Padding to the content host itself, so the template applies it nowhere else: the
|
||||
placeholder takes it as its own padding (plus the 2 px the text view adds) and the leading icon sits at its
|
||||
left edge; with an icon, text and placeholder start 8 px after it. -->
|
||||
<ControlTemplate TargetType="TextBox">
|
||||
<Border x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{StaticResource Radius.Control}" SnapsToDevicePixels="True">
|
||||
<Grid Margin="{TemplateBinding Padding}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:Icon x:Name="Glyph" Glyph="{TemplateBinding ui:Field.Glyph}" Foreground="{DynamicResource Brush.TextFaint}" Margin="0,0,8,0" VerticalAlignment="Center" />
|
||||
<TextBlock x:Name="Placeholder" Grid.Column="1" Text="{TemplateBinding ui:Field.Placeholder}" Foreground="{DynamicResource Brush.TextFaint}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Visibility="Collapsed" IsHitTestVisible="False" TextTrimming="CharacterEllipsis" Margin="2,0,0,0" />
|
||||
<ScrollViewer x:Name="PART_ContentHost" Grid.Column="1" Focusable="False" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
<Grid>
|
||||
<ui:Icon x:Name="Glyph" Glyph="{TemplateBinding ui:Field.Glyph}" Foreground="{DynamicResource Brush.TextFaint}" HorizontalAlignment="Left"
|
||||
Margin="{TemplateBinding Padding}" />
|
||||
<TextBlock x:Name="Placeholder" Text="{TemplateBinding ui:Field.Placeholder}" Foreground="{DynamicResource Brush.TextFaint}" Padding="{TemplateBinding Padding}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Visibility="Collapsed" IsHitTestVisible="False" TextTrimming="CharacterEllipsis" Margin="24,0,0,0" />
|
||||
<ScrollViewer x:Name="PART_ContentHost" Focusable="False" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="22,0,0,0"
|
||||
HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" />
|
||||
</Grid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="ui:Field.Glyph" Value="{x:Null}">
|
||||
<Setter TargetName="Glyph" Property="Visibility" Value="Collapsed" />
|
||||
<Setter TargetName="Placeholder" Property="Margin" Value="2,0,0,0" />
|
||||
<Setter TargetName="PART_ContentHost" Property="Margin" Value="0" />
|
||||
</Trigger>
|
||||
<Trigger Property="Text" Value="">
|
||||
<Setter TargetName="Placeholder" Property="Visibility" Value="Visible" />
|
||||
@@ -282,10 +284,11 @@
|
||||
<Setter Property="SelectionBrush" Value="{DynamicResource Brush.Accent}" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<!-- As for TextBox, the password box hands its Padding to the content host itself. -->
|
||||
<ControlTemplate TargetType="PasswordBox">
|
||||
<Border x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{StaticResource Radius.Control}" SnapsToDevicePixels="True">
|
||||
<ScrollViewer x:Name="PART_ContentHost" Margin="{TemplateBinding Padding}" VerticalAlignment="Center" Focusable="False"
|
||||
<ScrollViewer x:Name="PART_ContentHost" VerticalAlignment="Center" Focusable="False"
|
||||
HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
@@ -295,6 +298,11 @@
|
||||
<Trigger Property="IsKeyboardFocused" Value="True">
|
||||
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource Brush.Accent}" />
|
||||
</Trigger>
|
||||
<!-- A password has no binding to validate: the owner sets ui:Field.Error (DESIGN §4 error state, as TextBox). -->
|
||||
<Trigger Property="ui:Field.HasError" Value="True">
|
||||
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource Brush.Error}" />
|
||||
<Setter Property="AutomationProperties.HelpText" Value="{Binding (ui:Field.Error), RelativeSource={RelativeSource Self}}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Opacity" Value="0.4" />
|
||||
</Trigger>
|
||||
|
||||
@@ -136,8 +136,7 @@
|
||||
<!-- First run / signed out: connect form. -->
|
||||
<Grid Grid.Row="1" Visibility="{Binding IsConnectVisible, Converter={StaticResource BoolToVisibility}}">
|
||||
<StackPanel DataContext="{Binding Connect}" Width="440" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<!-- The mark is artwork: its off-centre sun must not flip in right-to-left languages. -->
|
||||
<ui:BrandMarkIcon Width="48" Height="48" HorizontalAlignment="Center" FlowDirection="LeftToRight" />
|
||||
<ui:BrandMarkIcon Width="48" Height="48" HorizontalAlignment="Center" />
|
||||
<TextBlock Text="{l:Loc Uploader.Connect.Title}" Style="{StaticResource Text.Title}" HorizontalAlignment="Center" Margin="0,14,0,20" />
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
@@ -188,15 +187,9 @@
|
||||
ToolTip="{l:Loc Tooltips.Uploader.User}" AutomationProperties.Name="{l:Loc Uploader.Connect.User}" />
|
||||
|
||||
<TextBlock Grid.Row="3" Text="{l:Loc Uploader.Connect.Password}" Style="{StaticResource Text.Label}" Margin="0,12,12,0" />
|
||||
<!-- A wrong password: the kit's error border (DESIGN §4); the message is the tooltip. -->
|
||||
<PasswordBox x:Name="Password" Grid.Row="3" Grid.Column="1" Margin="0,12,0,0" PasswordChanged="OnPasswordChanged"
|
||||
ToolTip="{Binding PasswordToolTip}" AutomationProperties.Name="{l:Loc Uploader.Connect.Password}" />
|
||||
<!--
|
||||
A wrong password: the Error border (DESIGN §4), drawn over the box because the password box has no binding
|
||||
to validate and its template paints the focus border over its own; the message is the tooltip.
|
||||
-->
|
||||
<Border x:Name="PasswordErrorRing" Grid.Row="3" Grid.Column="1" Margin="0,12,0,0" BorderBrush="{DynamicResource Brush.Error}" BorderThickness="1"
|
||||
CornerRadius="{StaticResource Radius.Control}" SnapsToDevicePixels="True" IsHitTestVisible="False"
|
||||
Visibility="{Binding PasswordError, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
|
||||
ToolTip="{Binding PasswordToolTip}" AutomationProperties.Name="{l:Loc Uploader.Connect.Password}" ui:Field.Error="{Binding PasswordError}" />
|
||||
|
||||
<Border Grid.Row="4" Grid.Column="1" Margin="0,12,0,0" Padding="10,6,6,6" CornerRadius="{StaticResource Radius.Control}" Background="{DynamicResource Brush.ErrorSubtle}"
|
||||
Visibility="{Binding ErrorText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}">
|
||||
|
||||
@@ -42,7 +42,7 @@ public sealed class UploaderScreenSmokeTests
|
||||
Assert.Null(vm.Connect.ErrorText);
|
||||
foreach (var box in screen.Visible<TextBox>())
|
||||
Assert.False(Validation.GetHasError(box), $"{AutomationProperties.GetName(box)} shows an error before use");
|
||||
Assert.False(screen.Named<Border>("PasswordErrorRing").IsVisible, "the password box shows no error before use");
|
||||
Assert.False(Field.GetHasError(screen.Named<PasswordBox>("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.
|
||||
|
||||
Reference in new issue
Block a user