Skip to content

Commit

Permalink
user accessibleNameBehavior in AccordionBox, #444
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Aug 18, 2020
1 parent 430958c commit ef901e4
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions js/AccordionBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ import AccordionBoxIO from './AccordionBoxIO.js';
import ExpandCollapseButton from './ExpandCollapseButton.js';
import sun from './sun.js';

// The definition for how AccordionBox sets its accessibleName in the PDOM. Forward it onto its expandCollapseButton. See
// AccordionBox.md for further style guide and documentation on the pattern.
const ACCESSIBLE_NAME_BEHAVIOR = ( node, options, accessibleName ) => {

// Support mutation before this is defined
if ( node.expandCollapseButton ) {
node.expandCollapseButton.accessibleName = accessibleName;
}
return options;
};

/**
* @constructor
*
Expand Down Expand Up @@ -96,6 +107,7 @@ function AccordionBox( contentNode, options ) {
// pdom
tagName: 'div',
headingTagName: 'h3', // specify the heading that this AccordionBox will be, TODO: use this.headingLevel when no longer experimental https://github.com/phetsims/scenery/issues/855
accessibleNameBehavior: ACCESSIBLE_NAME_BEHAVIOR,

// phet-io support
tandem: Tandem.REQUIRED,
Expand Down Expand Up @@ -529,17 +541,6 @@ inherit( Node, AccordionBox, {
}
},

/**
* The accessibleName of the AccordionBox is passed through to its ExpandCollapseButton, as that is its PDOM display.
* @override
* @param {string|null} accessibleName
*/
setAccessibleName: function( accessibleName ) {
assert && assert( this.accessibleName === null, 'accessibleName should not be set directly on the AccordionBox, but ' +
'should instead forward to its expandCollapseButton.' );
this.expandCollapseButton.accessibleName = accessibleName;
},

/**
* Ensures this node is eligible for GC.
* @public
Expand Down

0 comments on commit ef901e4

Please sign in to comment.