Problem Description
When creating a table_select element using the form api, the added column with the checkboxes does not have a valid control labels. A title is added to the input for the "select all" by JS, but is not added to the inputs for each individual row. This causes screen readers such as NVDA to repeat the same "select all rows" title for each row, causing confusion. Ideally the input for each of these rows would be titled with something like 'select row #'.
For instance consider a form like follows:
public function buildForm(array $form, FormStateInterface $form_state): array {
$form['message'] = [
'#type' => 'tableselect',
'#title' => $this->t('Test Table Select'),
'#required' => TRUE,
'#header' => ['1','2','3'],
'#options' => [
'1' => ['a','b','c'],
'2' => ['d','e','f'],
'3' => ['g','h','i'],
],
'#multiple' => TRUE,
];
$form['actions'] = [
'#type' => 'actions',
'submit' => [
'#type' => 'submit',
'#value' => $this->t('Send'),
],
];
return $form;
}
If you examine the resultant form using a tool like the drupal editoria11y module (
https://www.drupal.org/project/editoria11y β
) or the industry standard axe dev tools, it reports an accessibility error.
Image from axe dev-tools: