jquery.makeCollapsible: Add toggleARIA option and enable for plain toggle
authorVolker E <volker.e@wikimedia.org>
Fri, 20 Sep 2019 03:14:46 +0000 (20:14 -0700)
committerKrinkle <krinklemail@gmail.com>
Sat, 21 Sep 2019 02:34:52 +0000 (02:34 +0000)
Adding `aria-expanded` attributes to `$toggle`.
That is not resolving each and every issue, but it gives at least
a valuable hint for screen readers and resolves the situation for
togglers, where the toggled content comes directly after `$toggle`.

Bug: T222904
Change-Id: Ic457bda58e56fb9ba2dce6df195e9fb48afb07f6

resources/src/jquery/jquery.makeCollapsible.js

index 20bd405..de307a6 100644 (file)
                                .toggleClass( 'mw-collapsible-toggle-expanded', wasCollapsed );
                }
 
+               // Toggle `aria-expanded` attribute, if requested (for default and premade togglers by default).
+               if ( options.toggleARIA ) {
+                       $toggle.attr( 'aria-expanded', wasCollapsed ? 'true' : 'false' );
+               }
+
                // Toggle the text ("Show"/"Hide") within elements tagged with mw-collapsible-text
                if ( options.toggleText ) {
                        collapseText = options.toggleText.collapseText;
                        actionHandler = function ( e, opts ) {
                                var defaultOpts = {
                                        toggleClasses: true,
+                                       toggleARIA: true,
                                        toggleText: { collapseText: collapseText, expandText: expandText }
                                };
                                opts = $.extend( defaultOpts, options, opts );
 
                        // Attach event handlers to togglelink
                        $toggle.on( 'click.mw-collapsible keypress.mw-collapsible', actionHandler )
+                               .attr( 'aria-expanded', 'true' )
                                .prop( 'tabIndex', 0 );
 
                        $( this ).data( 'mw-collapsible', {