From 2d1cb1daeb7c5a998fbc6f7e39542f67bffa1bf0 Mon Sep 17 00:00:00 2001 From: Michael Kauzmann Date: Fri, 23 Aug 2024 12:45:31 -0600 Subject: [PATCH] better naming/storing for grab/drag state, https://github.com/phetsims/density-buoyancy-common/issues/356 Signed-off-by: Michael Kauzmann --- js/accessibility/GrabDragInteraction.ts | 43 +++++++++++++------------ 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/js/accessibility/GrabDragInteraction.ts b/js/accessibility/GrabDragInteraction.ts index 149243c9..db28d8da 100644 --- a/js/accessibility/GrabDragInteraction.ts +++ b/js/accessibility/GrabDragInteraction.ts @@ -161,14 +161,16 @@ type StateOptions = StrictOmit { - // When swapping from grabbable to draggable, the draggable element will be focused, ignore that case here, see https://github.com/phetsims/friction/issues/213 - this.grabbable && voicingNode.defaultFocusListener(); + // When swapping from interactionState to draggable, the draggable element will be focused, ignore that case here, see https://github.com/phetsims/friction/issues/213 + this.interactionState === 'grabbable' && voicingNode.defaultFocusListener(); }; // These Utterances should only be announced if the Node is globally visible and voicingVisible. @@ -506,7 +508,7 @@ class GrabDragInteraction extends EnabledComponent { // and pick it up immediately again. if ( !guardKeyPressFromDraggable ) { - // blur as a grabbable so that we geta new focus event after we turn into a draggable + // blur as a grabbable so that we get a new focus event after we turn into a draggable this.node.blur(); this.turnToDraggable(); @@ -601,10 +603,9 @@ class GrabDragInteraction extends EnabledComponent { }, release: event => { - // release if interrupted, but only if not already - // grabbable, which is possible if the GrabDragInteraction has been - // reset since press - if ( ( event === null || !event.isFromPDOM() ) && !this.grabbable ) { + // release if interrupted, but only if not already grabbable, which is possible if the GrabDragInteraction + // has been reset since press + if ( ( event === null || !event.isFromPDOM() ) && this.interactionState === 'draggable' ) { this.releaseDraggable(); } }, @@ -639,7 +640,7 @@ class GrabDragInteraction extends EnabledComponent { this.node.removePDOMAttribute( 'aria-roledescription' ); // Remove listeners according to what state we are in - if ( this.grabbable ) { + if ( this.interactionState === 'grabbable' ) { this.removeInputListeners( this.listenersForGrabState ); } else { @@ -688,7 +689,7 @@ class GrabDragInteraction extends EnabledComponent { * Release the draggable */ public releaseDraggable(): void { - assert && assert( !this.grabbable, 'cannot set to grabbable if already set that way' ); + assert && assert( this.interactionState === 'draggable', 'cannot set to interactionState if already set that way' ); this.turnToGrabbable(); this.onRelease(); } @@ -697,7 +698,7 @@ class GrabDragInteraction extends EnabledComponent { * turn the Node into the grabbable (button), swap out listeners too */ public turnToGrabbable(): void { - this.grabbable = true; + this.interactionState = 'grabbable'; // To support gesture and mobile screen readers, we change the roledescription, see https://github.com/phetsims/scenery-phet/issues/536 // By default, the grabbable gets a roledescription to force the AT to say its role. This fixes a bug in VoiceOver @@ -729,7 +730,7 @@ class GrabDragInteraction extends EnabledComponent { private turnToDraggable(): void { this.numberOfGrabs++; - this.grabbable = false; + this.interactionState = 'draggable'; // by default, the draggable has roledescription of "movable". Can be overwritten in `onDraggable()` this.node.setPDOMAttribute( 'aria-roledescription', movableStringProperty ); @@ -777,7 +778,7 @@ class GrabDragInteraction extends EnabledComponent { private updateFocusHighlights(): void { const voicingNode = this.node as VoicingNode; - if ( this.grabbable ) { + if ( this.interactionState === 'grabbable' ) { this.node.focusHighlight = this.grabFocusHighlight; voicingNode.isVoicing && voicingNode.setInteractiveHighlight( this.grabInteractiveHighlight ); }