Improved a11y of spoiler bbcodes
authorMarcel Werk <burntime@woltlab.com>
Sat, 16 Mar 2019 21:35:01 +0000 (22:35 +0100)
committerMarcel Werk <burntime@woltlab.com>
Sat, 16 Mar 2019 21:35:01 +0000 (22:35 +0100)
See #2713

com.woltlab.wcf/templates/spoilerMetaCode.tpl
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeWoltlabSpoiler.class.php

index 5b1b26dd4054e8b78becf2a582d3f1431c1dc6e3..cf61094181114b5bbb9121579529b8a5b420c1ba 100644 (file)
@@ -1,9 +1,9 @@
 <div class="spoilerBox jsSpoilerBox">
        <div class="jsOnly spoilerBoxHeader">
-               <a class="button small jsSpoilerToggle"{if $buttonLabel} data-has-custom-label="true"{/if}>{if $buttonLabel}{$buttonLabel}{else}{lang}wcf.bbcode.spoiler.show{/lang}{/if}</a>
+               <a href="#" id="spoiler-button-{@$spoilerID}" role="button" aria-expanded="false" aria-controls="spoiler-content-{@$spoilerID}" class="button small jsSpoilerToggle"{if $buttonLabel} data-has-custom-label="true"{/if}>{if $buttonLabel}{$buttonLabel}{else}{lang}wcf.bbcode.spoiler.show{/lang}{/if}</a>
        </div>
        
-       <div class="spoilerBoxContent" style="display: none">
+       <div class="spoilerBoxContent" style="display: none" id="spoiler-content-{@$spoilerID}" aria-hidden="true" aria-labelledby="spoiler-button-{@$spoilerID}">
                <!-- META_CODE_INNER_CONTENT -->
        </div>
        
                                        event.preventDefault();
                                        
                                        toggleButton.classList.toggle('active');
-                                       window[(toggleButton.classList.contains('active') ? 'elShow' : 'elHide')](container);
+                                       var isActive = toggleButton.classList.contains('active');
+                                       window[(isActive ? 'elShow' : 'elHide')](container);
+                                       elAttr(toggleButton, 'aria-expanded', isActive);
+                                       elAttr(container, 'aria-hidden', !isActive);
                                        
                                        if (!elDataBool(toggleButton, 'has-custom-label')) {
                                                toggleButton.textContent = (toggleButton.classList.contains('active')) ? '{lang}wcf.bbcode.spoiler.hide{/lang}' : '{lang}wcf.bbcode.spoiler.show{/lang}';
index 5550f6c70851cad6fddba5e68edc741c1cb515bc..5da1594ef60a9d78b00f3af103180a98ae9e5336 100644 (file)
@@ -47,7 +47,8 @@ class HtmlOutputNodeWoltlabSpoiler extends AbstractHtmlOutputNode {
         */
        public function replaceTag(array $data) {
                WCF::getTPL()->assign([
-                       'buttonLabel' => $data['label']
+                       'buttonLabel' => $data['label'],
+                       'spoilerID' => substr(StringUtil::getRandomID(), 0, 8)
                ]);
                return WCF::getTPL()->fetch((HtmlBBCodeParser::getInstance()->getIsGoogleAmp() ? 'spoilerAmpMetaCode' : 'spoilerMetaCode'));
        }