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
- Create a webform containing a
fieldsetelement and configure#states(Conditions) to hide it when a specific condition is met. - Enable a theme (or add theme CSS) that explicitly defines a
displayproperty on the fieldset using a class selector (e.g.,.fieldset { display: flex; }). - View the form and trigger the condition that hides the fieldset.
- Inspect the
<fieldset>element:js-webform-states-hiddenis added to the class list, but the element remains visible because the theme'sdisplayproperty overrides Webform'scomponent-level rule.
Proposed resolution
There are three ways to resolve this:
- Move the rule to the
stateCSS group: Define.js-webform-states-hiddenin a library file under thestateSMACSS category inwebform.libraries.ymlso it loads aftercomponentandlayoutstyles, matching Drupal's CSS architecture for state-driven visibility. - Use the HTML
hiddenattribute: Toggle the nativehiddenattribute on the element when conditional logic hides it instead of relying solely on a CSS class. - Add
!importantto 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
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
Comment #3
loominade commentedComment #4
liam morland