diff --git a/components/interactive-elements.html b/components/interactive-elements.html index 05575e9..f6e18fa 100644 --- a/components/interactive-elements.html +++ b/components/interactive-elements.html @@ -390,23 +390,13 @@ Standard Checkbox - - Variante aktivierbar: inaktiv + + Variante aktivierbar ✓ - Option nicht gewählt, aber auswählbar - - - - Variante aktivierbar: aktiv - - - ✓ - - × - - Option gewählt + Option wählbar + × @@ -440,23 +430,13 @@ Standard Radio - - Variante aktivierbar: inaktiv + + Variante aktivierbar - Option nicht gewählt, aber auswählbar - - - - Variante aktivierbar: aktiv - - - - - × - - Option gewählt + Option wählbar + × @@ -699,6 +679,19 @@ return; } + const activatableOption = checkbox.closest('[data-component="checkbox-field"][data-activatable="true"]'); + if (activatableOption) { + checkbox.setAttribute('aria-checked', 'true'); + checkbox.classList.add('sg-form-active'); + checkbox.classList.remove('sg-checkbox-field--inactive-selectable'); + activatableOption.dataset.componentState = 'active'; + const removeButton = activatableOption.querySelector('[data-checkbox-activate-remove]'); + if (removeButton) { + removeButton.hidden = false; + } + return; + } + const nextState = checkbox.getAttribute('aria-checked') !== 'true'; checkbox.setAttribute('aria-checked', String(nextState)); @@ -745,6 +738,19 @@ return; } + const activatableOption = radio.closest('[data-component="radio-field"][data-activatable="true"]'); + if (activatableOption) { + radio.setAttribute('aria-checked', 'true'); + radio.classList.add('sg-form-active'); + radio.classList.remove('sg-radio-field--inactive-selectable'); + activatableOption.dataset.componentState = 'active'; + const removeButton = activatableOption.querySelector('[data-radio-activate-remove]'); + if (removeButton) { + removeButton.hidden = false; + } + return; + } + const group = radio.closest('.sg-form-preview-area'); if (!group) { return; @@ -883,6 +889,42 @@ }); }); + document.querySelectorAll('[data-checkbox-activate-remove]').forEach((removeButton) => { + removeButton.addEventListener('click', (event) => { + event.stopPropagation(); + const option = removeButton.closest('[data-component="checkbox-field"][data-activatable="true"]'); + const checkbox = option ? option.querySelector('.sg-checkbox-field') : null; + + if (!option || !checkbox) { + return; + } + + option.dataset.componentState = 'inactive-selectable'; + checkbox.setAttribute('aria-checked', 'false'); + checkbox.classList.remove('sg-form-active'); + checkbox.classList.add('sg-checkbox-field--inactive-selectable'); + removeButton.hidden = true; + }); + }); + + document.querySelectorAll('[data-radio-activate-remove]').forEach((removeButton) => { + removeButton.addEventListener('click', (event) => { + event.stopPropagation(); + const option = removeButton.closest('[data-component="radio-field"][data-activatable="true"]'); + const radio = option ? option.querySelector('.sg-radio-field') : null; + + if (!option || !radio) { + return; + } + + option.dataset.componentState = 'inactive-selectable'; + radio.setAttribute('aria-checked', 'false'); + radio.classList.remove('sg-form-active'); + radio.classList.add('sg-radio-field--inactive-selectable'); + removeButton.hidden = true; + }); + }); + // Filter rows inside the opened pulldown start as inactive preselected rows. // They are visually dimmed but remain operable; clicking or changing them activates the row. document.querySelectorAll('[data-pulldown-filter-row]').forEach((row) => { diff --git a/styleguide.css b/styleguide.css index 065076a..53c2613 100644 --- a/styleguide.css +++ b/styleguide.css @@ -1293,6 +1293,10 @@ section + section { color: var(--text-control-default); } + .sg-checkbox-field-option[data-activatable="true"][data-component-state="inactive-selectable"] { + opacity: var(--disabled-opacity); + } + .sg-checkbox-field-option--disabled { color: var(--text-control-disabled); opacity: var(--disabled-opacity);