Generated with the help of an LLM.

Problem/Motivation

Drupal previously loaded the .fieldgroup border and padding reset on every page through system/base. Core commit fae1be903910 moved the reset to core/drupal.fieldgroup. Relevant change record: system/base split into smaller, conditionally loaded libraries.

CompositeFormElementTrait::preRenderCompositeFormElement() adds the fieldgroup class to fieldset wrappers for radio and checkbox groups without attaching the library. In themes that relied on core's reset, these fieldsets can now show the browser's default border and padding.

Steps to reproduce

  1. Install Drupal core and use a frontend theme without its own
    fieldset border or padding reset.
  2. Add the following element to a Form API form and open the form
    on a page using that theme.
    $form['choice'] = [
      '#type' =>'radios',
      '#title' => $this->t('Choices'),
      '#options' => ['a' => 'A', 'b' => 'B'],
    ];
  3. Inspect the wrapping fieldset.fieldgroup.form-composite in browser developer tools. On a page where no other element loads core/drupal.fieldgroup, the browser's default border and padding are visible. The expected result is zero border width and padding, matching the previous .fieldgroup reset.
  4. Repeat with #type set to checkboxes.

Proposed resolution

Attach core/drupal.fieldgroup in CompositeFormElementTrait::preRenderCompositeFormElement() when it adds the fieldgroup class.

Remaining tasks

  1. Add regression coverage for the library attachment and open a merge
    request.
  2. Review
  3. Merge

User interface changes

Restore the border and padding reset on radio and checkbox fieldsets in themes that rely on core's .fieldgroup styling.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

Not applicable.

Issue fork drupal-3641190

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

thomasdegraaff created an issue. See original summary.

thomasdegraaff’s picture

Issue summary: View changes
thomasdegraaff’s picture

Confirmed in Chromium on a clean Drupal 11.4.7 installation using the Minimal profile, core’s Stark theme, and core’s built-in form_test module. Both the radio and checkbox fieldsets had a 2px browser-default border and default padding. The page didn’t load fieldgroup.module.css. After I loaded that stylesheet in the browser, both the border width and padding became 0px.

thomasdegraaff’s picture

Issue summary: View changes
thomasdegraaff’s picture

Issue summary: View changes

keerthi kumar’s picture

Status: Active » Reviewed & tested by the community

Reviewed MR !17911:
- Code review: The fix in `CompositeFormElementTrait` cleanly attaches `core/drupal.fieldgroup` whenever the `fieldgroup` class is added to composite form elements.
- Test coverage: `ElementTest::testFieldsetWrappers()` validates the regression by asserting `fieldgroup.module.css` is attached on composite radio/checkbox forms.

eelkeblok’s picture

Title: Fieldset with fieldgroup class does set css what leaves browser default border visible » Radio and checkbox group fieldsets can show browser-default borders and padding
Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

I cleaned up the issue title and the summary a little. There are some failing tests, so back to Needs work.

eelkeblok’s picture

Issue summary: View changes