Radios template does not apply form-radios class

Created on 26 July 2018, over 6 years ago
Updated 31 January 2024, 11 months ago

Problem/Motivation

The 'checkboxes.html.twig' templates for core, stable, and classy all apply the form-checkboxes class, but only the classy 'radios.html.twig' template applies the form-radios class.

A theme inheriting from stable must override the radios template in order to apply styles in the same way as is possible with checkboxes. Individual checkbox and radio inputs receive the 'form-checkbox' and 'form-radio' classes, respectively (see \Drupal\Core\Render\Element\Checkbox::preRenderCheckbox and \Drupal\Core\Render\Element\Radio::preRenderRadio()).

Proposed resolution

Add the form-radios class to the radios.html.twig templates in core and stable for consistency.

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Theme 

Last updated 40 minutes ago

Created by

🇨🇦Canada gapple

Live updates comments and jobs are added and updated live.
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.

  • 🇺🇸United States dww

    This came up as today's random triage target in #bugsmash.

    Yeah, this is definitely still a bug. A grep of the 11.x source for form-radios only finds these hits:

    modules/system/tests/src/Functional/Form/ElementsLabelsTest.php (for "form-radios-test")
    profiles/demo_umami/themes/umami/templates/classy/form/radios.html.twig:<div{{ attributes.addClass('form-radios') }}>{{ children }}</div>
    themes/claro/templates/form/radios.html.twig:<div{{ attributes.addClass('form-radios', 'form-boolean-group') }}>{{ children }}</div>
    themes/starterkit_theme/templates/form/radios.html.twig:<div{{ attributes.addClass('form-radios') }}>{{ children }}</div>
    

    But yes, thankfully, the way core handles Twig templates has evolved enough that we can fix bugs like this again. 🎉 Yay!

  • 🇺🇸United States dww

    Sorry, completely missed this from #10:

    Maybe we should open a follow-up to move classes from other form elements to Classy instead?

    Interesting. So you think this is a bug?

    lib/Drupal/Core/Render/Element/Checkbox.php:    static::setAttributes($element, ['form-checkbox']);
    

    ?

  • 🇺🇸United States bnjmnm Ann Arbor, MI

    If there's evidence this could benefit users without introducing problems, I'm happy to FEFM approve form-radios getting added in a manner similar to other form elements.

    Just make a followup for a potential "do it right" version #19. I think it's a noble pursuit, but even if it were to happen, it would not be quick (FE this issue is almost 6 years old). While they wait, I'm OK with letting folks enjoy the consistent-but-not-DRUPALSTRONG addition of form-radios .

Production build 0.71.5 2024