TabControl doesn't send the name of selected tab to accessibility clients on initial focus
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 1d 13m
- Merged PRs (30d)
- 85
Description
### .NET version
9.0.100
### Did it work in .NET Framework?
Not tested/verified
### Did it work in any of the earlier releases of .NET Core or .NET 5+?
_No response_
### Issue description
Normally, when focusing a tab control using a screen reader, the name of the selected tab is announced. You can even see this in Winforms, by creating a tab control and then tabbing onto it. However, if the tab control gets the initial focus, or is the firstly focused item when you alt+tab back to the window, this doesn't happen. Here's a minimal C# Form to showcase this. I wrote and ran this with the dotnet CLI on Windows 10 IoT LTSC. Tested with NVDA, JAWS, and narrator.
```C#
using System;
using System.Drawing;
using System.Windows.Forms;
namespace TabControlTest;
public class Form1 : Form {
private TabControl tabControl;
public Form1() {
Text = "Tab Control Demo";
ClientSize = new Size(400, 300);
tabControl = new TabControl {
Dock = DockStyle.Fill,
Parent = this
};
var tabPage1 = new TabPage("Tab 1");
var label = new Label {
Text = "Welcome to Tab 1",
Location = new Point(20, 20),
AutoSize = true
};
var button = new Button {
Text = "Click Me!",
Location = new Point(20, 50),
Size = new Size(75, 23)
};
button.Click += (sender, e) => MessageBox.Show("Button clicked!");
tabPage1.Controls.Add(label);
tabPage1.Controls.Add(button);
tabControl.Controls.Add(tabPage1);
var tabPage2 = new TabPage("Tab 2");
var listBox = new ListBox {
Location = new System.Drawing.Point(20, 20),
Size = new Size(200, 150)
};
listBox.Items.AddRange(new object[] { "Item 1", "Item 2", "Item 3" });
tabPage2.Controls.Add(listBox);
tabControl.Controls.Add(tabPage2);
}
[STAThread]
static void Main() {
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
```
### Steps to reproduce
1. Start a screen reader.
2. Run the test app provided above.
3. Note what the screen reader reports when you land on the tab control.
4. Tab around the application a few times, exploring the various tabs, and take note of what the screen reader reports after focusing the tab control subsequent times.
5. For added effect, focus the tab control, then alt+tab out of the window and come back, note what is reported.
Contributor guide
Assessment
This issue has not been assessed yet.