From f5fb7de6059e6fb75634734bea9bf70c448e1198 Mon Sep 17 00:00:00 2001 From: Jesse Date: Fri, 8 Nov 2024 18:13:10 -0500 Subject: [PATCH] Find a default accessibleName for ComboBox items, see https://github.com/phetsims/sun/issues/911 and https://github.com/phetsims/models-of-the-hydrogen-atom/issues/82 --- js/ComboBox.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/js/ComboBox.ts b/js/ComboBox.ts index e396d0aa..c70f864c 100644 --- a/js/ComboBox.ts +++ b/js/ComboBox.ts @@ -30,7 +30,7 @@ import InstanceRegistry from '../../phet-core/js/documentation/InstanceRegistry. import optionize from '../../phet-core/js/optionize.js'; import IntentionalAny from '../../phet-core/js/types/IntentionalAny.js'; import StrictOmit from '../../phet-core/js/types/StrictOmit.js'; -import { Display, extendsWidthSizable, Focus, FocusManager, isWidthSizable, MatrixBetweenProperty, Node, NodeOptions, PDOMBehaviorFunction, PDOMPeer, PDOMValueType, TColor, TInputListener, TPaint, TrimParallelDOMOptions, WidthSizable, WidthSizableOptions } from '../../scenery/js/imports.js'; +import { Display, extendsWidthSizable, Focus, FocusManager, isWidthSizable, MatrixBetweenProperty, Node, NodeOptions, PDOMBehaviorFunction, PDOMPeer, PDOMUtils, PDOMValueType, TColor, TInputListener, TPaint, TrimParallelDOMOptions, WidthSizable, WidthSizableOptions } from '../../scenery/js/imports.js'; import sharedSoundPlayers from '../../tambo/js/sharedSoundPlayers.js'; import TSoundPlayer from '../../tambo/js/TSoundPlayer.js'; import EventType from '../../tandem/js/EventType.js'; @@ -252,6 +252,14 @@ export default class ComboBox extends WidthSizable( Node ) { const nodes = getGroupItemNodes( items, options.tandem.createTandem( 'items' ) ); + // pdom - If an item has not been given an accessibleName, try to find a default value from the visual Node. + // Assigned to the item, because the accessible name is used in the ComboBoxButton and ComboBoxListItemNode. + items.forEach( ( ( item, i ) => { + if ( !item.accessibleName ) { + item.accessibleName = PDOMUtils.findStringProperty( nodes[ i ] ); + } + } ) ); + assert && nodes.forEach( node => { assert && assert( !node.hasPDOMContent, 'Accessibility is provided by ComboBoxItemNode and ' + 'ComboBoxItem.accessibleName. Additional PDOM content in the provided ' +