From cc4bd4486c75fab6dc003566df2b67cf507d5685 Mon Sep 17 00:00:00 2001 From: Davide Giacometti Date: Tue, 23 Apr 2024 16:36:12 +0200 Subject: [PATCH] [Settings]Colorpicker settings page focus a11y fixes (#32582) * fixed dialog tab navigation * fixed color formats list focus --- .../Controls/ColorFormatEditor.xaml | 4 +++- .../SettingsXAML/Views/ColorPickerPage.xaml | 1 + .../SettingsXAML/Views/ColorPickerPage.xaml.cs | 17 ++++++++++++++--- .../ViewModels/ColorPickerViewModel.cs | 5 +++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/ColorFormatEditor.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Controls/ColorFormatEditor.xaml index 4622609b95..32f0ee488e 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/ColorFormatEditor.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Controls/ColorFormatEditor.xaml @@ -1,4 +1,4 @@ - + @@ -107,6 +108,7 @@ diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/ColorPickerPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/ColorPickerPage.xaml index 6179f87a08..5762d03064 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/ColorPickerPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/ColorPickerPage.xaml @@ -95,6 +95,7 @@ 0) { - ViewModel.ColorFormats.Move(index, index - 1); + ViewModel.ColorFormats.Move(index, --index); + SetColorFormatsFocus(index); } } @@ -78,7 +79,8 @@ namespace Microsoft.PowerToys.Settings.UI.Views var index = ViewModel.ColorFormats.IndexOf(color); if (index < ViewModel.ColorFormats.Count - 1) { - ViewModel.ColorFormats.Move(index, index + 1); + ViewModel.ColorFormats.Move(index, ++index); + SetColorFormatsFocus(index); } } @@ -95,7 +97,8 @@ namespace Microsoft.PowerToys.Settings.UI.Views dialog.Content = new TextBlock() { Text = resourceLoader.GetString("Delete_Dialog_Description") }; dialog.PrimaryButtonClick += (s, args) => { - ViewModel.DeleteModel(color); + var deleteIndex = ViewModel.DeleteModel(color); + SetColorFormatsFocus(deleteIndex < ViewModel.ColorFormats.Count ? deleteIndex : ViewModel.ColorFormats.Count - 1); }; var result = await dialog.ShowAsync(); } @@ -105,6 +108,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views ColorFormatModel newColorFormat = ColorFormatDialog.DataContext as ColorFormatModel; ViewModel.AddNewColorFormat(newColorFormat.Name, newColorFormat.Format, true); ColorFormatDialog.Hide(); + SetColorFormatsFocus(0); } private void Update() @@ -159,5 +163,12 @@ namespace Microsoft.PowerToys.Settings.UI.Views modifiedColorFormat.Format = oldProperties.Value; } } + + private void SetColorFormatsFocus(int index) + { + ColorFormats.UpdateLayout(); + var colorFormat = ColorFormats.ContainerFromIndex(index) as ContentPresenter; + colorFormat.Focus(Microsoft.UI.Xaml.FocusState.Programmatic); + } } } diff --git a/src/settings-ui/Settings.UI/ViewModels/ColorPickerViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/ColorPickerViewModel.cs index 43a7736510..a1f57d4fc3 100644 --- a/src/settings-ui/Settings.UI/ViewModels/ColorPickerViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/ColorPickerViewModel.cs @@ -424,10 +424,11 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels return colorFormatModel.IsValid; } - internal void DeleteModel(ColorFormatModel colorFormatModel) + internal int DeleteModel(ColorFormatModel colorFormatModel) { + var deleteIndex = ColorFormats.IndexOf(colorFormatModel); ColorFormats.Remove(colorFormatModel); - SetPreviewSelectedIndex(); + return deleteIndex; } internal void UpdateColorFormat(string oldName, ColorFormatModel colorFormat)