dotnet / dotnet/wpf

First visit to a ComboBox via Keyboard allows selection of disabled ComboBoxItems

Open
#4,929 0 comments 0 reactions 0 assignees View on GitHub
.NET Framework Bug
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version: (e.g. 3.0 Preview1, or daily build number, use `dotnet --info`) 6.0.100-preview.6.21355.2
* Windows version: (`winver`) 21H1
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
* Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)? No, ComboBox
* Security issues and bugs should be reported privately, learn more via our [responsible disclosure guidelines](https://github.com/dotnet/wpf/blob/master/README.md#reporting-security-issues-and-security-bugs).



**Problem description:**
When first loading a `ComboBox`, you can use the keyboard to tab to it and arrow-key to `ComboBoxItems`.
The problem is you can select disabled (`IsEnabled=False`) items as well.
Once you open the Dropdown (expand it by clicking it), it shows disabled items in the correct theme, and they cannot be selected.
From this point, the keyboard can no longer select them either.

I found a very old blog post that mentioned this as a bug, so wanted to see if it is still a bug, or if there's a better way to handle such a thing today.
https://elgaard.blog/2009/09/03/wpf-making-combo-box-items-disabled-also-when-accessed-using-the-keyboard/

**Actual behavior:**
First visit to a ComboBox via Keyboard allows selection of disabled ComboBoxItems.
Here's the keyboard navigation to the `null` / Separator item:
![image](https://user-images.githubusercontent.com/49205731/127102923-949d1a11-a63b-4d8b-b9f1-e81f38ee85b3.png)
After expanding the dropdown via mouse:
![image](https://user-images.githubusercontent.com/49205731/127102920-dc6c02a1-baa1-45f5-b751-b871bc582d3b.png)

**Expected behavior:**
Shouldn't be able to select a disabled item via keyboard.

**Minimal repro:**

Bind to a `MyItems` collection with a `null` value (I tested with `List`).
```



<Style.Triggers>
<DataTrigger Binding="{Binding Mode=OneWay}" Value="{x:Null}">
<Setter Property="IsEnabled" Value="False"></Setter>
</DataTrigger>
</Style.Triggers>



```

Alternatively, use the NuGet repro for the bug I'm investigating: https://github.com/nuget/home/issues/11007

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.