Skip to content

Commit 0584186

Browse files
(editable) ComboBox: Moved ToggleButton down in Z-Order (#2789)
* Moved ToggleButton down in Z-Order This allows the editable TextBox to capture mouse interactions and grab focus without opening the drop down. * Removed whitespace - to force new PR check
1 parent d0ea60b commit 0584186

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

MainDemo.Wpf/ComboBoxes.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@
275275
HorizontalAlignment="Left">
276276
<ComboBox
277277
Style="{StaticResource MaterialDesignFilledComboBox}"
278-
materialDesign:HintAssist.Hint="Validation test"
278+
materialDesign:HintAssist.Hint="Validation test (editable)"
279+
IsEditable="True"
279280
ItemsSource="{Binding ShortStringList}"
280281
materialDesign:TextFieldAssist.HasClearButton="True"
281282
Width="256">

MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,49 @@ async Task AssertMenu(string menuHeader)
127127
Assert.True(menuItem is not null, $"{menuHeader} menu item not found");
128128
}
129129
}
130-
}
130+
131+
[Fact]
132+
[Description("Issue 2713")]
133+
public async Task OnEditableComboBox_ClickInTextArea_FocusesTextBox()
134+
{
135+
await using var recorder = new TestRecorder(App);
136+
137+
var stackPanel = await LoadXaml<StackPanel>(@"
138+
<StackPanel Orientation=""Horizontal"">
139+
<ComboBox x:Name=""EditableComboBox"" IsEditable=""True"" Style=""{StaticResource MaterialDesignComboBox}"">
140+
<ComboBoxItem>Select1</ComboBoxItem>
141+
<ComboBoxItem>Select2</ComboBoxItem>
142+
<ComboBoxItem IsSelected=""True"">Select3</ComboBoxItem>
143+
<ComboBoxItem>Select4</ComboBoxItem>
144+
<ComboBoxItem>Select5</ComboBoxItem>
145+
</ComboBox>
146+
<Button x:Name=""Button"" />
147+
</StackPanel>");
148+
149+
var comboBox = await stackPanel.GetElement<ComboBox>("EditableComboBox");
150+
var editableTextBox = await comboBox.GetElement<TextBox>("PART_EditableTextBox");
151+
var button = await stackPanel.GetElement<Button>("Button");
152+
153+
// Open the combobox initially
154+
await comboBox.LeftClick(Position.RightCenter);
155+
await Task.Delay(50); // Allow a little time for the drop-down to open (and property to change)
156+
bool wasOpenAfterClickOnToggleButton = await comboBox.GetIsDropDownOpen();
157+
158+
// Focus (i.e. click) another element
159+
await button.LeftClick();
160+
161+
// Click the editable TextBox of the ComboBox
162+
await editableTextBox.LeftClick();
163+
await Task.Delay(50); // Allow a little time for the drop-down to open (and property to change)
164+
bool wasOpenAfterClickOnEditableTextBox = await comboBox.GetIsDropDownOpen();
165+
bool textBoxHasFocus = await editableTextBox.GetIsFocused();
166+
bool textBoxHasKeyboardFocus = await editableTextBox.GetIsKeyboardFocused();
167+
168+
Assert.True(wasOpenAfterClickOnToggleButton, "ComboBox should have opened drop down when clicking the toggle button");
169+
Assert.False(wasOpenAfterClickOnEditableTextBox, "ComboBox should not have opened drop down when clicking the editable TextBox");
170+
Assert.True(textBoxHasFocus, "Editable TextBox should have focus");
171+
Assert.True(textBoxHasKeyboardFocus, "Editable TextBox should have keyboard focus");
172+
173+
recorder.Success();
174+
}
175+
}

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,14 @@
325325
Width="0"
326326
MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" />
327327
</Grid.ColumnDefinitions>
328+
<ToggleButton
329+
x:Name="toggleButton"
330+
Grid.ColumnSpan="2"
331+
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
332+
Style="{StaticResource MaterialDesignComboBoxToggleButton}"
333+
BorderBrush="{TemplateBinding BorderBrush}"
334+
Padding="{TemplateBinding Padding}"
335+
Margin="{Binding ElementName=InnerRoot, Path=Margin}" />
328336
<Border
329337
Grid.Column="0"
330338
Grid.Row="0"
@@ -489,13 +497,6 @@
489497
</ScrollViewer>
490498
</ContentControl>
491499
</wpf:ComboBoxPopup>
492-
<ToggleButton
493-
x:Name="toggleButton"
494-
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
495-
Style="{StaticResource MaterialDesignComboBoxToggleButton}"
496-
BorderBrush="{TemplateBinding BorderBrush}"
497-
Padding="{TemplateBinding Padding}"
498-
Margin="{Binding ElementName=InnerRoot, Path=Margin}" />
499500
<Button
500501
x:Name="PART_ClearButton"
501502
Style="{DynamicResource MaterialDesignToolButton}"

0 commit comments

Comments
 (0)