Skip to content

Commit 089ad07

Browse files
add a method to clear accessible responses of a particular group, see phetsims/molecule-polarity#347
1 parent 17f3876 commit 089ad07

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

js/accessibility/pdom/ParallelDOM.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,6 +3590,32 @@ export default class ParallelDOM extends PhetioObject {
35903590
this.addAccessibleResponse( alertable, 'other', providedOptions );
35913591
}
35923592

3593+
/**
3594+
* Remove any queued responses for the provided response groups across connected Displays.
3595+
* This does not cancel currently speaking responses.
3596+
*/
3597+
public clearAccessibleResponseGroups( responseGroups: string | string[] ): void {
3598+
const groups = Array.isArray( responseGroups ) ? responseGroups : [ responseGroups ];
3599+
3600+
for ( let i = 0; i < groups.length; i++ ) {
3601+
const group = groups[ i ];
3602+
const responseGroupUtterance = responseGroupRegistry.getGroupUtterance( group );
3603+
if ( !responseGroupUtterance ) {
3604+
continue;
3605+
}
3606+
3607+
if ( globalDescriptionQueue.hasUtterance( responseGroupUtterance ) ) {
3608+
globalDescriptionQueue.removeUtterance( responseGroupUtterance );
3609+
}
3610+
3611+
this.forEachUtteranceQueue( queue => {
3612+
if ( queue.hasUtterance( responseGroupUtterance ) ) {
3613+
queue.removeUtterance( responseGroupUtterance );
3614+
}
3615+
} );
3616+
}
3617+
}
3618+
35933619
/**
35943620
* Apply a callback on each utteranceQueue that this Node has a connection to (via Display). Note that only
35953621
* accessible Displays have utteranceQueues that this function will interface with.

js/accessibility/pdom/responseGroupRegistry.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ class ResponseGroupRegistry {
4545
return utterance;
4646
}
4747

48+
/**
49+
* Return the Utterance for a group, or null if none exists.
50+
*/
51+
public getGroupUtterance( group: string ): Utterance | null {
52+
assert && assert( group.trim().length > 0, 'group must be a non-empty string' );
53+
return this.groupMap.get( group ) || null;
54+
}
55+
4856
/**
4957
* Remove a single group from the registry.
5058
*/

0 commit comments

Comments
 (0)