Tableselect single radio button missing #title attribute and is not accessible

Created on 5 May 2016, over 8 years ago
Updated 18 May 2023, over 1 year ago

Problem/Motivation

Tableselect element sets title to empty string and doesn't read from $element['#options'] the title as it does for checkboxes tableselect style. It impacts accessibility for radio buttons printed using tableselect and is inconsistent with how tableselect renders checkboxes.
Code from Tableselect::processTableselect

foreach ($element['#options'] as $key => $choice) {
        // Do not overwrite manually created children.
        if (!isset($element[$key])) {
          if ($element['#multiple']) {
            $title = '';
            if (isset($element['#options'][$key]['title']) && is_array($element['#options'][$key]['title'])) {
              if (!empty($element['#options'][$key]['title']['data']['#title'])) {
                $title = new TranslatableMarkup('Update @title', array(
                  '@title' => $element['#options'][$key]['title']['data']['#title'],
                ));
              }
            }
            $element[$key] = array(
              '#type' => 'checkbox',
              '#title' => $title,
              '#title_display' => 'invisible',
              '#return_value' => $key,
              '#default_value' => isset($value[$key]) ? $key : NULL,
              '#attributes' => $element['#attributes'],
            );
          }
          else {
            // Generate the parents as the autogenerator does, so we will have a
            // unique id for each radio button.
            $parents_for_id = array_merge($element['#parents'], array($key));
            $element[$key] = array(
              '#type' => 'radio',
              '#title' => '',
              '#return_value' => $key,
              '#default_value' => ($element['#default_value'] == $key) ? $key : NULL,
              '#attributes' => $element['#attributes'],
              '#parents' => $element['#parents'],
              '#id' => HtmlUtility::getUniqueId('edit-' . implode('-', $parents_for_id)),
              '#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
            );
          }
          if (isset($element['#options'][$key]['#weight'])) {
            $element[$key]['#weight'] = $element['#options'][$key]['#weight'];
          }
        }
      }

Title is considered and set only for $element['#multiple'] == TRUE cases:

$title = '';
if (isset($element['#options'][$key]['title']) && is_array($element['#options'][$key]['title'])) {
  if (!empty($element['#options'][$key]['title']['data']['#title'])) {
    $title = new TranslatableMarkup('Update @title', array(
      '@title' => $element['#options'][$key]['title']['data']['#title'],
    ));
  }
}

You can see that $title is not used and is set to empty in radio button element:

$element[$key] = array(
  '#type' => 'radio',
  '#title' => '',
  ...
);

Proposed resolution

Add support for #title attribute to be specified in the tableselect element options.

Remaining tasks

Provide patch

User interface changes

None, I guess, as title will still be hidden with '#title_display' => 'invisible'

API changes

None

Data model changes

None

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
FormΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΈUnited States asgorobets

Live updates comments and jobs are added and updated live.
  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024