Use keyboard to expand the tree

Created on 26 March 2024, 6 months ago
Updated 16 May 2024, 4 months ago

Problem/Motivation

We use a Term Reference Tree widget to display a field on our user registration/user edit forms. Accessibility is an important factor for our site, and the fact that the term reference tree can't be expanded with the keyboard was flagged as an issue.

I used an existing issue, Cannot expand tree using just a keyboard πŸ› Cannot expand tree using just a keyboard Active , as the basis for my solution but applied it to the 2.0.x version of the module.

Steps to reproduce

Set a field on a form display to Term reference tree. Use the following settings:

  • Start minimized: True
  • Leaves only: True
  • Select parents automatically: False
  • Cascading selection: None
  • Maximum depth: 0

Proposed resolution

I'll attach a patch that'll do the following:

  • Add a tabindex attribute to the checkbox-tree-item template so users can navigate to it with the keyboard.
  • Bind the spacebar and Enter keys to the checkbox-tree-item div element to mimic the way you can check/uncheck checkboxes and radio buttons.

Remaining tasks

TBD

User interface changes

Add the ability to use the keyboard to navigate the term reference tree widget.

✨ Feature request
Status

Active

Version

2.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States jsutta United States

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

  • Issue created by @jsutta
  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States
  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    Patch attached.

    I should specify that I'm not completely sure my approach is the right one. I'm absolutely open to any and all feedback, improvements, etc.

  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    New version of the patch attached. This version corrects an issue where the behavior triggered twice when the spacebar was pressed, but only once when the enter or mouse buttons were pressed.

Production build 0.71.5 2024