Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private static Control MakePreviewBox(ManualChosenEncodingViewModel vm)
textBox.Bind(TextBox.TextProperty, new Binding(nameof(vm.PreviewText)) { Source = vm, Mode = BindingMode.OneWay });

grid.Add(label, 0);
grid.Add(textBox, 1);
grid.Add(textBox.WithLabeledBy(label), 1);

return UiUtil.MakeBorderForControl(grid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public EditWholeTextWindow(EditWholeTextViewModel vm)
};

grid.Add(labelLineInfo, 0, 0);
grid.Add(textBoxWholeText, 1, 0);
grid.Add(textBoxWholeText.WithLabeledBy(labelLineInfo), 1, 0);
grid.Add(panelButtons, 2, 0);

Content = grid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ private static Grid MakeFixesView(ApplyDurationLimitsViewModel vm)
item => item.Apply, (item, v) => item.Apply = v);

grid.Add(labelFixesAvailable, 0);
dataGrid.WithLabeledBy(labelFixesAvailable);
grid.Add(UiUtil.MakeBorderForControlNoPadding(dataGrid), 1);

return grid;
Expand Down Expand Up @@ -281,6 +282,7 @@ private static Grid MakeCannotFixView(ApplyDurationLimitsViewModel vm)
}, RoutingStrategies.Tunnel);

grid.Add(labelFixesAvailable, 0);
dataGrid.WithLabeledBy(labelFixesAvailable);
grid.Add(UiUtil.MakeBorderForControlNoPadding(dataGrid), 1);

return grid;
Expand Down
1 change: 1 addition & 0 deletions src/ui/Features/Video/RemuxVideo/PickAudioTrackWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public PickAudioTrackWindow(PickAudioTrackViewModel vm)
};
comboBox.Bind(ComboBox.ItemsSourceProperty, new Binding(nameof(PickAudioTrackViewModel.Tracks)));
comboBox.Bind(ComboBox.SelectedItemProperty, new Binding(nameof(PickAudioTrackViewModel.SelectedTrack)));
comboBox.WithAccessibleName(Se.Language.Video.RemuxVideoSelectAudioTrack);

var buttonOk = UiUtil.MakeButtonOk(vm.OkCommand);
var buttonCancel = UiUtil.MakeButtonCancel(vm.CancelCommand);
Expand Down
7 changes: 4 additions & 3 deletions src/ui/Logic/AccessibleLabels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
}

// A placeholder text is the label sighted users see in an unlabeled box.
if (control is TextBox { Watermark.Length: > 0 and <= 80 } textBox)

Check warning on line 55 in src/ui/Logic/AccessibleLabels.cs

View workflow job for this annotation

GitHub Actions / test

'TextBox.Watermark' is obsolete: 'Use PlaceholderText instead.'

Check warning on line 55 in src/ui/Logic/AccessibleLabels.cs

View workflow job for this annotation

GitHub Actions / test

'TextBox.Watermark' is obsolete: 'Use PlaceholderText instead.'
{
AutomationProperties.SetName(control, textBox.Watermark);

Check warning on line 57 in src/ui/Logic/AccessibleLabels.cs

View workflow job for this annotation

GitHub Actions / test

'TextBox.Watermark' is obsolete: 'Use PlaceholderText instead.'

Check warning on line 57 in src/ui/Logic/AccessibleLabels.cs

View workflow job for this annotation

GitHub Actions / test

'TextBox.Watermark' is obsolete: 'Use PlaceholderText instead.'
labeled.Add(control);
}
}
Expand Down Expand Up @@ -211,18 +211,19 @@
{
if (control is Label label)
{
return label.Content is not Control;
return label.Content is string labelText && !string.IsNullOrWhiteSpace(labelText);
}

if (control is CheckBox or RadioButton)
{
return ((ContentControl)control).Content is string;
return ((ContentControl)control).Content is string contentText &&
!string.IsNullOrWhiteSpace(contentText);
}

if (control is TextBlock textBlock)
{
var text = textBlock.Text;
return text == null || (text.Length <= 80 && !text.Contains('\n'));
return !string.IsNullOrWhiteSpace(text) && text.Length <= 80 && !text.Contains('\n');
}

return false;
Expand Down
61 changes: 61 additions & 0 deletions tests/UI/Logic/AccessibleLabelsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Avalonia.Automation;
using Avalonia.Controls;
using Avalonia.Headless.XUnit;
using Nikse.SubtitleEdit.Logic;
using Xunit;

namespace UITests.Logic;

public class AccessibleLabelsTests
{
[AvaloniaFact]
public void Apply_DoesNotUseEmptyTextBlockAsLabel()
{
var grid = new Grid();
var label = new TextBlock();
var input = new TextBox();

Grid.SetColumn(input, 1);
grid.Children.Add(label);
grid.Children.Add(input);

AccessibleLabels.Apply(grid);

Assert.Null(AutomationProperties.GetLabeledBy(input));
Assert.False(AccessibleLabels.HasAccessibleName(input));
}

[AvaloniaFact]
public void Apply_DoesNotUseEmptyLabelAsLabel()
{
var grid = new Grid();
var label = new Label();
var input = new TextBox();

Grid.SetColumn(input, 1);
grid.Children.Add(label);
grid.Children.Add(input);

AccessibleLabels.Apply(grid);

Assert.Null(AutomationProperties.GetLabeledBy(input));
Assert.False(AccessibleLabels.HasAccessibleName(input));
}

[AvaloniaFact]
public void Apply_StillUsesVisibleShortTextAsLabel()
{
var grid = new Grid();
var label = new TextBlock { Text = "Frame rate" };
var input = new ComboBox();

Grid.SetColumn(input, 1);
grid.Children.Add(label);
grid.Children.Add(input);

AccessibleLabels.Apply(grid);

Assert.Same(label, AutomationProperties.GetLabeledBy(input));
Assert.True(AccessibleLabels.HasAccessibleName(input));
}
}
Loading