Skip to content

Commit 66965c3

Browse files
corvinszKeboo
andauthored
fixes #3650 - TimePicker tab navigation (#3655)
* fixes #3650 added logic (and tests) for TimePicker to move to previous element when pressing Shift+Tab * Adjusting fix so that it leverages the WPF focus scopes This removes the need to manually handle the key strokes --------- Co-authored-by: Kevin Bost <[email protected]>
1 parent 31659be commit 66965c3

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TimePicker.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
4040
<Setter Property="IsHeaderVisible" Value="True" />
4141
<Setter Property="Padding" Value="{x:Static wpf:Constants.TextBoxDefaultPadding}" />
42+
<Setter Property="Focusable" Value="False" />
4243
<Setter Property="Template">
4344
<Setter.Value>
4445
<ControlTemplate TargetType="{x:Type wpf:TimePicker}">
@@ -101,7 +102,6 @@
101102
wpf:TextFieldAssist.UnderlineCornerRadius="{TemplateBinding wpf:TextFieldAssist.UnderlineCornerRadius}"
102103
internal:InternalTextFieldAssist.IsMouseOver="{TemplateBinding IsMouseOver}"
103104
BorderBrush="{TemplateBinding BorderBrush}"
104-
Focusable="{TemplateBinding Focusable}"
105105
Style="{DynamicResource NestedTextBoxStyle}">
106106
<wpf:TimePickerTextBox.BorderThickness>
107107
<PriorityBinding>

src/MaterialDesignThemes.Wpf/TimePicker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ private bool ProcessKey(KeyEventArgs keyEventArgs)
371371
{
372372
case Key.Down:
373373
{
374-
if ((Keyboard.Modifiers & ModifierKeys.Alt) == ModifierKeys.Alt)
374+
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
375375
{
376376
TogglePopup();
377377
return true;

tests/MaterialDesignThemes.UITests/WPF/TimePickers/TimePickerTests.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ public async Task TimePicker_WithOutlinedStyleAndNoCustomHintBackgroundSet_Shoul
560560
var timePickerTextBox = await timePicker.GetElement<TimePickerTextBox>("/TimePickerTextBox");
561561
var hintBackgroundGrid = await timePicker.GetElement<Grid>("HintBackgroundGrid");
562562

563-
var defaultBackground = Colors.Transparent;
563+
var defaultBackground = Colors.Transparent;
564564
var defaultFloatedBackground = await GetThemeColor("MaterialDesign.Brush.Background");
565565

566566
// Assert (unfocused state)
@@ -643,6 +643,36 @@ public async Task TimePicker_ShouldApplyIsMouseOverTriggers_WhenHoveringTimeButt
643643

644644
recorder.Success();
645645
}
646+
647+
[Fact]
648+
[Description("Issue 3650")]
649+
public async Task TimePicker_MovesFocusToPrevious_WhenShiftAndTabIsPressed()
650+
{
651+
await using var recorder = new TestRecorder(App);
652+
653+
// Arrange
654+
var stackPanel = await LoadXaml<StackPanel>("""
655+
<StackPanel>
656+
<TextBox />
657+
<materialDesign:TimePicker />
658+
</StackPanel>
659+
""");
660+
661+
var textBox = await stackPanel.GetElement<TextBox>("/TextBox");
662+
var timePickerTextBox = await stackPanel.GetElement<TimePickerTextBox>("/TimePickerTextBox");
663+
664+
// Act
665+
await timePickerTextBox.MoveKeyboardFocus();
666+
await Task.Delay(50);
667+
await timePickerTextBox.SendInput(new KeyboardInput(Key.LeftShift, Key.Tab));
668+
await Task.Delay(50);
669+
670+
// Assert
671+
Assert.True(await textBox.GetIsFocused());
672+
Assert.False(await timePickerTextBox.GetIsFocused());
673+
674+
recorder.Success();
675+
}
646676
}
647677

648678
public class OnlyTenOClockValidationRule : ValidationRule

0 commit comments

Comments
 (0)