Skip to content

Commit

Permalink
Improving accessible name of masses, see phetsims/buoyancy#109
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed May 28, 2024
1 parent 2d5a7b6 commit 33056f7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion js/buoyancy/model/Boat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export default class Boat extends ApplicationsMass {
shape: Shape.polygon( boatIntersectionVertices ),
volume: volume,
massShape: MassShape.BLOCK,
material: Material.BOAT_BODY
material: Material.BOAT_BODY,

accessibleName: 'Boat'
}, providedOptions );

super( engine, displacementVolumeProperty, options );
Expand Down
4 changes: 3 additions & 1 deletion js/buoyancy/model/Bottle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ export default class Bottle extends ApplicationsMass {
density: ( BOTTLE_MASS + BOTTLE_INITIAL_INTERIOR_MATERIAL.density * BOTTLE_INITIAL_INTERIOR_VOLUME ) / BOTTLE_VOLUME,
densityRange: BOTTLE_DENSITY_RANGE
} ),
massShape: MassShape.BLOCK
massShape: MassShape.BLOCK,

accessibleName: 'Bottle'
}, providedOptions );

super( engine, new NumberProperty( BOTTLE_VOLUME ), options );
Expand Down
12 changes: 11 additions & 1 deletion js/common/model/Mass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Vector3 from '../../../../dot/js/Vector3.js';
import { Shape } from '../../../../kite/js/imports.js';
import EnumerationIO from '../../../../tandem/js/types/EnumerationIO.js';
import optionize, { combineOptions, EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import { Color, ColorProperty } from '../../../../scenery/js/imports.js';
import { Color, ColorProperty, PDOMValueType } from '../../../../scenery/js/imports.js';
import PhetioObject, { PhetioObjectOptions } from '../../../../tandem/js/PhetioObject.js';
import Tandem from '../../../../tandem/js/Tandem.js';
import BooleanIO from '../../../../tandem/js/types/BooleanIO.js';
Expand Down Expand Up @@ -120,6 +120,7 @@ type SelfOptions = {
// Allow PhET-iO customization of the material beyond initial value, see https://github.com/phetsims/density/issues/101
adjustableMaterial?: boolean;
tag?: MassTag;
accessibleName?: PDOMValueType | null;
phetioType?: IOType;
inputEnabledPropertyOptions?: BooleanPropertyOptions;
materialPropertyOptions?: PropertyOptions<Material>;
Expand Down Expand Up @@ -228,6 +229,8 @@ export default abstract class Mass extends PhetioObject {

public readonly nameProperty: TReadOnlyProperty<string>;

public readonly accessibleName: PDOMValueType;

// Set by the model
public containingBasin: Basin | null;

Expand All @@ -250,6 +253,7 @@ export default abstract class Mass extends PhetioObject {
canMove: true,
adjustableMaterial: false,
tag: MassTag.NONE,
accessibleName: null,
phetioType: Mass.MassIO,
inputEnabledPropertyOptions: {},
materialPropertyOptions: {},
Expand Down Expand Up @@ -502,6 +506,12 @@ export default abstract class Mass extends PhetioObject {
} );
}

this.accessibleName = options.accessibleName || new DerivedProperty( [ options.tag.nameProperty ],
( tagName: string ) => {
const suffix = tagName !== 'NONE' ? tagName : '';
return 'Mass ' + suffix;
} );

this.containingBasin = null;

this.originalMatrix = this.matrix.copy();
Expand Down
2 changes: 2 additions & 0 deletions js/common/model/Scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export default class Scale extends Mass {

phetioType: Scale.ScaleIO,

accessibleName: 'Scale',

inputEnabledPropertyOptions: {
phetioReadOnly: true
},
Expand Down
2 changes: 1 addition & 1 deletion js/common/view/MassView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default abstract class MassView extends Disposable {
if ( mass.canMove ) {

this.focusablePath = new InteractiveHighlightingPath( this.focusableShapeProperty, {
accessibleName: this.mass.nameProperty.value ? this.mass.nameProperty.value : 'Mass',
accessibleName: this.mass.accessibleName,
tagName: 'div',
focusable: true
} );
Expand Down

0 comments on commit 33056f7

Please sign in to comment.