Problem/Motivation

Like all form elements, details elements are assigned an aria-describedby attribute with a value of {element-id}--description. The problem is that the actual description is not given this ID. It is properly assigned for other form elements (at least all that I've tested).

This attribute is set in FormBuilder.php on line 971 (as of 8.3.4):

if (!empty($element['#description'])) {
  $element['#attributes']['aria-describedby'] = $element['#id'] . '--description';
}

The default template for a details element is in the system module's details.html.twig:

{{ description }}

The main theme template is in classy's details.html.twig:

<div class="details-description">{{ description }}</div>

No where is this proper ID being set.

The description attributes seem to be provided in form.inc within template_preprocess_form_element() and template_preprocess_fieldset(), but not within template_preprocess_details().

Tested with Bartik, Classy, and Seven.

Proposed resolution

Update all templates like this example:

{%- if description -%}
  {% set description_attributes = create_attribute({id: attributes['aria-describedby']}) %}
  <div{{ description_attributes.addClass('description-details') }}>{{ description }}</div>
{%- endif -%}

Remaining tasks

Provide a patch.

User interface changes

aria-describedby attributes will all be correct for details elements by properly wrapping the description in a DIV with the correct ID.

Before:

After:

Issue fork drupal-2896169

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mstef created an issue. See original summary.

mstef’s picture

Issue summary: View changes
mstef’s picture

Component: forms system » render system

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andrewmacpherson’s picture

Tagging this, will look at it soon. I only noticed this issue because the Webform accessibility handbook page links here.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

sahal_va’s picture

Status: Active » Needs review
StatusFileSize
new2.28 KB

Created the patch for above issue.

sahal_va’s picture

StatusFileSize
new2.19 KB

Status: Needs review » Needs work

The last submitted patch, 12: 2896169-11.patch, failed testing. View results

joseph.olstad’s picture

I had a look at the patch quickly, looks good so far, looks like remaining work is on refactoring the simpletests.

sahal_va’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new5.38 KB

Corrected patch.

sahal_va’s picture

Status: Reviewed & tested by the community » Needs review
sahal_va’s picture

StatusFileSize
new5.54 KB

Status: Needs review » Needs work
ridhimaabrol24’s picture

Status: Needs work » Needs review
StatusFileSize
new5.63 KB
new617 bytes

Fixing failed tests!

Status: Needs review » Needs work

The last submitted patch, 19: 2896169-19.patch, failed testing. View results

ridhimaabrol24’s picture

Issue tags: +Bug Smash Initiative
StatusFileSize
new6.59 KB
new829 bytes

Fixing failed test!

ridhimaabrol24’s picture

Status: Needs work » Needs review
StatusFileSize
new6.59 KB
new829 bytes

Correcting the above error!

Status: Needs review » Needs work

The last submitted patch, 22: interdiff_19-22.patch, failed testing. View results

ridhimaabrol24’s picture

Status: Needs work » Needs review

Added interdiff.patch by mistake instead of interdiff.txt. Hence its failing. However the patch in #22 passes the test bot. Hence moving this to 'Needs Review'.

sahal_va’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new78.23 KB
new81.21 KB
new60.14 KB
new87.13 KB
new86.96 KB

I tested the issue with Bartik, Claro, Classy, and Seven. This seems to be fixed.
Attaching the screenshots below for Seven.

Hi @ridhimaabrol24
Though changes in both patches are same, why #17 fails? I think I'm missing something essential for auto testing??

joseph.olstad’s picture

+1 , great work! I checked the drupal bootstrap contrib theme (version 3x) and it doesn't override this twig so this fix should also fix the for bootstrap installs as well and likely others.

Get it in!

ridhimaabrol24’s picture

Hi @sahal_va
Please see the interdiff attached in #19 to see what fixed those tests!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 22: interdiff_19-22.patch, failed testing. View results

mohit_aghera’s picture

Status: Needs work » Needs review

Changing to needs review as patch is already passing all the test cases.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

hswong3i made their first commit to this issue’s fork.

hswong3i’s picture

Version: 9.3.x-dev » 9.4.x-dev

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new150 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mgifford’s picture

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dcam made their first commit to this issue’s fork.

dcam changed the visibility of the branch 11.x to hidden.

dcam changed the visibility of the branch 2896169-details-elements-have to hidden.

dcam’s picture

Status: Needs work » Needs review

I rerolled the former 9.x MR against 11.x. Changes for old themes were removed. Changes for new themes were added. I also added a basic test for the description wrapper markup.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record

Hiding patches and old MRs.

This will need a CR because of the template change.

User Inteface section is meant for before/after screenshots so those should be added too please

@mgifford is this the correct approach btw? Could we removed "Needs accessibility review" tag

Moving to NW for other items.

mgifford’s picture

This looks good to me.

I missed this issue @smustgrave - sorry about the delay.

dcam’s picture

Issue summary: View changes
StatusFileSize
new28.31 KB
new29.84 KB

Added screenshots.

dcam’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record

A change record has been added at https://www.drupal.org/node/3509534.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record updates

Since this is changing the default twig it should be noted in the CR or a new CR be created

dcam’s picture

@smustgrave I did note it with this line in the CR:

In the default core/modules/system/templates/details.html.twig template a wrapper was added around the description with the new description.attributes.

Do I need to add more, edit the line, or note it in a different way?

dcam’s picture

Per @nod_ in Slack:

can we add a wrapping div with only the corresponding id for aria? we already have that info in the template that would avoid changing the structure of description... I would much rather do that. We already have an extra div for errors so that wouldn't be strange to have one for description

I'm working on it.

dcam’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs change record updates

Although @nod_ said "can we add a wrapping div with only the corresponding id for aria? we already have that info in the template..." I couldn't figure out how to get individual attributes out of an existing Attribute object, at least not cleanly. Given that, I figured that this was probably best done in the preprocess function and assigned to a new variable. If I've missed something, then let me know.

I updated the IS and CR with information about this change.

nod_’s picture

Status: Needs review » Needs work

We should be able to do that from twig only, no php changes needed to form.inc

nod_’s picture

umm but then we get duplication, I'm asking for other opinions

dcam’s picture

Issue summary: View changes
Status: Needs work » Needs review

umm but then we get duplication, I'm asking for other opinions

It looks like you were right to me. I don't see any duplication. I knew there had to be a way. Thank you for showing me.

I updated the IS and CR again.

carlygerard’s picture

StatusFileSize
new437.43 KB

I tested the up to date branch on an 11.1.x install, this works as expected for me--the aria-describedby value matches the ID of the description text.

Firefox developer tools shows a details element with an aria-describedby referring to the ID of the text inside it.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Feedback appears to be addressed on this one.

  • catch committed c4b04705 on 11.x
    Issue #2896169 by dcam, sahal_va, ridhimaabrol24, hswong3i, carlygerard...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.