Inconsistencies in the "Close" button markup

Created on 17 March 2025, about 2 months ago

Problem/Motivation

When the consent customization window is opened using the rel="open-consent-manager" trigger, the close button has different markup.

  1. Notice dialog (fine):

    The markup is:

    <button title="Close dialog and decline all" type="button" class="cn-decline klaro-close" tabindex="0" aria-label="Close dialog and decline all"></button>
    
  2. Consent dialog opened automatically or by clicking "Customize" on modal variants

    The markup is the same as per "Notice dialog".

  3. Consent dialog opened using rel="open-consent-manager" trigger:

    The markup is completely different:

    <button title="Close" aria-label="Close" type="button" tabindex="0" class="hide"><svg role="img" aria-label="Close" width="12" height="12" version="1.1" xmlns="http://www.w3.org/2000/svg"><title>Close</title><line x1="1" y1="11" x2="11" y2="1" stroke-width="1"></line><line x1="1" y1="1" x2="11" y2="11" stroke-width="1"></line></svg></button>

Steps to reproduce

Open consent dialog using <a href="#" rel="open-consent-manager">{% trans %}Manage cookies{% endtrans %}</a>

Proposed resolution

Fix the markup to be the same, without SVG.

📌 Task
Status

Needs work

Version

3.0

Component

Code

Created by

🇷🇺Russia niklan Russia, Perm

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @niklan
  • Merge request !86Remove close button conditions → (Open) created by niklan
  • 🇷🇺Russia niklan Russia, Perm

    Not sure what these conditions are meant for, but removing them fixes the problem. In that case, everything works as expected.

  • Pipeline finished with Success
    about 2 months ago
    Total: 148s
    #450129
  • 🇩🇪Germany jan kellermann

    The 2nd markup is from Klaro JS.
    The 1st markup is provided by Drupal module.

    So we cant fix the Klaro JS markup :(

    The Klaro JS only shows close button on some situations. You may open an upstream issue on github.

  • 🇩🇪Germany jan kellermann

    > Not sure what these conditions are meant for, but removing them fixes the problem. In that case, everything works as expected.

    The conditions control when the Drupal module has to add its own close button. Else the close button fom Klaro JS is used.

  • 🇷🇺Russia niklan Russia, Perm

    Shouldn't the Klaro module replace the Klaro JS markup in this case? Removing these conditions ensures the close button is consistent across all scenarios.

    The conditions control when the Drupal module has to add its own close button. Else the close button fom Klaro JS is used.

    In that case, shouldn't these conditions affect all cases, not just the consent modal in a specific state?

    • Drupal.behaviors.klaro.manager.confirmed — as I understand it, this becomes TRUE if consent information is present (in a cookie or localStorage), no matter what consent was chosen.
    • Drupal.behaviors.klaro.config.mustConsent — becomes TRUE when a user must choose consent and confirm it. Basically, this is used for the "Consent dialog" that is opened by default.

    if ((Drupal.behaviors.klaro.manager.confirmed) && (!Drupal.behaviors.klaro.config.mustConsent)) {

    So, this condition can be explained as follows: if the user has already performed some actions with consent (accepted, customized, or declined) AND there is no force for the "Consent dialog", disable the close button and let Klaro JS handle it.

    But the “Consent dialog” from the rel="open-consent-manager" trigger is exactly the same. So, it sounds like the conditions are useless or wrong? The one with confirmed doesn’t make any sense. If it is confirmed, why would you try to hide the close button, or if it’s not mustConsent, again, why would you hide it?

    I see the logic for the close button, which disables all the consents on click. But shouldn’t it be that way only when Drupal.behaviors.klaro.manager.confirmed is FALSE? So, if it is not yet confirmed, disable everything and close, but if it is confirmed, we should preserve the settings and just close the window?

          // Handle close button X.
          if (drupalSettings.klaro.show_close_button) {
            if (document.querySelector('#klaro-cookie-notice')) {
              var elem = document.querySelector('#klaro-cookie-notice');
            }
            else if (document.querySelector('.cm-modal.cm-klaro')) {
              var elem = document.querySelector('.cm-modal.cm-klaro .cm-header');
            }
    
            if (elem && !document.querySelector('.klaro-close')) {
              var close_label = Drupal.t("Close dialog and decline all", {},{context: 'klaro'});
              if (Drupal.behaviors.klaro.manager.confirmed) {
                var close_label = Drupal.t("Close dialog and keep existing consents", {},{context: 'klaro'});
              }
              var close_html = '<button title="' + close_label + '" type="button" class="cn-decline klaro-close" tabindex="0" aria-label="' + close_label + '"></button>';
              elem.insertAdjacentHTML('beforeend', close_html);;
              document.querySelector('.klaro-close')?.addEventListener('click', (e) => {
                if (!Drupal.behaviors.klaro.manager.confirmed) {
                  Drupal.behaviors.klaro.manager.changeAll(false);
                  Drupal.behaviors.klaro.manager.saveAndApplyConsents();
                }
              }, false);
              document.querySelector('.klaro').classList.add('klaro-close-enabled');
              document.querySelector('.klaro .cookie-modal .cm-modal .hide')?.remove();
            }
          }
    

    Take a look at the .klaro-close event listener. It only changes all consents to a disabled state and applies the changes if the user has still not interacted with the consent dialogs in any way. However, if something has already been selected, it does nothing and simply closes the window.

    Another approach could be to remove the close button added by Klaro JS if it meets the current conditions, instead of setting elem to false. In that case, the “Consent modal” will be without a close button, which is also acceptable I think.

  • 🇩🇪Germany jan kellermann

    We discussed the close button for some weeks in https://www.drupal.org/project/klaro/issues/3485880 Make close button X as DeclineAll button for mustConsent: true (needed for Italy) Active
    Please have a look. I cannot remember all the problems we discussed.

    The behavior to "discard all" is only needed, if no consents are saved (in notice dialog and in consent dialog). The consent dialog has its own close-button - except if option "must consent" is enabled, then Klaro hides its own close button. So we added a close button with "discard all" function for this both cases. In all other cases the close-button is like an "abort"-button.

Production build 0.71.5 2024