Problem/Motivation

When conditional logic (#states) hides a fieldset in Webform, the js-webform-states-hidden class is appended to the <fieldset> element. However, .js-webform-states-hidden { display: none; } is currently defined in a stylesheet loaded under the component SMACSS CSS group.

Because Drupal orders CSS in the order base → layout → component → state → theme, any theme or layout stylesheet loaded later in the cascade that applies a display rule via a class selector of equal or higher specificity (e.g., .fieldset { display: flex; } or .form-wrapper { display: block; }) overrides .js-webform-states-hidden. As a result, the conditional hiding mechanism implicitly relies on fieldsets having an unset display property, causing conditionally hidden fieldsets to remain visible in themes that style them explicitly.

Steps to reproduce

  1. Create a webform containing a fieldset element and configure #states (Conditions) to hide it when a specific condition is met.
  2. Enable a theme (or add theme CSS) that explicitly defines a display property on the fieldset using a class selector (e.g., .fieldset { display: flex; }).
  3. View the form and trigger the condition that hides the fieldset.
  4. Inspect the <fieldset> element: js-webform-states-hidden is added to the class list, but the element remains visible because the theme's display property overrides Webform's component-level rule.

Proposed resolution

There are three ways to resolve this:

  1. Move the rule to the state CSS group: Define .js-webform-states-hidden in a library file under the state SMACSS category in webform.libraries.yml so it loads after component and layout styles, matching Drupal's CSS architecture for state-driven visibility.
  2. Use the HTML hidden attribute: Toggle the native hidden attribute on the element when conditional logic hides it instead of relying solely on a CSS class.
  3. Add !important to the declaration: Update the rule to .js-webform-states-hidden { display: none !important; } so conditional state visibility reliably takes precedence over theme layout styles (consistent with core utility classes like .hidden).

I would personally prefer option number 2 however, option one might be more backward compatible.

Issue fork webform-3639425

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

loominade created an issue. See original summary.

loominade’s picture

Title: hidden state requires » hidden states should go to css group "state"
liam morland’s picture

Version: 6.3.1 » 6.3.x-dev
Status: Active » Needs review